app.c 704 B

1234567891011121314151617181920212223242526272829303132
  1. #include "app/app.h"
  2. #include "foc/foc_stm.h"
  3. #include "foc/gas_sensor.h"
  4. #include "foc/foc_api.h"
  5. #include "libs/task.h"
  6. static u32 app_task(void);
  7. static void gas_sample_handler(timer_t *t);
  8. static timer_t _gas_sample_timer = {.handler = gas_sample_handler};
  9. void app_init(void){
  10. task_start(app_task, 5);
  11. timer_post(&_gas_sample_timer, 50);
  12. }
  13. void start_stop_handler(void) {
  14. if (!foc_is_ready()) {
  15. foc_set_ready(true);
  16. }else {
  17. foc_set_ready(false);
  18. }
  19. }
  20. static u32 app_task(void) {
  21. gas_sample_voltage();
  22. return 1;//隔5ms执行一次
  23. }
  24. static void gas_sample_handler(timer_t *t) {
  25. float v = gas_get_value();
  26. foc_set_ref_speed(v * MAX_SPEED_RPM);
  27. timer_post(&_gas_sample_timer, 200);
  28. }