Skip to content

[cpp][py] Expose sensor.bin_data attrbute#84

Merged
WasabiFan merged 1 commit intoev3dev:developfrom
ddemidov:bin_data
May 14, 2015
Merged

[cpp][py] Expose sensor.bin_data attrbute#84
WasabiFan merged 1 commit intoev3dev:developfrom
ddemidov:bin_data

Conversation

@ddemidov
Copy link
Copy Markdown
Member

This provides user access to bin_data_format/bin_data attributes of sensor class in C++ and python. See ddemidov/ev3dev-lang-python#4.

In C++ its possible to ask the sensor to read raw data into a user-supplied buffer/struct:

struct  __attribute__((__packed__)) abs_imu_data {
  char tilt[3];
  short accel[3];
  short compass;
  short mag[3];
  short gyro[3];
} val;

// The get_bin_data is implemented as template:
gyro.get_bin_data(&val);

In python, sensor.bin_data() function either returns a byte buffer, or unpacked tuple:

>>> from ev3dev import *
>>> ir = infrared_sensor()
>>> ir.value()
28
>>> ir.bin_data()
<read-only buffer ptr 0x3f6a58, size 1 at 0xb6a12b00>
>>> ir.bin_data('<b')
(28,)

WasabiFan added a commit that referenced this pull request May 14, 2015
[cpp][py] Expose sensor.bin_data attrbute
@WasabiFan WasabiFan merged commit da84989 into ev3dev:develop May 14, 2015
@ddemidov ddemidov deleted the bin_data branch May 14, 2015 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants