Author Topic: Super detached keyboard LEDs  (Read 9453 times)

0 Members and 1 Guest are viewing this topic.

Offline nanu

  • Thread Starter
  • Posts: 290
    • http://T-T.be/portal
Super detached keyboard LEDs
« on: Fri, 13 November 2009, 11:49:53 »
I modified my LED lamp that I have hanging on the ceiling above the desk. They are just about the same as pictured on my dead blog. The difference now is that each pendant holds a single 5mm LED, and it's no longer powered directly by USB. Instead, they are now wired to a USB keyboard by 5 meters of phone wire (2 pairs of conductors, for 2 LEDs); there is significant electrical resistance due to this length of copper, and frankly I'm surprised the circuit can still drive them. The LEDs were bought in ~2004 and output 14,000mcd each.



So this extra keyboard is used solely for powering these decorative lights, wired to to scroll lock and num lock. I encased the keyboard PCB in a toilet paper tube for a minimum of protection. A good start.

The keyboard used is a Zippy WK-711 that I failed to mod.

I lucked out finding code to control the LEDs per keyboard device. Finally, I thought up of a remotely practical and feasible use out of the whole setup.

You see, I run irssi in screen on a shell account for IRC (and bitlbee for IM) services; I found the bell.pl irssi script and use that to flash these fancy keyboard lights when I am directly chatted to (normally beeping the terminal bell).

beep.pl on the remote shell requests that my local machine flash the lights:
Code: [Select]
beep_command = curl -s http://mybox.dyndns.org:12345/bellbeep &
Locally, I use a simple Python webserver (which serves other functions but are stripped, here):
Code: [Select]

from subprocess import Popen
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from urllib import unquote  # decode URLs

SERVER_PORT = 12345
HOSTS_ALLOWED = [
  '127.0.0.1',
  '192.168.0.1',
  'shell_acct_IP_here'
]

class HTTPHandler(BaseHTTPRequestHandler):
  def do_GET(self):
    client_address, client_port = ( self.client_address )
    if client_address in HOSTS_ALLOWED:
      cmd = unquote(self.path[1:])
      output = ''

      if cmd == 'bellbeep':
        Popen(r'"C:\Program Files\AutoHotkey\Autohotkey.exe" C:\code\ahk\kbdflash.ahk')

      self.send_response( 200 )
      self.send_header('Content-type', 'text/plain')
      self.end_headers()
      if not output:
        output = ''
      self.wfile.write(output.encode('utf-8'))

      if cmd == 'quit':
        self.server.stop = True
    else:
      print 'denied: '+ client_address

class StoppableHTTPServer(HTTPServer):
  def serve_forever(self):
    self.stop = False
    while not self.stop:
      self.handle_request()

def serve():
  try:
    server = StoppableHTTPServer(('', SERVER_PORT), HTTPHandler)
    print 'Listening on port %d...\n' % SERVER_PORT
    server.serve_forever()
  except KeyboardInterrupt:
    server.socket.close()
    print 'Exiting...'

if __name__ == '__main__':
  serve()

As long as all parts of this Rube Goldberg system work, I get flashing lights in my peripheral vision when text chat is not the active program, even if I'm away or not connected to the shell account.

However, the flashing itself is mediocre since the flashing gets my attention more effectively when the room is reasonably dim.  Not a problem for the cooler part of the year, and generally during the brighter daytime I'm supposed to have important things to be doing anyhow to avoid being excessively distracted.

Here's a grainy clip to demonstrate 3 "beeps", 5 seconds apart:


Alas, it was fun to get all of this working.
« Last Edit: Fri, 13 November 2009, 18:11:04 by nanu »

Offline nanu

  • Thread Starter
  • Posts: 290
    • http://T-T.be/portal
Super detached keyboard LEDs
« Reply #1 on: Fri, 13 November 2009, 18:06:28 »
Thanks!

Updated with a brief video clip of the lights flashing.

I'm fairly undisciplined with programming, so I usually end up using a hodgepodge of scripts; I feel it's valid for the elaborate setup I use anyhow just to chat in plaintext.

I'm still interested in using this for other dorky pursuits, such as syncing the lights to a beat detection DSP plugin for musics, but yeah, implementation is always more difficult than conceiving ideas.