added TimePicker
This commit is contained in:
parent
d5be06edcd
commit
28395a9138
@ -4,6 +4,7 @@ import neopixel
|
|||||||
|
|
||||||
WHITE = (140,70,255)
|
WHITE = (140,70,255)
|
||||||
YELLOW = (127,0,255)
|
YELLOW = (127,0,255)
|
||||||
|
BLUE = (0,255,0)
|
||||||
|
|
||||||
class LEDs():
|
class LEDs():
|
||||||
def __init__(self, pin):
|
def __init__(self, pin):
|
||||||
|
49
Screens.py
49
Screens.py
@ -60,7 +60,7 @@ class InitHandsScreen():
|
|||||||
HW.stepperminu.rotateTo(0)
|
HW.stepperminu.rotateTo(0)
|
||||||
HW.stepperhour.rotateTo(0)
|
HW.stepperhour.rotateTo(0)
|
||||||
HW.housingLEDs.upper((50,50,50))
|
HW.housingLEDs.upper((50,50,50))
|
||||||
timeScreen = GetTimeScreen(\
|
timeScreen = Get2PositionsScreen(\
|
||||||
startTime=(0,0),\
|
startTime=(0,0),\
|
||||||
onStart=lambda _: HW.buzzer.playSound(HW.Buzzer.BEEP),\
|
onStart=lambda _: HW.buzzer.playSound(HW.Buzzer.BEEP),\
|
||||||
onSelectedTimeChange=None,\
|
onSelectedTimeChange=None,\
|
||||||
@ -199,7 +199,7 @@ class GetNumberScreen():
|
|||||||
for b in HW.buttons:
|
for b in HW.buttons:
|
||||||
b.setCallbacks()#Clear Callbacks
|
b.setCallbacks()#Clear Callbacks
|
||||||
|
|
||||||
class GetTimeScreen():
|
class Get2PositionsScreen():
|
||||||
def __init__(self,startTime = (0,0),onStart=None,onSelectedTimeChange = None,onPicked = None):
|
def __init__(self,startTime = (0,0),onStart=None,onSelectedTimeChange = None,onPicked = None):
|
||||||
self.onStart = onStart
|
self.onStart = onStart
|
||||||
self.onSelectedTimeChange = onSelectedTimeChange
|
self.onSelectedTimeChange = onSelectedTimeChange
|
||||||
@ -261,23 +261,24 @@ class GetTimeScreen():
|
|||||||
# TODO This is probably not save as its super unstable around the hour-increments
|
# TODO This is probably not save as its super unstable around the hour-increments
|
||||||
minutes = (60-HW.stepperminu.getOrientation()*60)
|
minutes = (60-HW.stepperminu.getOrientation()*60)
|
||||||
hours = (12-HW.stepperminu.getOrientation()*12)
|
hours = (12-HW.stepperminu.getOrientation()*12)
|
||||||
|
self.pickedTime = (hours,minutes)
|
||||||
self.onSelectedTimeChange(self.pickedTime)
|
self.onSelectedTimeChange(self.pickedTime)
|
||||||
|
|
||||||
|
class GetTimeScreen():
|
||||||
# TODO
|
|
||||||
class GetTimeOnePressScreen():
|
|
||||||
def __init__(self,startTime = (0,0),onStart=None,onSelectedTimeChange = None,onPicked = None):
|
def __init__(self,startTime = (0,0),onStart=None,onSelectedTimeChange = None,onPicked = None):
|
||||||
self.onStart = onStart
|
self.onStart = onStart
|
||||||
self.onSelectedTimeChange = onSelectedTimeChange
|
self.onSelectedTimeChange = onSelectedTimeChange
|
||||||
self.onPicked = onPicked
|
self.onPicked = onPicked
|
||||||
self.running = False
|
self.running = False
|
||||||
self.pickedTime = startTime
|
self.pickedTime = (startTime[0]*60 + startTime[1])%(24*60)
|
||||||
|
self.AM = (self.pickedTime < 12*60)
|
||||||
|
self.direction = 0
|
||||||
|
def calcTupleTime(self):
|
||||||
|
return (int(self.pickedTime/60),self.pickedTime%60)
|
||||||
def __await__(self):
|
def __await__(self):
|
||||||
self.running = True
|
self.running = True
|
||||||
HW.stepperminu.rotateTo(-(self.pickedTime[1])/12)
|
|
||||||
HW.stepperhour.rotateTo(-(self.pickedTime[0])/12)
|
|
||||||
HW.leds[1].flash(1)
|
HW.leds[1].flash(1)
|
||||||
|
HW.housingLEDs.upper(HW.HousingLEDs.BLUE if self.AM else HW.HousingLEDs.YELLOW)
|
||||||
for number,button in enumerate(HW.buttons):
|
for number,button in enumerate(HW.buttons):
|
||||||
button.setCallbacks(\
|
button.setCallbacks(\
|
||||||
onPushDown=lambda i=number:self.onButtonPressed(i),\
|
onPushDown=lambda i=number:self.onButtonPressed(i),\
|
||||||
@ -286,11 +287,19 @@ class GetTimeOnePressScreen():
|
|||||||
while not HW.stepperhour.isAtTarget() or not HW.stepperminu.isAtTarget():
|
while not HW.stepperhour.isAtTarget() or not HW.stepperminu.isAtTarget():
|
||||||
await asyncio.sleep_ms(200)
|
await asyncio.sleep_ms(200)
|
||||||
if self.onStart:
|
if self.onStart:
|
||||||
self.onStart(self.pickedTime)
|
self.onStart(self.calcTupleTime())
|
||||||
while self.running:
|
while self.running:
|
||||||
await asyncio.sleep_ms(200)
|
HW.stepperminu.rotateTo(-(self.pickedTime/60))
|
||||||
|
HW.stepperhour.rotateTo(-(self.pickedTime/60/12))
|
||||||
|
# Color the Top LED to indikate AM or PM
|
||||||
|
self.AM = (self.pickedTime < 12*60)
|
||||||
|
HW.housingLEDs.upper(HW.HousingLEDs.BLUE if self.AM else HW.HousingLEDs.YELLOW)
|
||||||
|
await asyncio.sleep_ms(100)
|
||||||
|
self.pickedTime = (self.pickedTime+self.direction)%(24*60)
|
||||||
|
if self.onSelectedTimeChange:
|
||||||
|
self.onSelectedTimeChange(self.calcTupleTime())
|
||||||
if self.onPicked:
|
if self.onPicked:
|
||||||
self.onPicked(self.pickedTime)
|
self.onPicked(self.calcTupleTime())
|
||||||
|
|
||||||
__iter__ = __await__ # https://github.com/micropython/micropython/issues/2678
|
__iter__ = __await__ # https://github.com/micropython/micropython/issues/2678
|
||||||
def finish(self):
|
def finish(self):
|
||||||
@ -305,24 +314,12 @@ class GetTimeOnePressScreen():
|
|||||||
HW.leds[button].on(overwriteFlashing=False)
|
HW.leds[button].on(overwriteFlashing=False)
|
||||||
else:
|
else:
|
||||||
HW.leds[button].on()
|
HW.leds[button].on()
|
||||||
if self.mode == 0:
|
self.direction = (-1 if button == 0 else 1)
|
||||||
HW.stepperminu.rotateTo(direction=(1 if button == 0 else -1))
|
|
||||||
elif self.mode == 1:
|
|
||||||
HW.stepperhour.rotateTo(direction=(1 if button == 0 else -1))
|
|
||||||
|
|
||||||
def onButtonReleased(self,button,time):
|
def onButtonReleased(self,button,time):
|
||||||
HW.leds[button].off(overwriteFlashing=(button!=1))
|
HW.leds[button].off(overwriteFlashing=(button!=1))
|
||||||
if button == 1:
|
if button == 1:
|
||||||
self.mode=(1+self.mode )% 2
|
|
||||||
if time > 700:
|
if time > 700:
|
||||||
self.finish()
|
self.finish()
|
||||||
else:
|
else:
|
||||||
if self.mode == 0:
|
self.direction = 0
|
||||||
HW.stepperminu.stop()
|
|
||||||
else:
|
|
||||||
HW.stepperhour.stop()
|
|
||||||
if self.onSelectedTimeChange:
|
|
||||||
# TODO This is probably not save as its super unstable around the hour-increments
|
|
||||||
minutes = (60-HW.stepperminu.getOrientation()*60)
|
|
||||||
hours = (12-HW.stepperminu.getOrientation()*12)
|
|
||||||
self.onSelectedTimeChange(self.pickedTime)
|
|
Loading…
x
Reference in New Issue
Block a user