Skip to content

Commit

Permalink
Implement CLEAR_DISPLAY and DISPLAY_PROPERTIES_REQUEST
Browse files Browse the repository at this point in the history
CLEAR_DISPLAY doesn't seem to do anything, it seems.
Send DPR as the second thing (after STANDBY) and parse its response
  • Loading branch information
BurntBrunch committed Jan 4, 2012
1 parent 99e486a commit 81be798
Showing 1 changed file with 59 additions and 9 deletions.
68 changes: 59 additions & 9 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ class Packet(object):
VIBRATE_REQUEST = 42
VIBRATE_RESPONSE = 43

CLEAR_DISPLAY_REQUEST = 21
CLEAR_DISPLAY_RESPONSE = 22

DISPLAY_PROPERTIES_REQUEST = 1
DISPLAY_PROPERTIES_RESPONSE = 2

def __init__(self, pId = None, length = None, data = None):
self.pId = pId
self.length = length
Expand Down Expand Up @@ -220,10 +226,13 @@ def vibrate(self):
def led(self):
return self.key == 'l'

def clear(self):
return self.key == 'c'

def begin(self):
print "========================================================="
print "Starting server, commands are: (q)uit, (v)ibrate, (l)ed"
print "========================================================="
print "=================================================================="
print "Starting server, commands are: (q)uit, (v)ibrate, (l)ed, (c)lear"
print "=================================================================="

self.__change_tty()

Expand All @@ -250,6 +259,8 @@ def __revert_tty(self):
termios.tcsetattr(fd, termios.TCSADRAIN, self.old_stdin)

class LiveViewManager(object):
SW_VERSION = "0.0.3"

def __init__(self, tty):
self._24hour_clock = False

Expand Down Expand Up @@ -349,6 +360,23 @@ def debug_navigation(self, packet):
else:
print "Not a navigation packet!"

def debug_dpr(self,packet):
data = packet.data

data = struct.unpack(">10B B %is" % (len(data) - 11) , data)
(width, height, sbWidth, sbHeight, viewWidth, viewHeight, aWidth,
aHeight, textChunkSize, idleTimer, stopbyte, version) = data

print "Width Height sbWidth sbHeight viewWidth viewHeight"
print "%5i %6i %7i %8i %9i %10i" % ( width, height, sbWidth, sbHeight,
viewWidth, viewHeight)

print "aWidth aHeight textChunk idleTimer"
print "%6i %7i %9i %9i" % (aWidth, aHeight, textChunkSize, idleTimer)

print "Software version: '%s'" % (version)


def communicate(self):
nextRead = 1
stdinman = StdinManager()
Expand All @@ -357,6 +385,13 @@ def communicate(self):
stdinman.begin()
self.send_standby()

print "Sending DPR..",
data = LiveViewManager.SW_VERSION
data = struct.pack('>%is' % (len(data) + 1), data)
tmp = Packet(Packet.DISPLAY_PROPERTIES_REQUEST, len(data), data)
self.send(tmp)
print "sent"

while nextRead > 0:
(seqin, seqout, seqex) = select.select([self.fd, sys.stdin],
[], [])
Expand Down Expand Up @@ -399,7 +434,16 @@ def communicate(self):

print "sent"

if stdinman.clear():
print "Clearing display..",

tmp = Packet(Packet.CLEAR_DISPLAY_REQUEST, 0, '')
self.send(tmp)

print "sent"

if self.fd in seqin and self.fd.inWaiting() > 0:
assert self.fd.inWaiting() >= nextRead
tmp = self.fd.read(nextRead)

if len(tmp) > 0:
Expand All @@ -416,13 +460,19 @@ def communicate(self):

print "sent"

if packet.pId == Packet.VIBRATE_RESPONSE:
print "Got VIBRATE_RESPONSE"
assert packet.data == chr(0x0)
packet_nops = {
Packet.VIBRATE_RESPONSE: "VIBRATE_RESPONSE",
Packet.LED_RESPONSE: "LED_RESPONSE",
Packet.CLEAR_DISPLAY_RESPONSE: "CLEAR_DISPLAY_RESPONSE",
}

if packet.pId == Packet.LED_RESPONSE:
print "Got LED_RESPONSE"
assert packet.data == chr(0x0)
if packet.pId in packet_nops:
print "Got %s" % (packet_nops[packet.pId],)

if packet.pId == Packet.DISPLAY_PROPERTIES_RESPONSE:
print "Got DISPLAY_PROPERTIES_RESPONSE"
self.debug_dpr(packet)
self.send_standby()

if packet.pId == Packet.STANDBY_REQUEST:
if packet.data == [0x2]:
Expand Down

0 comments on commit 81be798

Please sign in to comment.