2020-10-17 16:04:44 +00:00
|
|
|
from enum import Enum
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
subscribers = []
|
2019-02-07 22:03:28 +00:00
|
|
|
|
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
class State(Enum):
|
|
|
|
HOOK = 60,
|
|
|
|
STICK = 18,
|
|
|
|
LOOK = 100,
|
|
|
|
IDLE = -1
|
2019-02-07 22:03:28 +00:00
|
|
|
|
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
def _notify(event):
|
|
|
|
for subscriber in subscribers:
|
|
|
|
subscriber(event)
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2019-06-29 20:35:53 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
class FishingMode:
|
|
|
|
CurrentMode = State.IDLE
|
|
|
|
PrevMode = State.IDLE
|
2019-02-07 22:03:28 +00:00
|
|
|
|
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
def loop(hue_values):
|
|
|
|
"""
|
|
|
|
Executed in the start of the main loop in fishy.py
|
|
|
|
Changes modes, calls mode events (callbacks) when mode is changed
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
:param hue_values: hue_values read by the bot
|
|
|
|
"""
|
|
|
|
FishingMode.CurrentMode = State.IDLE
|
|
|
|
for s in State:
|
|
|
|
if hue_values == s.value:
|
|
|
|
FishingMode.CurrentMode = s
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
if FishingMode.CurrentMode != FishingMode.PrevMode:
|
|
|
|
_notify(FishingMode.CurrentMode)
|
2019-02-07 22:03:28 +00:00
|
|
|
|
2020-10-17 16:04:44 +00:00
|
|
|
FishingMode.PrevMode = FishingMode.CurrentMode
|