Exemplo n.º 1
0
def get_count(index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_async_read("m_button", "get_pressed_count", (), index)
    if value != None:
        return value[0]
    else:
        return 0
Exemplo n.º 2
0
def power_respond_power_all_state(device_index=1):
    if not isinstance(device_index, (int, float)):
        return False
    ret = neurons_async_read("m_standard_shield", "power_get_power_all_state",
                             (), device_index)
    if ret:
        return ret
    else:
        return False
Exemplo n.º 3
0
def get_value(index=1):
    if not isinstance(index, (int, float)):
        return 0
    value = neurons_async_read("m_light_sensor", "get_intensity", (), index)

    if value:
        return int(value[0])
    else:
        return 0
Exemplo n.º 4
0
def get_distance(index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_async_read("m_ranging_sensor", "get_value", (), index)
    if value != None:
        return round(value[0], 1)
    else:
        return 0
Exemplo n.º 5
0
def is_active(index = 1):
    if not isinstance(index, (int, float)):
        return False

    value = neurons_async_read("m_flame", "get_value", (), index)
    if value != None:
        return bool(value[0] > FLAME_ACTIVE_THRESHOLD)
    else:
        return False
Exemplo n.º 6
0
def get_angle(index=1):
    if (not isinstance(index, (int, ))) or (index <= 0):
        return 0
    value = neurons_async_read("m_smartservo", "get_position", (0x01), index)

    if value != None:
        return -int(value[0])
    else:
        return 0
Exemplo n.º 7
0
def get_loudness(index=1):
    if not isinstance(index, (int, float)):
        return 0
    value = neurons_async_read("m_sound_sensor", "get_loudness", (), index)

    if value:
        return int(value[0])
    else:
        return 0
Exemplo n.º 8
0
def get_relative_humidity(index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_async_read("m_humiture_sensor", "get_value", (), index)
    if value != None:
        return int(value[1])
    else:
        return 0
Exemplo n.º 9
0
def get_value(index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_async_read("m_slider", "get_value", (), index)
    if value != None:
        return value[0]
    else:
        return 0
Exemplo n.º 10
0
def get_humidity(index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_async_read("m_soil_moisture", "get_value", (), index)
    if value != None:
        return int(value[0])
    else:
        return 0
Exemplo n.º 11
0
def is_pressed(index=1):
    if not isinstance(index, (int, float)):
        return False

    value = neurons_async_read("m_button", "get_value", (), index)
    if value != None:
        return bool(value[0])
    else:
        return False
Exemplo n.º 12
0
def get_count(index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_async_read("m_magneto_dependent_sensor", "get_count", (),
                               index)
    if value != None:
        return value[0]
    else:
        return 0
Exemplo n.º 13
0
def get_all_data(index=1):
    global g_report_time

    if time.ticks_ms() - g_report_time > 1000:
        g_report_time = time.ticks_ms()
        set_report_mode(__PERIOD_REPORT_MODE, __REPORT_TIME, index)
    value = neurons_async_read("m_dual_rgb_sensor", "get_all_data", (),
                               index)  #0.25ms

    return value
Exemplo n.º 14
0
def is_active(index=1):
    if not isinstance(index, (int, float)):
        return False

    value = neurons_async_read("m_magneto_dependent_sensor", "get_value", (),
                               index)
    if value != None:
        return bool(value[0])
    else:
        return False
Exemplo n.º 15
0
def get_distance(index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_async_read("m_ultrasonic_sensor", "get_centimeter", (),
                               index)
    if value != None:
        return round(value[0], 1)
    else:
        return 0
Exemplo n.º 16
0
def get_cycles(index=1):
    if (not isinstance(index, (int, ))) or (index <= 0):
        return 0
    value = neurons_async_read("m_smartservo", "get_position", (0x01), index)
    # print(value)
    if value != None:
        cycles = -int(value[0] / 360)
        return cycles
    else:
        return 0
Exemplo n.º 17
0
def get_value(position, index = 1):
    if not isinstance(position, (int, float)):
        return 0
    if not isinstance(index, (int, float)):
        return 0
    position = num_range_scale(position, 1, 8)

    value = neurons_async_read("m_mult_touch", "get_value", position, index)
    if value != None:
        return value[0]
    else:
        return 0
Exemplo n.º 18
0
def is_active(level = "middle", index = 1):
    if not isinstance(index, (int, float)):
        return False
    if level in GAS_ACTIVITED_THRESOLD:
        thes = GAS_ACTIVITED_THRESOLD[level]
    else:
        thes = GAS_ACTIVITED_THRESOLD["middle"]

    value = neurons_async_read("m_mq2_sensor", "get_value", (), index)
    if value != None:
        return bool(value[0] > thes)
    else:
        return False
Exemplo n.º 19
0
def get_speed(index=1):
    if (not isinstance(index, (int, ))) or (index <= 0):
        return 0
    value = neurons_async_read("m_smartservo", "get_speed", (0x01), index)

    if value != None:
        if value[0] == (-1) or value[0] == (0) or value[0] == (
                1) or value[0] == (2):
            return 0
        else:
            # speed unit for users is degree per second
            # but real speed unit is rpm(revolutions per minute)
            return -int(value[0] * SPEED_RPM_TO_DPS)
    else:
        return 0
Exemplo n.º 20
0
def receive_remote_code(index = 1):
    if not isinstance(index, (int, float)):
        return [0, 0]

    if not isinstance(index, (int, float)):
        return [0, 0]
        
    value = neurons_async_read("m_ir_sensor", "read_cmd", (), index, request_first = False)
    # ir sensor is processed specially
    if len(value) == 1:
        return [0 , 0]
    else:
        if time.ticks_ms() - value[-1] < RECEIVING_INTERVAL_THRESHOLD:
            return value[0 : 2]
        else:
            return [0, 0]
Exemplo n.º 21
0
def receive(index = 1):
    global last_receing_time

    if not isinstance(index, (int, float)):
        return ""

    value = neurons_async_read("m_ir_sensor", "read_str", (), index, request_first = False)
    # ir sensor is processed specially
    if len(value) == 1:
        return ""
    else:
        if (last_receing_time != value[-1]) and (time.ticks_ms() - value[-1] < RECEIVING_INTERVAL_THRESHOLD):
            last_receing_time = value[-1]
            return value[0]
        else:
            return ""
Exemplo n.º 22
0
def is_active(ch, index = 1):
    if not isinstance(ch, (int, float)):
        if ch != "any":
            return False
    if not isinstance(index, (int, float)):
        return False
   
    value = neurons_async_read("m_mult_touch", "get_status", (), index)
    if value != None:
        if ch == "any":
            return bool(value[0])
        else:
            ch = round(ch)
            if ch > 8 or ch < 1:
                return False
            return bool(value[0] & (1 << ch - 1))
    else:
        return False
Exemplo n.º 23
0
def get_temperature(opt="celsius", index=1):
    if not isinstance(index, (int, float)):
        return 0
    if opt != "celsius" and opt != "fahrenheit":
        return 0

    if not neurons_is_block_online("m_humiture_sensor", index):
        return 0

    value = neurons_async_read("m_humiture_sensor", "get_value", (), index)

    if value:
        if opt == "fahrenheit":
            ret = _cal_fahrenheit_from_celsius(value[0])
            return int(ret)
        elif opt == "celsius":
            return int(value[0])
    else:
        return 0
Exemplo n.º 24
0
def get_value(opt, index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_async_read("m_joystick", "get_value", (), index)

    if value:
        if opt == 'x':
            return value[0]
        elif opt == 'y':
            return value[1]
        elif opt == 'all':
            return value

    else:
        if opt == 'all':
            return [0, 0]
        elif opt == 'y':
            return 0

    return 0
Exemplo n.º 25
0
def get_all_status(index = 1):
    value = neurons_async_read("m_mult_touch", "get_status", (), index)
    if value != None:
        return value[0]
    else:
        return 0x00