Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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())
async def meter(n, x, text, t):
print('Meter {} test.'.format(n))
m = Meter(wri, 5, x, divisions = 4, ptcolor=YELLOW,
label=text, style=Meter.BAR, legends=('0.0', '0.5', '1.0'))
l = LED(wri, ssd.height - 16 - wri.height, x, bdcolor=YELLOW, label ='over')
while True:
v = int.from_bytes(uos.urandom(3),'little')/16777216
m.value(v, color(v))
l.color(color(v))
l.text(txt(v), fgcolor=color(v))
refresh(ssd)
await asyncio.sleep_ms(t)
from writer import CWriter
from nanogui import LED, Meter, refresh
refresh(ssd)
# Fonts
import arial10, freesans20
GREEN = SSD.rgb(0, 255, 0)
RED = SSD.rgb(255, 0, 0)
YELLOW = SSD.rgb(255, 255, 0)
BLACK = 0
color = lambda v : RED if v > 0.7 else YELLOW if v > 0.5 else GREEN
txt = lambda v : 'ovr' if v > 0.7 else 'high' if v > 0.5 else 'ok'
class MyMeter(Meter):
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())
async def _run(self):
while True:
v = int.from_bytes(uos.urandom(3),'little')/16777216
self.value(v, color(v))
self.led.color(color(v))
self.led.text(txt(v), fgcolor=color(v))
# Slow asynchronous data acquisition might occur here. Note
async def meter(n, x, text, t):
print('Meter {} test.'.format(n))
m = Meter(wri, 5, x, divisions = 4, ptcolor=YELLOW,
label=text, style=Meter.BAR, legends=('0.0', '0.5', '1.0'))
l = LED(wri, ssd.height - 16 - wri.height, x, bdcolor=YELLOW, label ='over')
while True:
v = int.from_bytes(uos.urandom(3),'little')/16777216
m.value(v, color(v))
l.color(color(v))
l.text(txt(v), fgcolor=color(v))
refresh(ssd)
await asyncio.sleep_ms(t)