-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tilt.cpp
91 lines (77 loc) · 2.42 KB
/
Tilt.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <Tilt.h>
void Tilt::init() {
_gyro.writeRegister(LSM6DS3_ACC_GYRO_CTRL3_C, LSM6DS3_ACC_GYRO_SW_RESET_RESET_DEVICE);
//Over-ride default settings if desired
_gyro.settings.gyroEnabled = 1; //Can be 0 or 1
_gyro.settings.gyroRange = 2000; //Max deg/s. Can be: 125, 245, 500, 1000, 2000
_gyro.settings.gyroSampleRate = 104; //Hz. Can be: 13, 26, 52, 104, 208, 416, 833, 1666
_gyro.settings.gyroBandWidth = 200; //Hz. Can be: 50, 100, 200, 400;
_gyro.settings.accelEnabled = 1;
_gyro.settings.accelRange = 16; //Max G force readable. Can be: 2, 4, 8, 16
_gyro.settings.accelSampleRate = 833; //Hz. Can be: 13, 26, 52, 104, 208, 416, 833, 1666, 3332, 6664, 13330
_gyro.settings.accelBandWidth = 200; //Hz. Can be: 50, 100, 200, 400;
_gyro.begin();
// Set orientation threshold
_gyro.writeRegister(LSM6DS3_ACC_GYRO_TAP_THS_6D, LSM6DS3_ACC_GYRO_SIXD_THS_60_degree);
// Enable low pass filter 2
_gyro.writeRegister(LSM6DS3_ACC_GYRO_TAP_CFG1, 0x10);
_gyro.writeRegister(LSM6DS3_ACC_GYRO_CTRL8_XL, 0x01);
// Enable interrupt
_gyro.writeRegister(LSM6DS3_ACC_GYRO_MD1_CFG, LSM6DS3_ACC_GYRO_INT1_6D_ENABLED);
};
void Tilt::handle() {
uint8_t orientation;
_gyro.readRegister(&orientation, LSM6DS3_ACC_GYRO_D6D_SRC);
if(_currentOrientation == orientation) {
return;
}
_currentOrientation = orientation;
if(orientation == _tiltSequence[_tiltPointer++]) {
if(_tiltSequence.size() == _tiltPointer) {
for(uint8_t i = 0; i < 10; i++) {
_ring.ClearTo(white);
_ring.Show();
sleep(200);
_ring.ClearTo(green);
_ring.Show();
sleep(200);
}
return;
}
_ring.ClearTo(black);
_ring.Show();
sleep(500);
_ring.ClearTo(green);
_ring.Show();
return;
}
_tiltPointer = 0;
_ring.ClearTo(red);
_ring.Show();
/*switch(orientation){
case O_X_DOWN:
Serial.println("X down");
break;
case O_X_UP:
Serial.println("X up");
break;
case O_Y_DOWN:
Serial.println("Y down");
break;
case O_Y_UP:
Serial.println("Y up");
break;
case O_Z_DOWN:
Serial.println("Z down");
break;
case O_Z_UP:
Serial.println("Z up");
break;
default:
Serial.println("Unknown orientation");
}
char orientationString[9];
itoa(orientation, orientationString, 2);
Serial.print("\nOrientation:\n");
Serial.printf("%s", orientationString);*/
};