1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #include "Roll.h"
- #include "Sail.h"
- #include "Accelerometer.h"
- #include "stdlib.h"
-
- ADC_TypeDef * ROLL_ADC = ADC2;
- const int ROLL_X_CHANNEL = 11;
- const int ROLL_Y_CHANNEL = 10;
- GPIO_TypeDef * ROLL_GPIO = GPIOC;
- const int ROLL_X_PIN = LL_GPIO_PIN_0;
- const int ROLL_Y_PIN = LL_GPIO_PIN_1;
-
- const int TRIGGER_ANGLE = 40;
-
- int Roll_isEmergencyState = 0;
-
- void Roll_conf(void)
- {
- Accelerometer_conf(ROLL_ADC, ROLL_GPIO, ROLL_X_PIN, ROLL_Y_PIN);
- }
-
- void Roll_start(void)
- {
- Accelerometer_start(ROLL_ADC);
- }
-
- int Roll_getEmergencyState(void)
- {
- return Roll_isEmergencyState;
- }
-
- int current = 0;
- int angle= 0;
-
- void Roll_background(void)
- {
- // const int xAngle = Accelerometer_getAngle(ROLL_ADC, ROLL_X_CHANNEL);
- const int yAngle = Accelerometer_getAngle(ROLL_ADC, ROLL_Y_CHANNEL);
- angle = yAngle;
-
- const int currentState = Roll_isEmergencyState ? abs(yAngle) >= 10 : abs(yAngle) >= 40;
- current = currentState;
- if (Roll_isEmergencyState != currentState) {
- Sail_setEmergency(currentState);
- Roll_isEmergencyState = currentState;
- }
- }
|