Skip to content

Commit

Permalink
added more granular swatch time, small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mhenstell committed Dec 28, 2013
1 parent 6b8d1a1 commit 37ca7e9
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions hexaservice/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

debug = False



def internet_time():
"Swatch Internet Time. Biel meridian."
h, m, s = time.gmtime()[3:6]
Expand All @@ -21,6 +19,25 @@ def internet_time():
beats = beats % 1000.0
return beats

def internet_time2():
"More granular Swatch time. Courtesy https://github.com/gcohen55/pebble-beapoch"
return (((time.time() + 3600) % 86400) * 1000) / 86400

def render_time_bitmap():
"Render local time + Swatch beats into a 2-panel bitmap"
beats = internet_time2()
msg = time.strftime("%H:%M:%S")
txtimg = base_font.strImg(msg)
img = Image.new("1",(120,7))
img.paste(txtimg,(15,0))
bmsg = "{0:03.2f}".format(beats)
txt2img = base_font.strImg(bmsg)
img.paste(txt2img,(62,0))
img.paste(base_font.strImg(".beats"),(93,0))
bitmap = compile_image(img,0,0)

return bitmap

class PanelThread(threading.Thread):
def __init__(self, panel):
pass
Expand All @@ -45,20 +62,13 @@ def sigint_handler(signal,frame):
signal.signal(signal.SIGINT,sigint_handler)

while True:
beats = internet_time()
msg = time.strftime("%H:%M:%S")
txtimg = base_font.strImg(msg)
img = Image.new("1",(120,7))
img.paste(txtimg,(15,0))
bmsg = "{0:03.2f}".format(beats)
txt2img = base_font.strImg(bmsg)
img.paste(txt2img,(62,0))
img.paste(base_font.strImg(".beats"),(93,0))
bitmap = compile_image(img,0,0)

bitmap = render_time_bitmap()

for j in range(3):
panels[j].setCompiledImage(bitmap)
time.sleep(0.1)

time.sleep(0.10)

panels[0].setRelay(False)

Expand Down

0 comments on commit 37ca7e9

Please sign in to comment.