diff --git a/preload/apps/adventure_timer/__init__.py b/preload/apps/adventure_timer/__init__.py index 7c1f8eac3d90bb8c4c91b9046560dde6f4e10d43..74c37a6cd06cea8412709bb24f36f52e7fc11227 100644 --- a/preload/apps/adventure_timer/__init__.py +++ b/preload/apps/adventure_timer/__init__.py @@ -1,7 +1,7 @@ -import ujson +import json import os import display -import utime +import time import buttons CONFIG_NAME = "at-timestamp.json" @@ -11,7 +11,7 @@ def init(): if CONFIG_NAME not in os.listdir("."): at_config = {"time_start": "unset"} f = open(CONFIG_NAME, "w") - f.write(ujson.dumps(at_config)) + f.write(json.dumps(at_config)) f.close() if is_timestamp_set(): @@ -22,7 +22,7 @@ def init(): def is_timestamp_set(): f = open(CONFIG_NAME, "r") - c = ujson.loads(f.read()) + c = json.loads(f.read()) f.close() if c["time_start"] == "unset": return False @@ -40,29 +40,29 @@ def triangle(disp, x, y, left): def timestamp_reset(): f = open(CONFIG_NAME, "r") - c = ujson.loads(f.read()) + c = json.loads(f.read()) c["time_start"] = "unset" f.close() f = open(CONFIG_NAME, "w") - f.write(ujson.dumps(c)) + f.write(json.dumps(c)) f.close() def timestamp_read(): global time_start f = open(CONFIG_NAME, "r") - c = ujson.loads(f.read()) + c = json.loads(f.read()) time_start = c["time_start"] f.close() def timestamp_write(): f = open(CONFIG_NAME, "r") - c = ujson.loads(f.read()) - c["time_start"] = utime.time() + c = json.loads(f.read()) + c["time_start"] = time.time() f.close() f = open(CONFIG_NAME, "w") - f.write(ujson.dumps(c)) + f.write(json.dumps(c)) f.close() @@ -76,7 +76,7 @@ def menu(): triangle(disp, 10, 66, True) disp.print("start.", posx=15, posy=60, fg=[0, 255, 0]) elif menu_state == 1: - seconds = utime.time() - time_start + seconds = time.time() - time_start m, s = divmod(seconds, 60) h, m = divmod(m, 60) disp.print("%02d:%02d:%02d" % (h, m, s), posy=40, fg=[255, 255, 255]) @@ -122,4 +122,4 @@ while True: menu_state = 0 menu() disp.update() - utime.sleep(0.1) + time.sleep(0.1) diff --git a/preload/apps/analog_clock/__init__.py b/preload/apps/analog_clock/__init__.py index 543a0aba756015032a09448579c16ee011efc298..0dabbb1c973654f321a980dc9338cc70bbf83cea 100644 --- a/preload/apps/analog_clock/__init__.py +++ b/preload/apps/analog_clock/__init__.py @@ -1,11 +1,11 @@ # Adapted from https://github.com/muccc/flipdots/blob/master/scripts/clock.py import display -from utime import sleep -import utime +from time import sleep +import time import math import leds import buttons -import ujson +import json import os CONFIG_NAME = "clock.json" @@ -100,7 +100,7 @@ class Clock: def readConfig(self): with open(CONFIG_NAME, "r") as f: try: - c = ujson.loads(f.read()) + c = json.loads(f.read()) if ( "themes" in c and len(c["themes"]) > 0 @@ -114,7 +114,7 @@ class Clock: def writeConfig(self): with open(CONFIG_NAME, "w") as f: - f.write(ujson.dumps({"theme": self.theme, "themes": self.themes})) + f.write(json.dumps({"theme": self.theme, "themes": self.themes})) def setTheme(self, theme): self.theme = theme % len(self.themes) @@ -159,7 +159,7 @@ class Clock: try: with display.open() as disp: while True: - localtime = utime.localtime() + localtime = time.localtime() self.updateClock(disp, localtime) if self.run_once: break @@ -179,7 +179,7 @@ class Clock: elif button_pressed and v & buttons.TOP_RIGHT != 0: self.setTime(disp, localtime) - utime.sleep_ms(23) + time.sleep_ms(23) except KeyboardInterrupt: for i in range(11): @@ -255,7 +255,7 @@ class Clock: accepted = False previously_pressed_button = buttons.TOP_RIGHT button_repeat_counter = 0 - set_seconds = utime.mktime(localtime) + set_seconds = time.mktime(localtime) while not accepted: v = buttons.read( @@ -288,11 +288,11 @@ class Clock: elif previously_pressed_button == buttons.BOTTOM_RIGHT: set_seconds += seconds_change - self.updateClock(disp, utime.localtime(set_seconds)) - utime.sleep_ms(23) + self.updateClock(disp, time.localtime(set_seconds)) + time.sleep_ms(23) - utime.set_time(int(set_seconds)) - utime.sleep_ms(123) + time.set_time(int(set_seconds)) + time.sleep_ms(123) def circlePoint(self, t): return ( diff --git a/preload/apps/ble/__init__.py b/preload/apps/ble/__init__.py index 893fbde6a75a010104b96577e3a7a33664fd54e9..acf0b13530997eefaea87483283d978edf938c89 100644 --- a/preload/apps/ble/__init__.py +++ b/preload/apps/ble/__init__.py @@ -1,6 +1,6 @@ import os import display -import utime +import time import buttons CONFIG_NAME = "ble.txt" @@ -84,4 +84,4 @@ while True: selector() disp.update() - utime.sleep(0.1) + time.sleep(0.1) diff --git a/preload/apps/bme680_sensor_demo/__init__.py b/preload/apps/bme680_sensor_demo/__init__.py index d0e5279e4badee21944a5c498d908570aeaf0029..1e1d6b6fc8774c0e5011e7d8d6b7a7d6191164e3 100644 --- a/preload/apps/bme680_sensor_demo/__init__.py +++ b/preload/apps/bme680_sensor_demo/__init__.py @@ -7,7 +7,7 @@ import buttons import color import display import os -import utime +import time import bme680 @@ -25,7 +25,7 @@ def main(): disp.print("{:7.2f} rh".format(sensor_data[1]), posy=40) disp.print("{:7.2f} hPa".format(sensor_data[2]), posy=60) disp.update() - utime.sleep(10) + time.sleep(10) if __name__ == "__main__": diff --git a/preload/apps/card10_nickname/__init__.py b/preload/apps/card10_nickname/__init__.py index c6cd1b0b8037252cbc5f33f56ce19122a8c6c2cc..32f8ed786dc1e5d7b78faab2fdae5b165fea4955 100644 --- a/preload/apps/card10_nickname/__init__.py +++ b/preload/apps/card10_nickname/__init__.py @@ -1,10 +1,10 @@ -import utime +import time import display import leds import ledfx import buttons import light_sensor -import ujson +import json import os FILENAME = "nickname.txt" @@ -54,9 +54,9 @@ def blink_led(led): :param led: led to blink """ leds.clear() - utime.sleep(0.1) + time.sleep(0.1) leds.set(led, [255, 0, 0]) - utime.sleep(0.1) + time.sleep(0.1) leds.clear() @@ -118,15 +118,15 @@ def get_time(): :return: timestamp """ timestamp = "" - if utime.localtime()[3] < 10: + if time.localtime()[3] < 10: timestamp = timestamp + "0" - timestamp = timestamp + str(utime.localtime()[3]) + ":" - if utime.localtime()[4] < 10: + timestamp = timestamp + str(time.localtime()[3]) + ":" + if time.localtime()[4] < 10: timestamp = timestamp + "0" - timestamp = timestamp + str(utime.localtime()[4]) + ":" - if utime.localtime()[5] < 10: + timestamp = timestamp + str(time.localtime()[4]) + ":" + if time.localtime()[5] < 10: timestamp = timestamp + "0" - timestamp = timestamp + str(utime.localtime()[5]) + timestamp = timestamp + str(time.localtime()[5]) return timestamp @@ -166,7 +166,7 @@ def render_nickname(title, sub, fg, bg, fg_sub, bg_sub, main_bg, mode, bat): b = 0 rainbow_led_pos = 0 r_sub = sub - last_btn_poll = utime.time() - 2 + last_btn_poll = time.time() - 2 while True: sleep = 0.5 if sub == "#time": @@ -181,8 +181,8 @@ def render_nickname(title, sub, fg, bg, fg_sub, bg_sub, main_bg, mode, bat): r_bg = main_bg[dark] # Button handling pressed = buttons.read(buttons.BOTTOM_LEFT | buttons.BOTTOM_RIGHT) - if utime.time() - last_btn_poll >= 1: - last_btn_poll = utime.time() + if time.time() - last_btn_poll >= 1: + last_btn_poll = time.time() if pressed & buttons.BOTTOM_RIGHT != 0: anim = anim + 1 if anim >= len(ANIM_TYPES): @@ -267,7 +267,7 @@ def render_nickname(title, sub, fg, bg, fg_sub, bg_sub, main_bg, mode, bat): ) disp.update() disp.close() - utime.sleep(sleep) + time.sleep(sleep) def get_key(json, key, default): @@ -291,7 +291,7 @@ with display.open() as disp: if FILENAME_ADV in os.listdir("."): f = open(FILENAME_ADV, "r") try: - c = ujson.loads(f.read()) + c = json.loads(f.read()) f.close() # parse config nick = get_key(c, "nickname", "no nick") diff --git a/preload/apps/digiclk/__init__.py b/preload/apps/digiclk/__init__.py index 72e33fecaa98a9b2cf78574ebf55c3389d4fb610..77fca15c6bcd7587526276cc987cddd89f02fe5c 100644 --- a/preload/apps/digiclk/__init__.py +++ b/preload/apps/digiclk/__init__.py @@ -5,7 +5,7 @@ import display import buttons sys.path.append("/apps/digiclk/") -import monotime as utime +import monotime as time import draw DIGITS = [ @@ -48,7 +48,7 @@ def renderBar(d, num): def render(d): - ltime = utime.localtime() + ltime = time.localtime() years = ltime[0] months = ltime[1] days = ltime[2] @@ -111,7 +111,7 @@ def checkButton(button, button_long, osbutton, pressed, t): def checkButtons(): global pressed_prev - t = utime.time_monotonic_ms() + t = time.time_monotonic_ms() pressed = buttons.read( buttons.BOTTOM_LEFT | buttons.TOP_RIGHT | buttons.BOTTOM_RIGHT ) @@ -130,8 +130,8 @@ def checkButtons(): def modTime(yrs, mth, day, hrs, mns, sec): - ltime = utime.localtime() - new = utime.mktime( + ltime = time.localtime() + new = time.mktime( ( ltime[0] + yrs, ltime[1] + mth, @@ -143,7 +143,7 @@ def modTime(yrs, mth, day, hrs, mns, sec): None, ) ) - utime.set_time(new) + time.set_time(new) def ctrl_display(bs): @@ -334,13 +334,13 @@ def main(): bs = checkButtons() CTRL_FNS[MODE](bs) - last_secs, secs = secs, utime.time_monotonic() + last_secs, secs = secs, time.time_monotonic() if updated or secs > last_secs: render(d) - last_msecs, msecs = msecs, utime.time_monotonic_ms() + last_msecs, msecs = msecs, time.time_monotonic_ms() if msecs - last_msecs < BUTTON_UPDATE_TIME: - utime.sleep_ms(BUTTON_UPDATE_TIME - (msecs - last_msecs)) + time.sleep_ms(BUTTON_UPDATE_TIME - (msecs - last_msecs)) except KeyboardInterrupt: pass diff --git a/preload/apps/digiclk/monotime.py b/preload/apps/digiclk/monotime.py index 3cfbbbc54b9659c36928f772944899108a85eeb8..6227d1cae7165f54fc1fd1f69e9fcd6bea767799 100644 --- a/preload/apps/digiclk/monotime.py +++ b/preload/apps/digiclk/monotime.py @@ -1,42 +1,42 @@ -import utime as _utime +import time as _utime _offset_ms = 0 def time_monotonic(): - return _utime.time() + _offset_ms // 1000 + return _time.time() + _offset_ms // 1000 def time_monotonic_ms(): - return _utime.time_ms() + _offset_ms + return _time.time_ms() + _offset_ms def sleep(s): - return _utime.sleep(s) + return _time.sleep(s) def sleep_ms(ms): - return _utime.sleep_ms(ms) + return _time.sleep_ms(ms) def sleep_us(us): - return _utime.sleep_us(us) + return _time.sleep_us(us) def time(): - return _utime.time() + return _time.time() def time_ms(): - return _utime.time_ms() + return _time.time_ms() def set_time(t): global _offset_ms - cur_t = _utime.time_ms() - _utime.set_time(t) - new_t = _utime.time_ms() + cur_t = _time.time_ms() + _time.set_time(t) + new_t = _time.time_ms() diff = cur_t - new_t _offset_ms += diff @@ -45,9 +45,9 @@ def set_time(t): def set_unix_time(t): global _offset_ms - cur_t = _utime.time_ms() - _utime.set_unix_time(t) - new_t = _utime.time_ms() + cur_t = _time.time_ms() + _time.set_unix_time(t) + new_t = _time.time_ms() diff = cur_t - new_t _offset_ms += diff @@ -55,17 +55,17 @@ def set_unix_time(t): def localtime(s=None): if s != None: - return _utime.localtime(s) + return _time.localtime(s) else: - return _utime.localtime() + return _time.localtime() def mktime(t): - return _utime.mktime(t) + return _time.mktime(t) def alarm(s, cb=None): if cb != None: - return _utime.alarm(s, cb) + return _time.alarm(s, cb) else: - return _utime.alarm(s) + return _time.alarm(s) diff --git a/preload/apps/ecg/__init__.py b/preload/apps/ecg/__init__.py index 775fb2cec01d8170f9aa1ccd2ff34cf7223d2f38..978141d0e7c6722ad31e4ec1f6e976bd4e37195a 100644 --- a/preload/apps/ecg/__init__.py +++ b/preload/apps/ecg/__init__.py @@ -1,7 +1,7 @@ import os import display import leds -import utime +import time import buttons import max30001 import math @@ -178,7 +178,7 @@ def append_to_file(fileprefix, content): def write_pulse(): - # estimates timestamp as calls to utime.time() take too much time + # estimates timestamp as calls to time.time() take too much time approx_timestamp = write + samples_since_start_of_write // config.get_option("Rate") append_to_file("pulse", struct.pack("ib", approx_timestamp, pulse)) @@ -206,7 +206,7 @@ def close_sensor(): def toggle_write(): global write, disp, pause_screen, filebuffer, samples_since_start_of_write, write_time_string - pause_screen = utime.time_ms() + 1000 + pause_screen = time.time_ms() + 1000 disp.clear(COLOR_BACKGROUND) if write > 0: write_filebuffer() @@ -215,8 +215,8 @@ def toggle_write(): disp.print("logging", posx=30, posy=40, fg=COLOR_TEXT) else: filebuffer = bytearray() - write = utime.time() - lt = utime.localtime(write) + write = time.time() + lt = time.localtime(write) write_time_string = "{:04d}-{:02d}-{:02d}_{:02d}{:02d}{:02d}".format(*lt) samples_since_start_of_write = 0 try: @@ -285,7 +285,7 @@ def draw_graph(): if pause_screen == -1: return elif pause_screen > 0: - t = utime.time_ms() + t = time.time_ms() if t > pause_screen: pause_screen = 0 else: @@ -356,7 +356,7 @@ def draw_graph(): # announce writing ecg log if write > 0: - t = utime.time() + t = time.time() if write > 0 and t % 2 == 0: disp.print("LOG", posx=0, posy=60, fg=COLOR_WRITE_FG, bg=COLOR_WRITE_BG) @@ -381,7 +381,7 @@ def main(): "< WriteLog ", posx=0, posy=64, fg=COLOR_WRITE_BG, font=display.FONT16 ) disp.update() - utime.sleep(3) + time.sleep(3) # start ecg open_sensor() diff --git a/preload/apps/lsd_nickname/__init__.py b/preload/apps/lsd_nickname/__init__.py index 8ac8be0f253fa1353344c39bdaaa7b334a95d6b5..bb04c8df5e27e4499080dec6df9b8a871817b723 100644 --- a/preload/apps/lsd_nickname/__init__.py +++ b/preload/apps/lsd_nickname/__init__.py @@ -1,6 +1,6 @@ import display import leds -import utime +import time _rand = 123456789 @@ -43,4 +43,4 @@ while True: d.close() leds.set(rand() % 11, colors[rand() % len(colors)]) leds.set_rocket(rand() % 3, rand() % 32) - utime.sleep_us(1) # Feed watch doge + time.sleep_us(1) # Feed watch doge diff --git a/preload/apps/scope/__init__.py b/preload/apps/scope/__init__.py index b4e861a7ac00b4c14cc14074b18955acaf93ccac..df6f93eeb6a6106022ba54979290fbf9f4dd750d 100644 --- a/preload/apps/scope/__init__.py +++ b/preload/apps/scope/__init__.py @@ -1,6 +1,6 @@ import os import display -import utime +import time import buttons import light_sensor import math @@ -32,4 +32,4 @@ while True: disp.pixel(WIDTH - i, HEIGHT - y - 1) disp.update() - utime.sleep(0.1) + time.sleep(0.1) diff --git a/preload/apps/text_reader/__init__.py b/preload/apps/text_reader/__init__.py index 35a4b084805f3505e062173c10a47ada586001e2..ee8db7fd65402cace48f9c148c76bca8e6e3dc70 100644 --- a/preload/apps/text_reader/__init__.py +++ b/preload/apps/text_reader/__init__.py @@ -7,7 +7,7 @@ import buttons import color import display import os -import utime +import time STATE_LIST = "List" STATE_SHOW = "Show" @@ -64,7 +64,7 @@ def button_events(timeout=0): button_pressed = True yield buttons.TOP_RIGHT - utime.sleep_ms(10) + time.sleep_ms(10) COLOR1, COLOR2 = (color.CHAOSBLUE_DARK, color.CHAOSBLUE) diff --git a/preload/menu.py b/preload/menu.py index 1ace36aa43f5d5ccfe0106eba245320517263ca6..578d456cf63f69ec20acd90d0ef4128389462866 100644 --- a/preload/menu.py +++ b/preload/menu.py @@ -12,8 +12,8 @@ import display import os import simple_menu import sys -import ujson -import utime +import json +import time App = collections.namedtuple("App", ["name", "path"]) @@ -49,7 +49,7 @@ def enumerate_apps(apps=None): try: with open("/apps/" + app + "/metadata.json") as f: - info = ujson.load(f) + info = json.load(f) yield App( info["name"], "/apps/{}/{}".format(app, info.get("bin", "__init__.py")) @@ -74,7 +74,7 @@ def usb_mode(disp): disp.print("open", posx=52, posy=40, fg=color.CAMPGREEN_DARK) disp.update() - utime.sleep_ms(200) + time.sleep_ms(200) # Wait for select button to be released while buttons.read() == buttons.TOP_RIGHT: @@ -104,7 +104,7 @@ class SubMenu(simple_menu.Menu): import config config.set_string("default_app", self.app.path) - utime.sleep(1) + time.sleep(1) self.exit() @@ -127,7 +127,7 @@ class MainMenu(simple_menu.Menu): print("Loading failed: ") sys.print_exception(e) self.error("Loading", "failed") - utime.sleep(1.0) + time.sleep(1.0) os.exit(1) def on_long_select(self, app, index): @@ -168,7 +168,7 @@ def no_apps_message(): disp.update() while True: - utime.sleep(0.5) + time.sleep(0.5) if __name__ == "__main__":