Skip to content

Instantly share code, notes, and snippets.

@stigok
Created August 5, 2017 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stigok/dcf0e9bf846e6bacafd84b26b1497292 to your computer and use it in GitHub Desktop.
Save stigok/dcf0e9bf846e6bacafd84b26b1497292 to your computer and use it in GitHub Desktop.
#import dialogs, ugfx, network, badge, deepsleep
#import dialogs from micropython/unix/modules/dialogs.py
import ugfx, network, badge, time
mocked_messages = [
'sshow: hei, verden!',
'krav: hello, world!',
'sshow: funker dette?',
'krav: ja :):):):)',
'sshow: hei, verden!',
'krav: hello, world!',
'sshow: funker dette?',
'krav: ja :):):):)',
'sshow: hei, verden!',
'krav: hello, world!',
'sshow: funker dette?',
'krav: ja :):):):)'
]
font_height = 16
text_padding = 2
header_text = '#sha2017 @ chat.freenode.org'
def showSplash():
clearGhosting()
ugfx.clear(ugfx.WHITE)
ugfx.string(100,50,'IRC @ SHA IIRC','Roboto_Regular18',ugfx.BLACK)
ugfx.flush()
time.sleep(2)
print('splash done')
clearGhosting()
ugfx.clear(ugfx.WHITE)
def clearGhosting():
ugfx.clear(ugfx.WHITE)
ugfx.flush()
badge.eink_busy_wait()
ugfx.clear(ugfx.BLACK)
ugfx.flush()
badge.eink_busy_wait()
ugfx.init()
ugfx.input_init()
#showSplash()
program_name = 'shairc'
buffer_len = 21
# Set environment
#badge.nvs_set_str(program_name, 'matrix.username', 'test_user')
#badge.nvs_set_str(program_name, 'matrix.password', 'test_pass')
# Write header text
ugfx.string(text_padding, text_padding, header_text, 'Roboto_Regular%d' % font_height, ugfx.BLACK)
# Draw message window
message_list = ugfx.List(0, font_height, ugfx.width(), ugfx.height() - font_height)
message_list.set_focus()
def onMessage(msg):
#attachInput
# Keep buffer small
if (message_list.count() > buffer_len):
remove_item(buffer_len)
message_list.add_item(msg)
#
# Debugging
#
for s in mocked_messages:
onMessage(s)
def connectClick(pushed):
if pushed:
print('hello world')
#selected = options.selected_text().encode()
#print('selected')
#options.destroy()
#badge.eink_busy_wait()
#deepsleep.start_sleeping(1)
#print(ssidList.index(selected))
#ugfx.clear(ugfx.WHITE)
#ugfx.string(100,50,selected,'Roboto_Regular18',ugfx.BLACK)
#ugfx.flush()
#badge.nvs_set_str("badge", "wifi.ssid", selected)
else:
print('nah')
def show_message_prompt():
clearGhosting()
dialogs.prompt_text("Message:", cb = message_prompt_done)
def message_prompt_done(passIn):
send_message(passIn)
# Input bindings
#ugfx.input_attach(ugfx.BTN_A, connectClick)
#ugfx.input_attach(ugfx.BTN_B, connectClick)
ugfx.input_attach(ugfx.JOY_UP, lambda pushed: ugfx.flush() if pushed else 0)
ugfx.input_attach(ugfx.JOY_DOWN, lambda pushed: ugfx.flush() if pushed else 0)
# Bootstrapping
ugfx.set_lut(ugfx.LUT_FULL)
ugfx.flush()
ugfx.set_lut(ugfx.LUT_FASTER)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment