Beispiel #1
0
def show(message, pos_x=None, pos_y=None, wait=True, index=1):
    if not isinstance(index, (int, float)):
        return 0

    message = str(message)
    if message == '':
        clear()
        return

    str_len = len(message)
    if pos_x != None or pos_y != None:
        if pos_x == None:
            pos_x = 0
        if pos_y == None:
            pos_y = 0

        if (not isinstance(pos_x, (int, float))) or (not isinstance(
                pos_y, (int, float))):
            return
        pos_x = int(pos_x)
        pos_y = int(pos_y)
        neurons_request("m_led_panel", "show_str_with_pos",
                        (pos_x, pos_y, message), index)
    else:
        if wait:
            neurons_request("m_led_panel", "show_str_until_done", message,
                            index)
            while neurons_blocking_read("m_led_panel", "get_status",
                                        (), index) != [1]:
                if not neurons_is_block_online("m_led_panel", index):
                    return
                time.sleep(0.1)
        else:
            neurons_request("m_led_panel", "show_str", message, index)
Beispiel #2
0
def servo_get_angle_both(device_index=1):
    if not isinstance(device_index, (int, float)):
        return -1
    value = neurons_blocking_read("m_standard_shield", "servo_get_angle_both",
                                  (), device_index)
    if value != None:
        return value
    else:
        return [0, 0]
Beispiel #3
0
def power_get_battery_level(device_index=1):
    if not isinstance(device_index, (int, float)):
        return 0
    ret = neurons_blocking_read("m_standard_shield", "power_get_battery_level",
                                (), device_index)
    if ret:
        return ret[0]
    else:
        return 0
Beispiel #4
0
def power_get_power_all_state(device_index=1):
    if not isinstance(device_index, (int, float)):
        return 0
    ret = neurons_blocking_read("m_standard_shield",
                                "power_get_power_all_state", (), device_index)
    if ret:
        return ret
    else:
        return 0
Beispiel #5
0
def power_get_charge_state(device_index=1):
    if not isinstance(device_index, (int, float)):
        return 0
    ret = neurons_blocking_read("m_starter_shield", "power_get_charge_state",
                                (), device_index)
    if ret:
        return ret[0]
    else:
        return 0
Beispiel #6
0
def is_rotating_anticlockwise(index=1):
    if not isinstance(index, (int, float)):
        return False

    value = neurons_blocking_read("m_angle_sensor", "get_dir", (), index)
    if value[0] == ANTICLOCKWISE_VALUE:
        return True
    else:
        return False
Beispiel #7
0
def get_load(index=1):
    if not isinstance(index, (int, float)):
        return 0

    ret = neurons_blocking_read("m_dc_motor", "get_load", (), index)
    if ret:
        return ret[0]
    else:
        return 0
Beispiel #8
0
def get_load(index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_blocking_read("m_servo", "get_load", (), index)
    if value != None:
        return value[0]
    else:
        return 0
Beispiel #9
0
def is_playing(index=1):
    if not isinstance(index, (int, float)):
        return False

    value = neurons_blocking_read("m_speaker", "get_status", (), index)
    if value == None:
        return False
    else:
        return bool(value[0])
Beispiel #10
0
def get_volume(index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_blocking_read("m_speaker", "get_volume", (), index)
    if value == None:
        return 0
    else:
        return value[0]
Beispiel #11
0
def get_barcode_count(index=1):  #获取按键的信息
    if (not isinstance(index, (int, float))) or (index <= 0):
        return 0
    value = neurons_blocking_read("m_smart_camera", "get_barcode_count", (),
                                  index)
    if value != None:
        return value[0]
    else:
        return 0
Beispiel #12
0
def get_learn_data(index=1):  #获取学习的信息
    if (not isinstance(index, (int, float))) or (index <= 0):
        return 0
    value = neurons_blocking_read("m_smart_camera", "get_learn_data", (),
                                  index)
    if value != None:
        return value
    else:
        return 0
Beispiel #13
0
def get_angle_speed(index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_blocking_read("m_angle_sensor", "get_angle_speed", (),
                                  index)
    if value != None:
        return value[0]
    else:
        return 0
Beispiel #14
0
def get_crossings_line_angle_sigle_data(index=1):  #获取交叉口线角度的单独的信息
    if (not isinstance(index, (int, float))) or (index <= 0):
        return 0
    value = neurons_blocking_read("m_smart_camera",
                                  "get_crossings_line_angle_sigle_data", (),
                                  index)
    if value != None:
        return value
    else:
        return 0
Beispiel #15
0
def get_gyroscope(axis, index=1):
    if not isinstance(index, (int, float)):
        return 0

    if axis == 'x':
        value = neurons_blocking_read("m_motion_sensor", "get_gyr_x",
                                      (INQUIRE_ID, GYRO_X_ID), index)
    elif axis == 'y':
        value = neurons_blocking_read("m_motion_sensor", "get_gyr_y",
                                      (INQUIRE_ID, GYRO_Y_ID), index)
    elif axis == 'z':
        value = neurons_blocking_read("m_motion_sensor", "get_gyr_z",
                                      (INQUIRE_ID, GYRO_Z_ID), index)
    else:
        return 0

    if value != None:
        return value[0]
    else:
        return 0
Beispiel #16
0
def get_acceleration(axis, index=1):
    if not isinstance(index, (int, float)):
        return 0

    if axis == 'x':
        value = neurons_blocking_read("m_motion_sensor", "get_acc_x",
                                      (INQUIRE_ID, ACC_X_ID), index)
    elif axis == 'y':
        value = neurons_blocking_read("m_motion_sensor", "get_acc_y",
                                      (INQUIRE_ID, ACC_Y_ID), index)
    elif axis == 'z':
        value = neurons_blocking_read("m_motion_sensor", "get_acc_z",
                                      (INQUIRE_ID, ACC_Z_ID), index)
    else:
        return 0

    if value != None:
        return value[0] * ACC_SHIFT
    else:
        return 0
Beispiel #17
0
def get_roll(index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_blocking_read("m_motion_sensor", "get_roll",
                                  (INQUIRE_ID, ROLL_ID), index)

    if value != None:
        return value[0]
    else:
        return 0
Beispiel #18
0
def get_rotation(axis, index=1):
    if not isinstance(index, (int, float)):
        return 0

    if axis == 'x':
        value = neurons_blocking_read("m_motion_sensor", "get_rotate_x",
                                      (INQUIRE_ID, ROTATE_X_ID), index)
    elif axis == 'y':
        value = neurons_blocking_read("m_motion_sensor", "get_rotate_y",
                                      (INQUIRE_ID, ROTATE_Y_ID), index)
    elif axis == 'z':
        value = neurons_blocking_read("m_motion_sensor", "get_rotate_z",
                                      (INQUIRE_ID, ROTATE_Z_ID), index)
    else:
        return 0

    if value != None:
        return value[0]
    else:
        return 0
Beispiel #19
0
def get_crossings_all_data(index=1):  #获交叉口的所有信息
    if (not isinstance(index, (int, float))) or (index <= 0):
        return 0
    value = neurons_blocking_read("m_smart_camera", "get_crossings_all_data",
                                  (), index)
    if value != None:
        value[0] = round(value[0] * FRAME_REVISE_COE_LINE_X)
        value[1] = round(value[1] * FRAME_REVISE_COE_LINE_Y)
        return value
    else:
        return 0
Beispiel #20
0
def get_shake_strength(index=1):
    if not isinstance(index, (int, float)):
        return 0

    value = neurons_blocking_read("m_motion_sensor", "get_shake_strength",
                                  (INQUIRE_ID, SHAKE_ID), index)

    if value != None:
        return round(value[0], 1)
    else:
        return 0
Beispiel #21
0
def get_led_bri(led_index, index=1):
    if not isinstance(index, (int, float)):
        return 0
    if led_index not in [1, 2, 3, 4, 5, 6, 7, 8]:
        return
    value = neurons_blocking_read("m_led_ultrasonic_sensor", "get_led_bri", (),
                                  index)
    if value != None:
        return value[led_index - 1]
    else:
        return 0
Beispiel #22
0
def encoder_motor_get_speed(motor_index=1, device_index=1):
    if not isinstance(motor_index, (int, float)):
        return -1
    if not isinstance(device_index, (int, float)):
        return -1
    if motor_index not in [1, 2]:
        return -1
    ret = neurons_blocking_read("m_starter_shield", "encoder_motor_get_speed",
                                (motor_index), device_index)
    if ret:
        return ret[1]
    else:
        return 0
Beispiel #23
0
def dc_motor_get_power(motor_index=1, device_index=1):
    if not isinstance(motor_index, (int, float)):
        return -1
    if not isinstance(device_index, (int, float)):
        return -1
    if motor_index not in [1, 2]:
        return -1
    ret = neurons_blocking_read("m_standard_shield", "dc_motor_get_power",
                                (motor_index), device_index)
    if ret:
        return ret[1]
    else:
        return 0
Beispiel #24
0
def servo_get_angle(servo_index=1, device_index=1):
    if not isinstance(servo_index, (int, float)):
        return -1
    if not isinstance(device_index, (int, float)):
        return -1
    if servo_index not in [1, 2, 3, 4]:
        return -1
    value = neurons_blocking_read("m_starter_shield", "servo_get_angle",
                                  (servo_index), device_index)
    if value != None:
        return value[1]
    else:
        return 0
Beispiel #25
0
def servo_get_load(servo_index=1, device_index=1):
    if not isinstance(servo_index, (int, float)):
        return -1
    if not isinstance(device_index, (int, float)):
        return -1
    if servo_index not in [1, 2]:
        return -1
    value = neurons_blocking_read("m_standard_shield", "servo_get_load",
                                  (servo_index), device_index)
    if value != None:
        return value[0]
    else:
        return 0
Beispiel #26
0
def led_strip_get_brightness(strip_index=1, device_index=1):
    if not isinstance(strip_index, (int, float)):
        return -1
    if not isinstance(device_index, (int, float)):
        return -1
    if strip_index not in [1, 2]:
        return -1
    ret = neurons_blocking_read("m_starter_shield", "led_strip_get_brightness",
                                (strip_index), device_index)
    if ret:
        return ret[1]
    else:
        return -1
Beispiel #27
0
def get_barcode_all_data(barcode_id, index=1):  #获取某个条形码的所有信息
    if (not isinstance(barcode_id, (int, float))) or (not isinstance(
            index, (int, float))) or (index <= 0):
        return 0
    barcode_id = num_range_scale(barcode_id, 0, 15)
    value = neurons_blocking_read("m_smart_camera", "get_barcode_all_data",
                                  (barcode_id), index)
    if value != None:
        value[1] = round(value[1] * FRAME_REVISE_COE_LINE_X)
        value[2] = round(value[2] * FRAME_REVISE_COE_LINE_Y)
        return value
    else:
        return 0
Beispiel #28
0
def multifunction_analog_read(port, device_index=1):
    if not isinstance(port, (int, float)):
        return -1
    if not isinstance(device_index, (int, float)):
        return -1
    if port not in [1, 2]:
        return -1
    ret = neurons_blocking_read("m_standard_shield",
                                "multifunction_analog_read", (port),
                                device_index)
    if ret:
        return ret[1]
    else:
        return -1
Beispiel #29
0
def __get_info(index=1):
    global __led_value

    if not isinstance(index, (int, float)):
        return
    value = neurons_blocking_read("m_rgb", "get_info", (), index)
    value = value if value != None else [0, 0, 0]

    if index > __RGB_NUM_MAX:
        return

    __led_value[int(index)] = value

    return value
Beispiel #30
0
def get_pixel(pos_x, pos_y, index=1):
    if not isinstance(index, (int, float)):
        return False

    if (not isinstance(pos_x,
                       (int, float))) or (not isinstance(pos_y, (int, float))):
        return False
    pos_x = int(pos_x)
    pos_y = int(pos_y)
    if pos_x < 0 or pos_x > 15 or pos_y < 0 or pos_y > 7:
        return False
    ret = neurons_blocking_read("m_led_panel", "get_pixel", (pos_x, pos_y),
                                index)
    return bool(ret[2])