MCPcopy Create free account
hub / github.com/Santroller/Santroller / processData

Method processData

lib/accelerometer/accelerometerlib.cpp:39–346  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37 interface.dmaDeinit(LIS3DH_ADDRESS_2);
38}
39void Accelerometer::processData(uint8_t addr, bool running, bool timeout, bool abort_detected, bool stop_detected)
40{
41 // printf("processData %02x %d %d %d %d %d\r\n", addr, status, running, timeout, abort_detected, stop_detected);
42 // If we have started init, ignore i2c data from the other accelerometers
43 if (status != ACCEL_INIT && addr && addr != address)
44 {
45 return;
46 }
47 cancel_alarm(restart_alarm_id);
48 if (timeout || abort_detected)
49 {
50 if (status != ACCEL_INIT)
51 {
52 failCount++;
53 }
54 // during high load, there might be the occassional drop, so allow a few failures
55 if (failCount > 10 || status == ACCEL_INIT)
56 {
57 status = ACCEL_INIT;
58 type = AccelerometerType::None;
59 }
60 restart_alarm_id = add_alarm_in_ms(500, restart_handler, this, true);
61 return;
62 }
63 if (stop_detected)
64 {
65 seen_response_lis3dh_1 = addr == LIS3DH_ADDRESS;
66 seen_response_lis3dh_2 = addr == LIS3DH_ADDRESS_2;
67 seen_response_mpu6050 = addr == MPU6050_ADDRESS;
68 seen_response_adxl345 = addr == ADXL345_ADDRESS;
69 if (!abort_detected)
70 {
71 failCount = 0;
72 switch (status)
73 {
74 case MPU_6050_POLL:
75 case LIS_FAMILY_POLL:
76 accel[0] = bufferRx[1] << 8 | bufferRx[0];
77 accel[1] = bufferRx[3] << 8 | bufferRx[2];
78 accel[2] = bufferRx[5] << 8 | bufferRx[4];
79 if (HIDConfigDevice::tool_closed())
80 {
81 restart_alarm_id = add_alarm_in_us(500, restart_handler, this, true);
82 }
83 else
84 {
85 restart_alarm_id = add_alarm_in_us(5000, restart_handler, this, true);
86 }
87 break;
88 case ADXL_POLL:
89 // ADXL345 needs to be scaled
90 accel[0] = (bufferRx[1] << 8 | bufferRx[0]) * 64;
91 accel[1] = (bufferRx[3] << 8 | bufferRx[2]) * 64;
92 accel[2] = (bufferRx[5] << 8 | bufferRx[4]) * 64;
93 if (HIDConfigDevice::tool_closed())
94 {
95 restart_alarm_id = add_alarm_in_us(500, restart_handler, this, true);
96 }

Callers 1

restart_handlerFunction · 0.45

Calls 1

dmaWriteReadMethod · 0.80

Tested by

no test coverage detected