|
| 1 | +/* Breaks for all kind of stuff ... |
| 2 | + */ |
| 3 | + |
| 4 | +/* To fix this in the "class-wrapping" method, remove `static` |
| 5 | + * and change objects declarations |
| 6 | + * from `Classname obj(args...)` |
| 7 | + * to `Classname obj = Classname{args..}` |
| 8 | + */ |
| 9 | + |
| 10 | +/************************************************************************************** |
| 11 | + * CONSTANTS |
| 12 | + **************************************************************************************/ |
| 13 | + |
| 14 | +static byte constexpr LSM6DSOX_ADDRESS = 0x6A; |
| 15 | +static byte constexpr LSM6DSOX_WHO_AM_I_REG = 0x0F; |
| 16 | + |
| 17 | +/************************************************************************************** |
| 18 | + * GLOBAL VARIABLES |
| 19 | + **************************************************************************************/ |
| 20 | + |
| 21 | +// BusDevice lsm6dsox(Wire, LSM6DSOX_ADDRESS); |
| 22 | +BusDevice lsm6dsox = BusDevice{Wire, LSM6DSOX_ADDRESS}; |
| 23 | + |
| 24 | +/************************************************************************************** |
| 25 | + * FUNCTIONS |
| 26 | + **************************************************************************************/ |
| 27 | + |
| 28 | +byte lsm6dsox_read_reg(byte reg_addr) |
| 29 | +{ |
| 30 | + byte read_buf = 0; |
| 31 | + lsm6dsox.wire().write_then_read(®_addr, 1, &read_buf, 1); |
| 32 | + return read_buf; |
| 33 | +} |
| 34 | + |
| 35 | +/************************************************************************************** |
| 36 | + * SETUP/LOOP |
| 37 | + **************************************************************************************/ |
| 38 | + |
| 39 | +void setup() |
| 40 | +{ |
| 41 | + Serial.begin(9600); |
| 42 | +} |
| 43 | + |
| 44 | +void loop() |
| 45 | +{ |
| 46 | + /* Sleep between 5 and 500 ms */ |
| 47 | + rtos::ThisThread::sleep_for(rtos::Kernel::Clock::duration_u32(random(5,500))); |
| 48 | + /* Try to read some data from the LSM6DSOX. */ |
| 49 | + byte const who_am_i = lsm6dsox_read_reg(LSM6DSOX_WHO_AM_I_REG); |
| 50 | + /* Print thread id and chip id value to serial. */ |
| 51 | + char msg[64] = {0}; |
| 52 | + snprintf(msg, sizeof(msg), "%s: LSM6DSOX[WHO_AM_I] = 0x%X", rtos::ThisThread::get_name(), who_am_i); |
| 53 | + Serial.println(msg); |
| 54 | +} |
0 commit comments