2022-01-24 19:12:59 +00:00
|
|
|
from email.policy import default
|
2021-10-19 10:10:04 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
import click
|
|
|
|
import logging
|
|
|
|
|
2022-01-24 13:49:06 +00:00
|
|
|
from pizzactrl.statemachine import Statemachine, State
|
|
|
|
from pizzactrl.sb_showcase import STORYBOARD
|
|
|
|
from pizzactrl.hal_serial import PizzaHAL
|
2021-10-19 10:10:04 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger('pizzactrl.main')
|
|
|
|
|
|
|
|
|
|
|
|
@click.command()
|
|
|
|
@click.option('--test', is_flag=True, default=False)
|
|
|
|
@click.option('--debug', is_flag=True, default=False)
|
2021-11-19 15:09:49 +00:00
|
|
|
@click.option('--loop', is_flag=True, default=False)
|
2022-01-24 19:12:59 +00:00
|
|
|
def main(test: bool=False, debug: bool=False, loop: bool=False):
|
2021-10-19 10:10:04 +00:00
|
|
|
if debug or test:
|
|
|
|
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
|
|
|
|
else:
|
|
|
|
logging.basicConfig(level=logging.INFO, stream=sys.stdout)
|
|
|
|
|
2022-01-24 13:49:06 +00:00
|
|
|
hal = PizzaHAL()
|
2022-01-24 19:12:59 +00:00
|
|
|
sm = Statemachine(hal, STORYBOARD, loop=loop, test=test)
|
2022-01-24 13:49:06 +00:00
|
|
|
|
2021-10-19 10:10:04 +00:00
|
|
|
sm.test = test
|
|
|
|
|
|
|
|
exitcode = 0
|
|
|
|
try:
|
|
|
|
sm.run()
|
|
|
|
finally:
|
|
|
|
if sm.state is State.ERROR:
|
|
|
|
exitcode = 2
|
|
|
|
del sm
|
|
|
|
sys.exit(exitcode)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|