def aclock(): uv = lambda phi : cmath.rect(1, phi) # Return a unit vector of phase phi pi = cmath.pi days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday') months = ('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec') # Instantiate CWriter CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False) wri.set_clip(True, True, False) # Instantiate displayable objects dial = Dial(wri, 2, 2, height = 75, ticks = 12, bdcolor=None, label=120, pip=False) # Border in fg color lbltim = Label(wri, 5, 85, 35) hrs = Pointer(dial) mins = Pointer(dial) secs = Pointer(dial) hstart = 0 + 0.7j # Pointer lengths and position at top mstart = 0 + 0.92j sstart = 0 + 0.92j while True: t = utime.localtime() hrs.value(hstart * uv(-t[3]*pi/6 - t[4]*pi/360), YELLOW) mins.value(mstart * uv(-t[4] * pi/30), YELLOW) secs.value(sstart * uv(-t[5] * pi/30), RED) lbltim.value('{:02d}.{:02d}.{:02d}'.format(t[3], t[4], t[5])) dial.text('{} {} {} {}'.format(days[t[6]], t[2], months[t[1] - 1], t[0])) refresh(ssd) utime.sleep(1)
def main(): print('alevel test is running.') CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False) wri.set_clip(True, True, False) acc = pyb.Accel() dial = Dial(wri, 5, 5, height=75, ticks=12, bdcolor=None, label='Tilt Pyboard', style=Dial.COMPASS, pip=YELLOW) # Border in fg color ptr = Pointer(dial) scale = 1 / 40 while True: x, y, z = acc.filtered_xyz() # Depending on relative alignment of display and Pyboard this line may # need changing: swap x and y or change signs so arrow points in direction # board is tilted. ptr.value(-y * scale + 1j * x * scale, YELLOW) refresh(ssd) utime.sleep_ms(200)
async def aclock(): do_connect.do_connect() asyncio.create_task(set_rtc()) asyncio.create_task(ramcheck()) uv = lambda phi: cmath.rect(1, phi) # Return a unit vector of phase phi pi = cmath.pi days = ('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday') months = ('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December') # Instantiate CWriter CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it wri = CWriter(ssd, font, GREEN, BLACK, verbose=False) wri.set_clip(True, True, False) # Instantiate displayable objects dial = Dial(wri, 2, 2, height=130, ticks=12, bdcolor=None) # Border in fg color lbltim = Label(wri, 140, 2, 130) lblday = Label(wri, 170, 2, 130) lblmonth = Label(wri, 190, 2, 130) lblyr = Label(wri, 210, 2, 130) hrs = Pointer(dial) mins = Pointer(dial) secs = Pointer(dial) hstart = 0 + 0.7j # Pointer lengths and position at top mstart = 0 + 0.92j sstart = 0 + 0.92j t = time.localtime() while True: hrs.value(hstart * uv(-t[3] * pi / 6 - t[4] * pi / 360), YELLOW) mins.value(mstart * uv(-t[4] * pi / 30 - t[5] * pi / 1800), YELLOW) secs.value(sstart * uv(-t[5] * pi / 30), RED) lbltim.value('{:02d}.{:02d}.{:02d} {}'.format(t[3], t[4], t[5], 'BST' if bst else 'UTC')) lblday.value('{}'.format(days[t[6]])) lblmonth.value('{} {}'.format(t[2], months[t[1] - 1])) lblyr.value('{}'.format(t[0])) refresh(ssd) st = t while st == t: await asyncio.sleep_ms(100) t = time.localtime()
def __init__(self, x, text): CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False) wri.set_clip(True, True, False) super().__init__(wri, 5, x, divisions=4, ptcolor=YELLOW, label=text, style=Meter.BAR, legends=('0.0', '0.5', '1.0')) self.led = LED(wri, ssd.height - 16 - wri.height, x, bdcolor=YELLOW, label='over') self.task = asyncio.create_task(self._run())
def test(): def tickcb(f, c): if f > 0.8: return RED if f < -0.8: return BLUE return c def legendcb(f): return '{:2.0f}'.format(88 + ((f + 1) / 2) * (108 - 88)) refresh(ssd, True) # Initialise and clear display. CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False) wri.set_clip(True, True, False) scale1 = Scale(wri, 2, 2, width=124, legendcb=legendcb, pointercolor=RED, fontcolor=YELLOW) asyncio.create_task(radio(scale1)) lbl = Label(wri, ssd.height - wri.height - 2, 2, 50, bgcolor=DARKGREEN, bdcolor=RED, fgcolor=WHITE) # do_refresh is called with arg 4. In landscape mode this splits screen # into segments of 240/4=60 lines. Here we ensure a scale straddles # this boundary scale = Scale(wri, 55, 2, width=124, tickcb=tickcb, pointercolor=RED, fontcolor=YELLOW, bdcolor=CYAN) asyncio.run(default(scale, lbl))
def test(): def tickcb(f, c): if f > 0.8: return RED if f < -0.8: return BLUE return c def legendcb(f): return '{:2.0f}'.format(88 + ((f + 1) / 2) * (108 - 88)) refresh(ssd) # Initialise and clear display. CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False) wri.set_clip(True, True, False) scale1 = Scale(wri, 2, 2, width=124, legendcb=legendcb, pointercolor=RED, fontcolor=YELLOW) asyncio.create_task(radio(scale1)) lbl = Label(wri, ssd.height - wri.height - 2, 2, 50, bgcolor=DARKGREEN, bdcolor=RED, fgcolor=WHITE) scale = Scale(wri, 45, 2, width=124, tickcb=tickcb, pointercolor=RED, fontcolor=YELLOW, bdcolor=CYAN) asyncio.run(default(scale, lbl))
from gui.core.nanogui import refresh from gui.widgets.led import LED from gui.widgets.meter import Meter from gui.widgets.label import Label refresh(ssd, True) # Fonts import gui.fonts.arial10 as arial10 from gui.core.writer import Writer, CWriter import utime import uos from gui.core.colors import * CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False) wri.set_clip(True, True, False) def meter(): print('meter') refresh(ssd, True) # Clear any prior image m = Meter(wri, 5, 2, height=45, divisions=4, ptcolor=YELLOW, label='level', style=Meter.BAR,
def test(): refresh(ssd, True) # Initialise and clear display. CWriter.set_textpos(ssd, 0, 0) # In case previous tests have altered it wri = CWriter(ssd, arial10, verbose=False) wri.set_clip(True, True, False) asyncio.run(main(wri))