Пример #1
0
def main():
    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(4, GPIO.OUT)
    GPIO.output(4, GPIO.LOW)
    time.sleep(3)
    GPIO.cleanup()

    data_provider = DataProvider(DB_PATH)

    configuration = WeightProcessorConfiguration(MAX_PAUSE_BETWEEN_MORNING_CHECKS_IN_DAYS,
                                                 MAX_WEIGHT_DIFF_BETWEEN_MORNING_CHECKS,
                                                 USERS_MAX_W_DIFF,
                                                 MORNING_HOURS)

    user_provider = UserProvider(USERS)
    weight_processor = WeightProcessor(data_provider,
                                       configuration,
                                       user_provider,
                                       FitbitConnector(FITBIT_CLIENT_ID, FITBIT_CLIENT_SECRET, user_provider))

    events_processor = EventProcessor(weight_processor)
    board = Wiiboard(events_processor)

    if len(sys.argv) == 1:
        logging.debug("Discovering board...")
        address = board.discover()
    else:
        address = sys.argv[1]

    logging.debug("Trying to connect...")
    board.connect(address)  # The wii board must be in sync mode at this time
    board.set_light(False)

    while 1 == 1:
        events_processor.reset()
        board.receive()

        weight = events_processor.weight + 2

        weight_record = WeightRecord({'year': datetime.today().year,
                                      'month': datetime.today().month,
                                      'day': datetime.today().day,
                                      'w': weight})

        user = weight_processor.get_user_by_weight(weight)
        display.render(str(weight), WHITE, safe_text(user))
        weight_processor.process(weight_record)
        display.render_graph(data_provider.all_mornings(user))

        board.set_light(False)
        logging.debug('Ready for next job')