toio.cube.api.sensor module

class toio.cube.api.sensor.RequestMotionDetection[source]

Bases: CubeCommand

Motion information request command

References

https://toio.github.io/toio-spec/en/docs/ble_sensor#requesting-motion-detection-information

__init__()[source]
__bytes__() bytes[source]

Returns the byte representation of this class to be sent to cube.

Returns:

byte representation of this class to be sent to cube.

Return type:

bytes

class toio.cube.api.sensor.PostureDataType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Euler = 1
Quaternions = 2
HighPrecisionEuler = 3
class toio.cube.api.sensor.RequestPostureAngleDetection(data_type: PostureDataType)[source]

Bases: CubeCommand

Posture angle information request command

References

https://toio.github.io/toio-spec/en/docs/ble_high_precision_tilt_sensor#requesting-posture-angle-detection

__init__(data_type: PostureDataType)[source]
__bytes__() bytes[source]

Returns the byte representation of this class to be sent to cube.

Returns:

byte representation of this class to be sent to cube.

Return type:

bytes

class toio.cube.api.sensor.RequestMagneticSensor[source]

Bases: CubeCommand

Magnetic sensor information request command

References

https://toio.github.io/toio-spec/en/docs/ble_magnetic_sensor#requests-for-magnetic-sensor-information

__init__()[source]
__bytes__() bytes[source]

Returns the byte representation of this class to be sent to cube.

Returns:

byte representation of this class to be sent to cube.

Return type:

bytes

class toio.cube.api.sensor.Posture(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

Orientation of the cube.

Reference:

https://toio.github.io/toio-spec/en/docs/ble_sensor/#posture-detection

Unknown = 0
Top = 1
Bottom = 2
Rear = 3
Front = 4
Right = 5
Left = 6
class toio.cube.api.sensor.MotionDetectionData(payload: bytearray)[source]

Bases: CubeResponse

Information on the cube’s motion detection.

horizontal

Horizontal detection

Type:

bool

collision

Collision detection

Type:

bool

double_tap

Double-tap detection

Type:

bool

posture

Posture detection

Type:

Posture

shake

Shake detection (0:no shake, 1:Level1 - 10:Level10)

Type:

int

Reference:

https://toio.github.io/toio-spec/en/docs/ble_sensor/#obtaining-motion-detection-information

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.api.sensor.PostureAngleEulerData(payload: bytearray)[source]

Bases: CubeResponse

Information of posture angle (Euler angle)

roll

Roll (X axis)

Type:

int

pitch

Pitch (Y axis)

Type:

int

yaw

Yaw (Z axis)

Type:

int

References

https://toio.github.io/toio-spec/en/docs/ble_high_precision_tilt_sensor#obtaining-posture-angle-information-notifications-in-euler-angles

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.api.sensor.PostureAngleQuaternionsData(payload: bytearray)[source]

Bases: CubeResponse

PostureAngleQuaternionData

Information of posture angle (Quaternion)

w
Type:

float

x
Type:

float

y
Type:

float

z
Type:

float

References

https://toio.github.io/toio-spec/en/docs/ble_high_precision_tilt_sensor#obtaining-posture-angle-information-notifications-in-quaternions

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.api.sensor.PostureAngleHighPrecisionEulerData(payload: bytearray)[source]

Bases: CubeResponse

Information of high precision posture angle (Euler angle)

roll

Roll (X axis)

Type:

float

pitch

Pitch (Y axis)

Type:

float

yaw

Yaw (Z axis)

Type:

float

References

https://toio.github.io/toio-spec/en/docs/ble_high_precision_tilt_sensor#obtaining-posture-angle-information-notifications-in-euler-angles

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
__str__() str[source]

Return str(self).

class toio.cube.api.sensor.MagneticSensorData(payload: bytearray)[source]

Bases: CubeResponse

Information of magnetic sensor

state

Magnet state

Type:

int

strength

Magnetic force strength

Type:

int

x

Magnetic force direction (X axis)

Type:

int

y

Magnetic force direction (Y axis)

Type:

int

z

Magnetic force direction (Z axis)

Type:

int

References

https://toio.github.io/toio-spec/en/docs/ble_magnetic_sensor/#obtaining-magnetic-sensor-information-

static is_myself(payload: bytearray) bool[source]

If argument data is a byte representation of this class, this function converts the byte representation to an object and returns it.

Parameters:

data (GattReadData) – received data from the cube.

__init__(payload: bytearray)[source]
toio.cube.api.sensor.SensorResponseType

Response types of Sensor characteristic

alias of Union[MotionDetectionData, PostureAngleEulerData, PostureAngleQuaternionsData, PostureAngleHighPrecisionEulerData, MagneticSensorData]

class toio.cube.api.sensor.Sensor(interface: CubeInterface, device: Any)[source]

Bases: CubeCharacteristic

Sensor information characteristic

References

Motion detection

Posture angle detection

Magnetic sensor

static is_my_data(payload: bytearray) MotionDetectionData | PostureAngleEulerData | PostureAngleQuaternionsData | PostureAngleHighPrecisionEulerData | MagneticSensorData | None[source]

If payload is my characteristic response, this function returns CubeResponse object. Otherwise, it returns None.

Parameters:

payload (GattReadData) – received data from the cube.

__init__(interface: CubeInterface, device: Any)[source]
async read() MotionDetectionData | PostureAngleEulerData | PostureAngleQuaternionsData | PostureAngleHighPrecisionEulerData | MagneticSensorData | None[source]

Read sensor information response

Returns:

One of SensorInformationData or None (None returns when read fails)

async request_motion_information() None[source]

Send motion information request command

async request_posture_angle_information(data_type: PostureDataType) None[source]

Send posture angle information request command

async request_magnetic_sensor_information() None[source]

Send magnetic sensor information request