Skip to content
This repository was archived by the owner on Aug 2, 2020. It is now read-only.

Commit 76635bf

Browse files
authored
Merge pull request #9 from badgeteam/disobey-last-pieces
Disobey badge #2: last pieces
2 parents ccf185e + 6952e8a commit 76635bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+3080
-13
lines changed

esp32/Makefile

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,46 @@ MICROPY_NATIVEFS = 1
2020
MICROPY_PY_BTREE = 1
2121

2222
#FROZEN_DIR = scripts
23-
FROZEN_MPY_DIR = modules
23+
24+
ifdef CONFIG_SHA_BADGE_V1
25+
FROZEN_MPY_DIR = modules_sha2017
26+
endif
27+
28+
ifdef CONFIG_SHA_BADGE_V2
29+
FROZEN_MPY_DIR = modules_sha2017
30+
endif
31+
32+
ifdef CONFIG_SHA_BADGE_V3
33+
FROZEN_MPY_DIR = modules_sha2017
34+
endif
35+
36+
ifdef CONFIG_SHA_BADGE_V3_LITE
37+
FROZEN_MPY_DIR = modules_sha2017
38+
endif
39+
40+
ifdef PROJECT_PATH
41+
FROZEN_MPY_DIR = modules_disobey2019
42+
endif
43+
44+
ifdef CONFIG_HACKERHOTEL_BADGE_V1
45+
FROZEN_MPY_DIR = modules_hackerhotel2019
46+
endif
47+
48+
ifdef CONFIG_HACKERHOTEL_BADGE_V0
49+
FROZEN_MPY_DIR = modules_hackerhotel2019
50+
endif
51+
52+
ifdef CONFIG_SHA_BADGE_NONE
53+
FROZEN_MPY_DIR = modules_generic
54+
endif
2455

2556
# include py core make definitions
2657
include ../py/py.mk
2758

2859
PORT ?= /dev/ttyUSB0
2960
BAUD ?= 921600
61+
DISOBEY_PORT ?= /dev/ttyACM0
62+
DISOBEY_BAUD ?= 115200
3063
FLASH_MODE ?= dio
3164
FLASH_FREQ ?= 80m
3265
FLASH_SIZE ?= 16MB
@@ -166,17 +199,6 @@ SRC_C = \
166199
ugfx_styles.c \
167200
$(SRC_MOD)
168201

169-
### TODO fix hardcoded images when we can't get image loader to work
170-
#BADGE_MAIN_SRC_C = $(addprefix ../../main/,\
171-
# imgv2_menu.c \
172-
# imgv2_nick.c \
173-
# imgv2_sha.c \
174-
# imgv2_test.c \
175-
# imgv2_weather.c \
176-
# madison_gurkha.c \
177-
# leaseweb.c \
178-
# )
179-
180202
EXTMOD_SRC_C = $(addprefix extmod/,\
181203
modonewire.c \
182204
)
@@ -748,6 +770,19 @@ erase:
748770
$(ECHO) "Erasing flash"
749771
$(Q)$(ESPTOOL) --chip esp32 --port $(PORT) --baud $(BAUD) erase_flash
750772

773+
deploy_disobey: $(BUILD)/firmware.bin
774+
$(ECHO) "Writing $^ to the board"
775+
$(Q)$(ESPTOOL) --before no_reset --after no_reset --chip esp32 --port $(DISOBEY_PORT) --baud $(DISOBEY_BAUD) write_flash -z --flash_mode $(FLASH_MODE) --flash_freq $(FLASH_FREQ) 0x1000 $^
776+
777+
flash_disobey: $(BUILD)/firmware.bin
778+
$(ECHO) "Writing $^ to the board"
779+
$(Q)$(ESPTOOL) --before no_reset --after no_reset --port $(DISOBEY_PORT) --baud $(DISOBEY_BAUD) erase_region 0xd000 0x2000
780+
$(Q)$(ESPTOOL) --before no_reset --after no_reset --port $(DISOBEY_PORT) --baud $(DISOBEY_BAUD) write_flash 0x10000 build/application.bin
781+
782+
erase_disobey:
783+
$(ECHO) "Erasing flash"
784+
$(Q)$(ESPTOOL) --before no_reset --after no_reset --chip esp32 --port $(DISOBEY_PORT) --baud $(DISOBEY_BAUD) erase_flash
785+
751786
################################################################################
752787
# Declarations to build the application
753788

esp32/board_framebuffer.h

Lines changed: 0 additions & 1 deletion
This file was deleted.

esp32/modules_disobey2019/_boot.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import badge, gc, uos
2+
3+
badge.mount_root()
4+
uos.mount(uos.VfsNative(None), '/')
5+
6+
try:
7+
uos.mkdir('/lib')
8+
except:
9+
pass
10+
11+
gc.collect()

esp32/modules_disobey2019/about.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import ugfx, appglue, term, sys,time, version, easydraw
2+
3+
names = [
4+
"Niek Blankers", "Sebastian Oort", "Bas van Sisseren",
5+
"Jeroen Domburg", "Christel Sanders", "Markus Bechtold",
6+
"Thomas Roos", "Anne Jan Brouwer", "Renze Nicolai",
7+
"Aram Verstegen", "Arnout Engelen", "Alexandre Dulaunoy",
8+
"Eric Poulsen", "Damien P. George", "Heikki Juva",
9+
"Teemu Hakala", "Kliment", "Windytan",
10+
"Purkkaviritys", "Otto Raila", "Jaga",
11+
"uGFX", "EMF Badge Team", "",
12+
"", "Press back or start", "to quit!"]
13+
14+
def action_exit(pushed):
15+
if (pushed):
16+
appglue.home()
17+
18+
def show_names():
19+
global names
20+
c = False
21+
y = 10
22+
nos = 0
23+
ugfx.clear()
24+
25+
term.header(True, "About")
26+
print("Developers:")
27+
for n in range(0, len(names)):
28+
if (names[n]==""):
29+
break
30+
print(" - "+names[n])
31+
32+
nos = 9999
33+
34+
for n in range(0, len(names)):
35+
if (nos > 3):
36+
if (nos < 900):
37+
time.sleep(2)
38+
nos = 0
39+
easydraw.msg("", "Thank you!", True)
40+
easydraw.msg(names[n])
41+
nos += 1
42+
43+
def main():
44+
ugfx.input_init()
45+
ugfx.input_attach(ugfx.BTN_B, action_exit)
46+
ugfx.input_attach(ugfx.BTN_START, action_exit)
47+
show_names()
48+
sys.stdin.read(1) #Wait for any key
49+
action_exit(True)
50+
51+
52+
main()
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import ugfx, esp, badge, deepsleep, term, easydraw
2+
3+
def start_app(app, display = True):
4+
if display:
5+
easydraw.msg(app, "Loading...", True)
6+
term.header(True, "Loading application "+app+"...")
7+
esp.rtcmem_write_string(app)
8+
deepsleep.reboot()
9+
10+
def home():
11+
start_app("")
12+
13+
def start_ota():
14+
term.header(True, "Starting OTA...")
15+
esp.rtcmem_write(0,1)
16+
esp.rtcmem_write(1,254)
17+
deepsleep.reboot()
18+
19+
#def start_bpp(duration):
20+
# term.header(True, "Starting BPP...")
21+
# print("[BPP] Duration = "+str(duration))
22+
# esp.rtcmem_write(0,2)
23+
# esp.rtcmem_write(1,253)
24+
# deepsleep.reboot()

esp32/modules_disobey2019/boot.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# This file is executed on every boot (including wake-boot from deepsleep)
2+
import badge, machine, esp, ugfx, sys, time
3+
badge.init()
4+
ugfx.init()
5+
ugfx.input_init()
6+
7+
esp.rtcmem_write(0,0)
8+
esp.rtcmem_write(1,0)
9+
10+
# setup timezone
11+
timezone = badge.nvs_get_str('system', 'timezone', 'CET-1CEST-2,M3.5.0/02:00:00,M10.5.0/03:00:00')
12+
time.settimezone(timezone)
13+
14+
if badge.safe_mode():
15+
splash = 'splash'
16+
else:
17+
splash = badge.nvs_get_str('boot','splash','splash')
18+
19+
if machine.reset_cause() != machine.DEEPSLEEP_RESET:
20+
print('[BOOT] Cold boot')
21+
else:
22+
print("[BOOT] Wake from sleep")
23+
load_me = esp.rtcmem_read_string()
24+
if load_me:
25+
splash = load_me
26+
print("starting %s" % load_me)
27+
esp.rtcmem_write_string("")
28+
29+
try:
30+
if not splash=="shell":
31+
if splash.startswith('bpp '):
32+
splash = splash[4:len(splash)]
33+
badge.mount_bpp()
34+
elif splash.startswith('remfs '):
35+
splash = splash[6:len(splash)]
36+
badge.mount_remfs()
37+
elif splash.startswith('sdcard '):
38+
splash = splash[7:len(splash)]
39+
badge.mount_sdcard()
40+
41+
def back_button_default_action(pressed):
42+
if pressed:
43+
esp.rtcmem_write_string("")
44+
machine.deepsleep(1)
45+
ugfx.input_attach(ugfx.BTN_B, back_button_default_action)
46+
47+
__import__(splash)
48+
else:
49+
ugfx.clear(ugfx.WHITE)
50+
ugfx.flush(ugfx.LUT_FULL)
51+
except BaseException as e:
52+
sys.print_exception(e)
53+
import easydraw
54+
easydraw.msg("","Fatal exception", True)
55+
56+
# if we started the splash screen and it is not the default splash screen,
57+
# then revert to original splash screen.
58+
if splash == badge.nvs_get_str('boot', 'splash', 'splash') and splash != 'splash':
59+
print(">> Restored default splashscreen! <<")
60+
badge.nvs_erase_key('boot', 'splash')
61+
easydraw.msg(str(e))
62+
import time
63+
time.sleep(5)
64+
import appglue
65+
appglue.home()
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import tasks.otacheck as otacheck, easydraw, term, appglue, time, version, easywifi, badge, ugfx
2+
3+
term.header(True, "Update check")
4+
print("Checking for updates...")
5+
print("")
6+
print("Currently installed:",version.name,"(Build "+str(version.build)+")")
7+
8+
easydraw.msg("Current version:", "Update check", True)
9+
easydraw.msg_nosplit(str(version.build)+") "+version.name)
10+
time.sleep(3)
11+
available = 0
12+
13+
badge.nvs_set_u8('badge','OTA.ready',0)
14+
15+
def start(pressed):
16+
if pressed:
17+
appglue.start_ota()
18+
19+
if not easywifi.status():
20+
if not easywifi.enable():
21+
easydraw.msg("Error: could not connect to WiFi!")
22+
23+
title = "Update check"
24+
message = "?? Unknown state ??"
25+
26+
if easywifi.status():
27+
info = otacheck.download_info()
28+
if info:
29+
print("Server has: ",info['name']," (Build "+str(info['build'])+")")
30+
if info["build"] > version.build:
31+
badge.nvs_set_u8('badge','OTA.ready',0)
32+
print("Update available!")
33+
badge.nvs_set_u8('badge','OTA.ready',1)
34+
easydraw.msg("Update available!")
35+
easydraw.msg_nosplit(str(info["build"])+") "+info["name"])
36+
easydraw.msg("Update now?")
37+
title = "Firmware update available"
38+
message = "A new firmware version is available. Update?\n"
39+
message += "Currently installed: "+version.name+" (Build "+str(version.build)+")\n"
40+
message += "Available : "+info["name"]+" (Build "+str(info["build"])+")"
41+
elif info["build"] < version.build:
42+
badge.nvs_set_u8('badge','OTA.ready',0)
43+
print("Server has an older version.")
44+
badge.nvs_set_u8('badge','OTA.ready',1)
45+
easydraw.msg("Downgrade available!")
46+
easydraw.msg_nosplit(str(info["build"])+") "+info["name"])
47+
easydraw.msg("Downgrade now?")
48+
title = "Firmware downgrade available"
49+
message = "An older firmware version is available. Update?\n"
50+
message += "Currently installed: "+version.name+" (Build "+str(version.build)+")\n"
51+
message += "Available : "+info["name"]+" (Build "+str(info["build"])+")"
52+
else:
53+
print("You are up-to-date!")
54+
easydraw.msg("Up-to-date!")
55+
easydraw.msg_nosplit(str(version.build)+") "+version.name)
56+
easydraw.msg("Update anyway?")
57+
title = "Up-to-date"
58+
message = "You are up-to-date.\n"
59+
message += "Currently installed: "+version.name+" (Build "+str(version.build)+")\n"
60+
message += "Available : "+info["name"]+" (Build "+str(info["build"])+")"
61+
else:
62+
print("An error occured!")
63+
easydraw.msg("Check failed.")
64+
easydraw.msg_nosplit(str(version.build)+") "+version.name)
65+
easydraw.msg("Update anyway?")
66+
title = "Update check"
67+
message = "An error occured while fetching information. You can still choose to start the OTA procedure."
68+
else:
69+
easydraw.msg("No WiFi!")
70+
easydraw.msg_nosplit(str(version.build)+") "+version.name)
71+
easydraw.msg("Update anyway?")
72+
title = "Update check"
73+
message = "Could not connect to the WiFi network. You can still choose to start the OTA procedure."
74+
75+
ugfx.input_attach(ugfx.BTN_START, start)
76+
77+
78+
items = ["Cancel", "Start OTA update"]
79+
callbacks = [appglue.home, appglue.start_ota]
80+
callbacks[term.menu(title, items, 0, message)]()
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import machine, badge, term, time
2+
3+
pin = machine.Pin(25)
4+
rtc = machine.RTC()
5+
rtc.wake_on_ext0(pin = pin, level = 0)
6+
7+
def start_sleeping(sleepTime=0):
8+
badge.off()
9+
term.header(True, "Going to sleep...")
10+
if (sleepTime >= 86400000): #One day
11+
sleepTime = 0
12+
if (sleepTime < 1):
13+
print("Sleeping until touchbutton is pressed...")
14+
else:
15+
print("Sleeping for "+str(sleepTime)+"ms...")
16+
time.sleep(0.1)
17+
machine.deepsleep(sleepTime)
18+
19+
def reboot():
20+
machine.deepsleep(1)
File renamed without changes.

0 commit comments

Comments
 (0)