Exemplo n.º 1
0
    def __get_spi_bus_from_ptdm(self):
        message = Message.from_parts(Message.REQ_GET_OLED_SPI_BUS)

        with PTDMRequestClient() as request_client:
            response = request_client.send_message(message)

        return int(response.parameters[0])
Exemplo n.º 2
0
def ping():
    message = Message.from_parts(Message.REQ_PING, [])

    with PTDMRequestClient() as request_client:
        response = request_client.send_message(message)

    return int(response.parameters[0]) == 1
Exemplo n.º 3
0
    def __set_controls(self, controlled_by_pi):
        message = Message.from_parts(
            Message.REQ_SET_OLED_CONTROL, [str(int(controlled_by_pi))]
        )

        with PTDMRequestClient() as request_client:
            request_client.send_message(message)
Exemplo n.º 4
0
def legacy_pitop_peripherals():
    """Returns a list with the status of legacy peripheral devices.

    Returns:
        list: list of dictionaries with the status of legacy peripherals
    """
    peripherals = []

    for peripheral_enum in PeripheralID:
        if peripheral_enum == PeripheralID.unknown:
            continue

        peripheral_id = peripheral_enum.value
        human_readable_name = PeripheralName[peripheral_enum.name].value

        message = Message.from_parts(
            Message.REQ_GET_PERIPHERAL_ENABLED, [peripheral_id]
        )

        with PTDMRequestClient() as request_client:
            response = request_client.send_message(message)

        p_enabled = int(response.parameters[0]) == 1
        peripherals.append({"name": human_readable_name, "connected": p_enabled})

    return peripherals
Exemplo n.º 5
0
    def get_full_state(cls):
        message = Message.from_parts(Message.REQ_GET_BATTERY_STATE, [])

        with PTDMRequestClient() as request_client:
            response = request_client.send_message(message)

        return response.parameters
Exemplo n.º 6
0
def __device_id():
    message = Message.from_parts(Message.REQ_GET_DEVICE_ID, [])

    with PTDMRequestClient() as request_client:
        response = request_client.send_message(message)

    parameters = response.parameters
    device_id = int(parameters[0])
    return device_id
Exemplo n.º 7
0
    def spi_bus(self, bus):
        """Request SPI bus change from pi-top device manager."""
        assert bus in range(0, 2)

        if self.__spi_bus == bus:
            return

        message = Message.from_parts(Message.REQ_SET_OLED_SPI_BUS, [str(bus)])

        with PTDMRequestClient() as request_client:
            request_client.send_message(message)
Exemplo n.º 8
0
    def __do_transaction(self, message, state_str):
        with PTDMRequestClient() as request_client:
            response = request_client.send_message(message)

        return response