Projet voilier 4IRA1 Arnaud Vergnet Marino Benassai Bastien Picco Yohan Simard
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Roll.c 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "Roll.h"
  2. #include "Sail.h"
  3. #include "Accelerometer.h"
  4. #include "stdlib.h"
  5. ADC_TypeDef * ROLL_ADC = ADC2;
  6. const int ROLL_X_CHANNEL = 11;
  7. const int ROLL_Y_CHANNEL = 10;
  8. GPIO_TypeDef * ROLL_GPIO = GPIOC;
  9. const int ROLL_X_PIN = LL_GPIO_PIN_0;
  10. const int ROLL_Y_PIN = LL_GPIO_PIN_1;
  11. const int TRIGGER_ANGLE = 40;
  12. int Roll_isEmergencyState = 0;
  13. void Roll_conf(void)
  14. {
  15. Accelerometer_conf(ROLL_ADC, ROLL_GPIO, ROLL_X_PIN, ROLL_Y_PIN);
  16. }
  17. void Roll_start(void)
  18. {
  19. Accelerometer_start(ROLL_ADC);
  20. }
  21. int Roll_getEmergencyState(void)
  22. {
  23. return Roll_isEmergencyState;
  24. }
  25. int current = 0;
  26. int angle= 0;
  27. void Roll_background(void)
  28. {
  29. // const int xAngle = Accelerometer_getAngle(ROLL_ADC, ROLL_X_CHANNEL);
  30. const int yAngle = Accelerometer_getAngle(ROLL_ADC, ROLL_Y_CHANNEL);
  31. angle = yAngle;
  32. const int currentState = Roll_isEmergencyState ? abs(yAngle) >= 10 : abs(yAngle) >= 40;
  33. current = currentState;
  34. if (Roll_isEmergencyState != currentState) {
  35. Sail_setEmergency(currentState);
  36. Roll_isEmergencyState = currentState;
  37. }
  38. }