encoder_interface.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "interface/encoder_interface.h"
  2. typedef void (* motion_function_t)(void);
  3. typedef struct {
  4. os_timer_t motion_timer;
  5. uint32_t motion_timeout;
  6. motion_function_t motion_cb;
  7. uint32_t vcell;
  8. uint32_t soc;
  9. os_timer_t battery_timer;
  10. uint32_t battery_timeout;
  11. } Encoder_t;
  12. typedef struct {
  13. uint32_t vcell;
  14. uint32_t motion;
  15. } Encoder_Battery_t;
  16. static Encoder_t encoder;
  17. void ICACHE_FLASH_ATTR Encoder_Shutdown(void)
  18. {
  19. Light_Shutdown();
  20. IO_Shutdown();
  21. system_deep_sleep(0);
  22. }
  23. void ICACHE_FLASH_ATTR Encoder_Factory_Reset(void)
  24. {
  25. system_restore();
  26. }
  27. void ICACHE_FLASH_ATTR Encoder_Restart(void)
  28. {
  29. Light_Restart();
  30. system_restart();
  31. }
  32. /* Motion Functions */
  33. void ICACHE_FLASH_ATTR Encoder_MotionSetCallback(motion_function_t motion_cb)
  34. {
  35. encoder.motion_cb = motion_cb;
  36. os_timer_setfn(&encoder.motion_timer, (os_timer_func_t *)encoder.motion_cb, NULL);
  37. }
  38. void ICACHE_FLASH_ATTR Encoder_MotionStartTimer(uint32_t timeout)
  39. {
  40. encoder.motion_timeout = timeout;
  41. os_timer_arm(&encoder.motion_timer, encoder.motion_timeout, false);
  42. }
  43. void ICACHE_FLASH_ATTR Encoder_MotionStopTimer()
  44. {
  45. os_timer_disarm(&encoder.motion_timer);
  46. }
  47. /* Battery Monitor Functions */
  48. // static void ICACHE_FLASH_ATTR encoder_battery_monitor_cb(void)
  49. // {
  50. //
  51. // }
  52. //
  53. // void ICACHE_FLASH_ATTR Encoder_StartBatteryMonitor(uint32_t battery_monitor_rate)
  54. // {
  55. //
  56. // }
  57. //
  58. // void ICACHE_FLASH_ATTR Encoder_StopBatteryMonitor(void)
  59. // {
  60. //
  61. // }
  62. //
  63. // Encoder_Battery_t ICACHE_FLASH_ATTR Encoder_GetBatteryStatus(void)
  64. // {
  65. //
  66. // }