Commit b078c4f0 authored by mik's avatar mik
Browse files

doebi patches

parent 57a8a7bb
mport ugfx
import ugfx
import time
import badge
import wifi
......@@ -24,8 +24,8 @@ class WinkeKatze:
# / ^ \\
# (|| ||)\\
# ,""_""_(/.
def draw_cat(self,cat='up',footer="https://devlol.org - press A to wink all other cats", nick=''):
def draw_cat(self,cat='up',footer="https://devlol.org - press A to wink all other cats"):
i=2
if (cat == 'up'):
drawcat = self.cat
......@@ -43,67 +43,57 @@ class WinkeKatze:
if footer:
i +=1
ugfx.string(8,12*i,footer,self.font,ugfx.BLACK)
if nick:
if self.nick:
ugfx.string(110,90,("%s winks" % (str(self.nick))),self.font,ugfx.BLACK)
if self.nick1:
ugfx.string(110,80,("%s winks" % (str(self.nick1))),self.font,ugfx.BLACK)
if self.nick2:
ugfx.string(110,70,("%s winks" % (str(self.nick2))),self.font,ugfx.BLACK)
if self.nick3:
ugfx.string(110,60,("%s winks" % (str(self.nick3))),self.font,ugfx.BLACK)
if self.nick4:
ugfx.string(110,50,("%s winks" % (str(self.nick4))),self.font,ugfx.BLACK)
ugfx.string(110,0,self.owner,"PermanentMarker36",ugfx.BLACK)
ugfx.string(110,10,self.owner,"PermanentMarker36",ugfx.BLACK)
ugfx.string(0,0,str(self.motd),self.font,ugfx.BLACK)
ugfx.flush()
def new_wink(self,msg):
self.nick4 = self.nick3
self.nick4 = self.nick3
self.nick3 = self.nick2
self.nick2 = self.nick1
self.nick1 = self.nick
self.nick = msg.decode("utf-8")
self.nick2 = self.nick1
self.nick1 = self.nick
self.nick = msg.decode("utf-8")
def sub_cb(self,topic,msg):
print ("received mqtt message topic: %s, payload: %s" % (topic,msg))
if topic.endswith('/nick'):
print ("setting received nick to %s" % msg.decode("utf-8"))
self.new_wink(msg)
#self.nick = msg.decode("utf-8")
list = []
hash = ubinascii.hexlify(sha1(self.nick).digest())
list.append(int(hash[0:2], 16))
list.append(int(hash[2:4], 16))
list.append(int(hash[4:6], 16))
list.append(0)
list.append(int(hash[6:8], 16))
list.append(int(hash[8:10], 16))
list.append(int(hash[10:12], 16))
list.append(0)
list.append(int(hash[12:14], 16))
list.append(int(hash[14:16], 16))
list.append(int(hash[16:18], 16))
list.append(0)
list.append(int(hash[18:20], 16))
list.append(int(hash[20:22], 16))
list.append(int(hash[22:24], 16))
list.append(0)
list.append(int(hash[24:26], 16))
list.append(int(hash[26:28], 16))
list.append(int(hash[28:30], 16))
list.append(0)
list.append(int(hash[30:32], 16))
list.append(int(hash[32:34], 16))
list.append(int(hash[34:36], 16))
list.append(0)
for i in range(6):
list.append(int(hash[i*6:i*6+2], 16))
list.append(int(hash[i*6+2:i*6+4], 16))
list.append(int(hash[i*6+4:i*6+6], 16))
list.append(0)
list.reverse()
colors = bytes(list)
print(colors)
for count in [1,2,3]:
self.draw_cat(cat="down",nick=self.nick)
badge.leds_send_data(colors)
badge.vibrator_activate(127)
time.sleep(0.5)
self.draw_cat(nick=self.nick)
badge.leds_send_data(''.join(['\0\0\0\0' for i in range(6)]))
time.sleep(0.5)
self.wink(colors)
if topic.endswith('/motd'):
self.motd = msg.decode("utf-8")
self.wink(''.join(['\0\0\0\50' for i in range(6)]))
def wink(self, colors):
for count in [1,2,3]:
self.draw_cat(cat="down")
badge.leds_send_data(colors)
badge.vibrator_activate(127)
time.sleep(0.5)
self.draw_cat()
badge.leds_send_data(''.join(['\0\0\0\0' for i in range(6)]))
time.sleep(0.5)
def btn_select(self,pressed):
if pressed:
print("Returning to homescreen")
......@@ -134,7 +124,7 @@ class WinkeKatze:
def __init__(self, font="fixed_10x20",server='mqtt.devlol.org',topic='devlol/h19/mainroom/winkekatze'):
self.cat = [' |\_/| ', ' (. .) ', ' =w= (\ ', ' / ^ \// ', ' (|| ||) ', ' ,""_""_ .']
self.catdown =[' |\_/| ', ' (. .) ', ' =w= ', ' / ^ \\\\ ', ' (|| ||)\\', ' ,""_""_(/.']
self.font = font
self.font = font
self.clientname = 'SHA2017Badge' + str(ubinascii.hexlify(uos.urandom(5)))
self.server = server
self.topic = topic
......@@ -143,7 +133,8 @@ class WinkeKatze:
self.nick2 = ''
self.nick3 = ''
self.nick4 = ''
self.motd = 'Alle 5 Minuten verliebt sich ein Hacker ueber die WinkekatzenApp'
badge.init()
badge.leds_enable()
#workaround for emulator
......@@ -179,7 +170,6 @@ class WinkeKatze:
ugfx.input_attach(ugfx.BTN_START,lambda pressed: self.btn_start(pressed))
ugfx.input_attach(ugfx.BTN_A,lambda pressed: self.btn_a(pressed))
ugfx.input_attach(ugfx.BTN_B,lambda pressed: self.btn_b(pressed))
self.draw_cat()
while True:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment