io_utils.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "at32f403a_407.h"
  2. #include "io_utils.h"
  3. #include "FreeRTOS.h"
  4. #include "task.h"
  5. #include "settings_api.h"
  6. #include "mux.h"
  7. #include "analog_output.h"
  8. #include <stdio.h>
  9. bool save_mode = false;
  10. static uint16_t counter = 0;
  11. //
  12. void save_mode_init(void)
  13. {
  14. save_mode = settings.save_mode;
  15. save_mode ? mux_led_status(false) : mux_led_status(true);
  16. }
  17. //
  18. void save_mode_set(bool state)
  19. {
  20. save_mode = state;
  21. save_mode ? mux_led_status(false) : mux_led_status(true);
  22. }
  23. //
  24. bool save_mode_get(void)
  25. {
  26. return save_mode;
  27. }
  28. // Должна вызываться раз в секунду
  29. void save_mode_inc_cnt(void)
  30. {
  31. if (settings.save_mode)
  32. return;
  33. bool foo = counter++ > settings.save_delay ? true : false;
  34. save_mode_set(foo);
  35. }
  36. // Должна вызываться раз в секунду
  37. void save_mode_set_with_counter(void)
  38. {
  39. if (!settings.save_mode)
  40. return;
  41. if (counter++ > settings.save_delay) {
  42. if (!save_mode_get()) {
  43. save_mode_set(true);
  44. #if (MAO_4)
  45. ao_save_update(true);
  46. #endif
  47. }
  48. }
  49. }
  50. //
  51. void save_mode_reset_cnt(void)
  52. {
  53. counter = 0;
  54. save_mode_set(false);
  55. #if (MAO_4)
  56. ao_save_update(false);
  57. #endif
  58. }