Ejemplo n.º 1
0
def set_lights(light, data):
    print("[PHY]: set_lights[%s], data[%s]" % (light.path, data))
    state = int(data) if data in ("0", "1", 0, 1) else None
    if state is not None:
        light.state = state
        leds.set_state_by_name(light.main_light, state)
        leds.set_state_by_name(light.activity_light, int(not (state)))
        if on_state_change_cb is not None:
            on_state_change_cb(light.path, light.state)
Ejemplo n.º 2
0
def parse_leds(cmd):
    if cmd[1] == "1":
        leds.set_state_by_name("ONBOARD_LED1", int(cmd[2]))
    elif cmd[1] == "2":
        leds.set_state_by_name("ONBOARD_LED2", int(cmd[2]))
    elif cmd[1] == "3":
        leds.set_state_by_name("ONBOARD_LED3", int(cmd[2]))
    elif cmd[1] == "init":
        leds.init()
    elif cmd[1] == "name":
        leds.set_state_by_name(cmd[2], int(cmd[3]))
    else:
        print("[CLI]: \"%s\" not implemented" % (" ".join(cmd)))
Ejemplo n.º 3
0
def check_lights_for_button(alias, state):
    light = get_light_from_alias(alias)
    if light is not None:
        if state:
            leds.set_state_by_name(light.activity_light, 0)
            leds.set_state_by_name(light.inverted_light, 1)
        else:
            leds.set_state_by_name(light.inverted_light, 0)
            set_lights(light, int(not (light.state)))
Ejemplo n.º 4
0
def check_rollos_for_button(alias, state):
    rollo = get_rollo_from_alias(alias)
    if rollo is not None:
        if state:
            if rollo.alarm.active == False:
                if rollo.up.button == alias:
                    leds.set_state_by_name(rollo.up.idle_light, 0)
                    leds.set_state_by_name(rollo.up.pressed_light, 1)
                elif rollo.down.button == alias:
                    leds.set_state_by_name(rollo.down.idle_light, 0)
                    leds.set_state_by_name(rollo.down.pressed_light, 1)
        else:
            if rollo.up.active or rollo.down.active:
                set_rollos(rollo, "STOP")
            else:
                if rollo.up.button == alias:
                    set_rollos(rollo, "UP")
                elif rollo.down.button == alias:
                    set_rollos(rollo, "DOWN")
Ejemplo n.º 5
0
def set_co2allarms(rollo, data):
    print("[PHY]: set_co2allarms[%s], data[%s]" % (rollo.alarm.path, data))
    state = int(data) if data in ("0", "1", 0, 1) else None
    if state is not None:
        rollo.alarm.active = state
        if rollo.alarm.active:
            leds.set_state_by_name(rollo.up.pressed_light, 1)
            leds.set_state_by_name(rollo.up.idle_light, 0)
            leds.set_state_by_name(rollo.down.pressed_light, 1)
            leds.set_state_by_name(rollo.down.idle_light, 0)
        else:
            leds.set_state_by_name(rollo.up.pressed_light, 0)
            leds.set_state_by_name(rollo.up.idle_light, 1)
            leds.set_state_by_name(rollo.down.pressed_light, 0)
            leds.set_state_by_name(rollo.down.idle_light, 1)
Ejemplo n.º 6
0
def set_rollos(rollo, data):
    print("[PHY]: set_rollos[%s], data[%s]" % (rollo.path, data))
    if data == "STOP":
        if rollo.alarm.active == False:
            leds.set_state_by_name(rollo.up.pressed_light, 0)
            leds.set_state_by_name(rollo.up.idle_light, 1)
            leds.set_state_by_name(rollo.down.pressed_light, 0)
            leds.set_state_by_name(rollo.down.idle_light, 1)
        leds.set_state_by_name(rollo.up.relay, 0)
        if rollo.up.active:
            if common.millis_passed(rollo.timestamp) >= rollo.max_timeout:
                rollo.current_position = 100
            else:
                if rollo.current_position is not None:
                    rollo.current_position = rollo.current_position + int(
                        common.millis_passed(rollo.timestamp) /
                        rollo.max_timeout * 100)
                    if rollo.current_position > 100:
                        rollo.current_position = 100
        elif rollo.down.active:
            if common.millis_passed(rollo.timestamp) >= rollo.max_timeout:
                rollo.current_position = 0
            else:
                if rollo.current_position is not None:
                    rollo.current_position = rollo.current_position - int(
                        common.millis_passed(rollo.timestamp) /
                        rollo.max_timeout * 100)
                    if rollo.current_position < 0:
                        rollo.current_position = 0
        print("[PHY]: rollo[%s], position[%s]" %
              (rollo.path, str(rollo.current_position)))
        if on_state_change_cb is not None:
            on_state_change_cb(rollo.path, str(rollo.current_position))
        rollo.up.active = False
        leds.set_state_by_name(rollo.down.relay, 0)
        rollo.down.active = False
        rollo.timeout = None
        rollo.timestamp = None
    else:
        percent = get_percent_from_data(data)
        if percent is not None:
            direction_up = False
            direction_down = False
            timeout = None
            if percent == 100:
                direction_up = True
                timeout = rollo.max_timeout
            elif percent == 0:
                direction_down = True
                timeout = rollo.max_timeout
            else:
                if rollo.current_position is not None:
                    move_percent = percent - rollo.current_position
                    timeout = abs(int(move_percent / 100 * rollo.max_timeout))
                    if move_percent > 0:
                        direction_up = True
                    elif move_percent < 0:
                        direction_down = True
                else:
                    rollo.first_time_position = percent
                    direction_up = True
                    timeout = rollo.max_timeout

            if direction_up:
                if rollo.alarm.active == False:
                    leds.set_state_by_name(rollo.up.pressed_light, 0)
                    leds.set_state_by_name(rollo.up.idle_light, 1)
                if rollo.down.active:
                    leds.set_state_by_name(rollo.down.relay, 0)
                    rollo.down.active = False
                leds.set_state_by_name(rollo.up.relay, 1)
                rollo.up.active = True
                rollo.timeout = timeout
                rollo.timestamp = common.get_millis()
            elif direction_down:
                if rollo.alarm.active == False:
                    leds.set_state_by_name(rollo.down.pressed_light, 0)
                    leds.set_state_by_name(rollo.down.idle_light, 1)
                if rollo.up.active:
                    leds.set_state_by_name(rollo.up.relay, 0)
                    rollo.up.active = False
                leds.set_state_by_name(rollo.down.relay, 1)
                rollo.down.active = True
                rollo.timeout = timeout
                rollo.timestamp = common.get_millis()
def check_signal_led_activity():
    global activity_timestamp
    if activity_timestamp is not None and common.millis_passed(activity_timestamp) >= activity_timeout:
        activity_timestamp = None
        leds.set_state_by_name(ACTIVITY_LED, 0)
def set_activity():
    global activity_timestamp
    activity_timestamp = common.get_millis()
    leds.set_state_by_name(ACTIVITY_LED, 1)
def check_signal_led_mqtt(state):
    if leds.get_state_by_name(MQTT_LED) != int(state):
        leds.set_state_by_name(MQTT_LED, int(state))
def set_signal_led_boot():
    leds.set_state_by_name(BOOT_LED, 1)