app_api.c 614 B

123456789101112131415161718192021222324252627282930
  1. #include "app_api.h"
  2. foc_fault_t api_set_ready(bool ready) {
  3. if (ready == foc_is_ready()) {
  4. return foc_success;
  5. }
  6. normal_task_enable(false);
  7. if (foc_stm_nextstate(ready?START:ANY_STOP) == NoError) {
  8. foc_set_ready(ready);
  9. normal_task_enable(true);
  10. return foc_success;
  11. }
  12. normal_task_enable(true);
  13. return foc_not_allowed;
  14. }
  15. foc_fault_t api_set_speed(u16 rpm) {
  16. normal_task_enable(false);
  17. FOCState focs = foc_stm_state();
  18. if (focs == IDLE || focs == ANY_STOP) {
  19. normal_task_enable(true);
  20. return foc_not_allowed;
  21. }
  22. foc_set_ref_speed(rpm);
  23. normal_task_enable(true);
  24. return foc_success;
  25. }