2020-01-31 20:36:55 +01:00
|
|
|
import time
|
|
|
|
def sleep_ms(ms):
|
|
|
|
time.sleep(ms / 1000)
|
|
|
|
time.sleep_ms = sleep_ms
|
|
|
|
|
2020-03-09 00:16:30 +01:00
|
|
|
import draw565
|
|
|
|
|
2020-03-07 12:50:26 +01:00
|
|
|
from machine import I2C
|
2020-01-31 20:36:55 +01:00
|
|
|
from machine import Pin
|
|
|
|
from machine import SPI
|
|
|
|
|
2020-03-07 12:50:26 +01:00
|
|
|
from drivers.cst816s import CST816S
|
2020-01-31 20:36:55 +01:00
|
|
|
from drivers.st7789 import ST7789_SPI
|
|
|
|
from drivers.vibrator import Vibrator
|
|
|
|
|
2020-02-23 21:19:37 +01:00
|
|
|
|
2020-02-01 21:20:53 +01:00
|
|
|
class Backlight(object):
|
|
|
|
def __init__(self, level=1):
|
2020-03-09 00:16:30 +01:00
|
|
|
pass
|
2020-02-01 21:20:53 +01:00
|
|
|
|
|
|
|
def set(self, level):
|
2020-03-09 00:16:30 +01:00
|
|
|
"""Set the simulated backlight level.
|
|
|
|
|
|
|
|
This function contains a subtle trick. As soon as the backlight is
|
|
|
|
turned off (e.g. the watch goes to sleep) then we will simulate
|
|
|
|
a button press in order to turn the watch back on again.
|
|
|
|
"""
|
2020-02-01 21:20:53 +01:00
|
|
|
print(f'BACKLIGHT: {level}')
|
|
|
|
|
2020-02-23 21:19:37 +01:00
|
|
|
button.value(bool(level))
|
|
|
|
|
2020-02-03 23:29:57 +01:00
|
|
|
class Battery(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.voltage = 3.9
|
|
|
|
self.step = -0.01
|
|
|
|
self.powered = False
|
|
|
|
|
|
|
|
def charging(self):
|
|
|
|
self.voltage_mv()
|
|
|
|
return self.powered
|
|
|
|
|
|
|
|
def power(self):
|
|
|
|
self.voltage_mv()
|
|
|
|
return self.powered
|
|
|
|
|
|
|
|
def voltage_mv(self):
|
|
|
|
if self.voltage > 4:
|
2020-02-23 21:19:37 +01:00
|
|
|
self.step = -0.01
|
2020-02-03 23:29:57 +01:00
|
|
|
self.powered = False
|
|
|
|
elif self.voltage < 3.4:
|
2020-02-23 21:19:37 +01:00
|
|
|
self.step = 0.04
|
2020-02-03 23:29:57 +01:00
|
|
|
self.powered = True
|
|
|
|
self.voltage += self.step
|
|
|
|
|
|
|
|
return int(self.voltage * 1000)
|
|
|
|
|
|
|
|
def level(self):
|
|
|
|
mv = self.voltage_mv()
|
|
|
|
level = ((19 * mv) // 100) - 660
|
|
|
|
if level > 100:
|
|
|
|
return 100
|
|
|
|
if level < 0:
|
|
|
|
return 0
|
|
|
|
return level
|
|
|
|
|
2020-02-03 20:23:10 +01:00
|
|
|
class RTC(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.uptime = 0
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
now = time.time()
|
|
|
|
if now == self.uptime:
|
|
|
|
return False
|
|
|
|
self.uptime = now
|
|
|
|
return True
|
|
|
|
|
2020-02-19 20:32:06 +01:00
|
|
|
def get_localtime(self):
|
|
|
|
return time.localtime()
|
|
|
|
|
2020-02-03 20:23:10 +01:00
|
|
|
def get_time(self):
|
|
|
|
now = time.localtime()
|
|
|
|
return (now[3], now[4], now[5])
|
|
|
|
|
|
|
|
def uptime(self):
|
2020-03-07 12:50:26 +01:00
|
|
|
return time.time()
|
|
|
|
|
|
|
|
def get_uptime_ms(self):
|
|
|
|
return int(time.time() * 1000)
|
2020-02-03 20:23:10 +01:00
|
|
|
|
2020-02-01 21:20:53 +01:00
|
|
|
backlight = Backlight()
|
2020-03-09 00:16:30 +01:00
|
|
|
spi = SPI(0)
|
|
|
|
spi.init(polarity=1, phase=1, baudrate=8000000)
|
|
|
|
display = ST7789_SPI(240, 240, spi,
|
|
|
|
cs=Pin("DISP_CS", Pin.OUT, quiet=True),
|
|
|
|
dc=Pin("DISP_DC", Pin.OUT, quiet=True),
|
|
|
|
res=Pin("DISP_RST", Pin.OUT, quiet=True))
|
|
|
|
drawable = draw565.Draw565(display)
|
|
|
|
|
2020-02-03 23:29:57 +01:00
|
|
|
battery = Battery()
|
2020-03-09 00:16:30 +01:00
|
|
|
button = Pin('BUTTON', Pin.IN, quiet=True)
|
2020-02-03 20:23:10 +01:00
|
|
|
rtc = RTC()
|
2020-03-09 00:16:30 +01:00
|
|
|
touch = CST816S(I2C(0))
|
2020-01-31 20:36:55 +01:00
|
|
|
vibrator = Vibrator(Pin('MOTOR', Pin.OUT, value=0), active_low=True)
|
2020-02-03 20:23:10 +01:00
|
|
|
|