예제 #1
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
예제 #2
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
예제 #3
0
def get_value(index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_async_read("m_flame", "get_value", (), index)
    if value != None:
        return value[0]
    else:
        return 0
예제 #4
0
def get_gesture(index=1):
    if not isinstance(index, (int, float)):
        return False

    value = neurons_async_read("m_fingertip_piano", "get_gesture", (), index)
    if value != None:
        return value[0]
    else:
        return False
예제 #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
예제 #6
0
def is_activated(index=1):
    if not isinstance(index, (int, float)):
        return False

    value = neurons_async_read("m_pir", "get_value", (), index)
    if value != None:
        return bool(value[0])
    else:
        return False
예제 #7
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
예제 #8
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
예제 #9
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
예제 #10
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
예제 #11
0
 def receive_remote_code(index=1):
     if index != 0x01:
         return 0
     value = neurons_async_read("m_halobot", "ir_receive_remote_code", (),
                                index, False)
     if value != None:
         return value[1]
     else:
         return 0
예제 #12
0
def get_all_data(index=1):
    global g_report_time

    if (time.time() - g_report_time) > 1:
        g_report_time = time.time()
        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
예제 #13
0
 def receive(index=1):
     if index != 0x01:
         return 0
     value = neurons_async_read("m_halobot", "ir_receive", (), index, False)
     if value != None:
         data_str = value[0]
         if type(data_str) == str:
             data_str = data_str[0:len(data_str) - 1]
             return data_str
     return 0
예제 #14
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
예제 #15
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
예제 #16
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
예제 #17
0
def get_distance(index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_async_read("m_fingertip_piano", "get_distance", (), index)

    if value:
        return value[0]
    else:
        return 0

    return 0
예제 #18
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
예제 #19
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
예제 #20
0
def is_button_pressed(button_idx, index=1):
    if not isinstance(index, (int, float)):
        return False

    value = neurons_async_read("m_fingertip_piano", "get_button_state", (),
                               index)
    if value:
        if button_idx == 'button1':
            return bool(value[0])
        elif button_idx == 'button2':
            return bool(value[1])
    else:
        return False
예제 #21
0
def get_button_count(button_idx, index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_async_read("m_fingertip_piano", "get_button_count", (),
                               index)
    if value:
        if button_idx == 'button1':
            return value[0]
        elif button_idx == 'button2':
            return value[1]
    else:
        return 0
예제 #22
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
예제 #23
0
 def is_pressed(button, index=1):
     if index != 0x01:
         return False
     if not isinstance(button, (str, )):
         return False
     if button not in button_id_dict.keys():
         return False
     value = neurons_async_read("m_halobot", "ir_receive_remote_code", (),
                                index, False)
     if value != None:
         if value[1] == button_id_dict[button]:
             return True
         else:
             return False
     else:
         return False
예제 #24
0
def is_touchpad_pressed(touchpad_idx, index=1):
    if not isinstance(index, (int, float)):
        return False

    value = neurons_async_read("m_fingertip_piano", "get_touchpad_state", (),
                               index)
    if value:
        if touchpad_idx == 'touchpad1':
            return bool(value[0])
        elif touchpad_idx == 'touchpad2':
            return bool(value[1])
        elif touchpad_idx == 'touchpad3':
            return bool(value[2])
        elif touchpad_idx == 'touchpad4':
            return bool(value[3])
    else:
        return False
예제 #25
0
def get_touchpad_value(touchpad_idx, index=1):
    if not isinstance(index, (int, float)):
        return False

    value = neurons_async_read("m_fingertip_piano", "get_touchpad_value", (),
                               index)
    if value:
        if touchpad_idx == 'touchpad1':
            return value[0]
        elif touchpad_idx == 'touchpad2':
            return value[1]
        elif touchpad_idx == 'touchpad3':
            return value[2]
        elif touchpad_idx == 'touchpad4':
            return value[3]
    else:
        return 0
예제 #26
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
예제 #27
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
예제 #28
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]
예제 #29
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 ""
예제 #30
0
파일: joystick.py 프로젝트: FFtust/mkPython
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