|
@@ -1,23 +1,20 @@
|
|
|
#include "interface/encoder_interface.h"
|
|
|
|
|
|
typedef void (* motion_function_t)(void);
|
|
|
+typedef void (* battery_function_t)(void);
|
|
|
|
|
|
typedef struct {
|
|
|
os_timer_t motion_timer;
|
|
|
uint32_t motion_timeout;
|
|
|
motion_function_t motion_cb;
|
|
|
- uint32_t vcell;
|
|
|
- uint32_t soc;
|
|
|
+ uint16_t vcell;
|
|
|
+ uint16_t soc;
|
|
|
os_timer_t battery_timer;
|
|
|
uint32_t battery_timeout;
|
|
|
+ battery_function_t battery_cb;
|
|
|
} Encoder_t;
|
|
|
|
|
|
-typedef struct {
|
|
|
- uint32_t vcell;
|
|
|
- uint32_t motion;
|
|
|
-} Encoder_Battery_t;
|
|
|
-
|
|
|
-static Encoder_t encoder;
|
|
|
+//static Encoder_t encoder;
|
|
|
|
|
|
void ICACHE_FLASH_ATTR Encoder_Shutdown(void)
|
|
|
{
|
|
@@ -37,43 +34,70 @@ void ICACHE_FLASH_ATTR Encoder_Restart(void)
|
|
|
system_restart();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/* Motion Functions */
|
|
|
|
|
|
-void ICACHE_FLASH_ATTR Encoder_MotionSetCallback(motion_function_t motion_cb)
|
|
|
-{
|
|
|
- encoder.motion_cb = motion_cb;
|
|
|
- os_timer_setfn(&encoder.motion_timer, (os_timer_func_t *)encoder.motion_cb, NULL);
|
|
|
-}
|
|
|
+// void ICACHE_FLASH_ATTR Encoder_MotionSetCallback(motion_function_t motion_cb)
|
|
|
+// {
|
|
|
+// encoder.motion_cb = motion_cb;
|
|
|
+// os_timer_setfn(&encoder.motion_timer, (os_timer_func_t *)encoder.motion_cb, NULL);
|
|
|
+// }
|
|
|
|
|
|
-void ICACHE_FLASH_ATTR Encoder_MotionStartTimer(uint32_t timeout)
|
|
|
-{
|
|
|
- encoder.motion_timeout = timeout;
|
|
|
- os_timer_arm(&encoder.motion_timer, encoder.motion_timeout, false);
|
|
|
-}
|
|
|
+// void ICACHE_FLASH_ATTR Encoder_MotionStartTimer(uint32_t timeout)
|
|
|
+// {
|
|
|
+// encoder.motion_timeout = timeout;
|
|
|
+// os_timer_arm(&encoder.motion_timer, encoder.motion_timeout, false);
|
|
|
+// }
|
|
|
|
|
|
-void ICACHE_FLASH_ATTR Encoder_MotionStopTimer()
|
|
|
-{
|
|
|
- os_timer_disarm(&encoder.motion_timer);
|
|
|
-}
|
|
|
+// void ICACHE_FLASH_ATTR Encoder_MotionStopTimer()
|
|
|
+// {
|
|
|
+// os_timer_disarm(&encoder.motion_timer);
|
|
|
+// }
|
|
|
|
|
|
/* Battery Monitor Functions */
|
|
|
|
|
|
+#define VOLTAGE_CUTOFF 2800 // v_cutoff = 3.5V / 1.25mV
|
|
|
+
|
|
|
// static void ICACHE_FLASH_ATTR encoder_battery_monitor_cb(void)
|
|
|
// {
|
|
|
-//
|
|
|
+// // measure battery voltage and store
|
|
|
+// //LSM6DS3_Enable_I2C_Bridge(true);
|
|
|
+
|
|
|
+// encoder.vcell = max17043_getVoltage();
|
|
|
+// encoder.soc = max17043_getSOC();
|
|
|
+
|
|
|
+// if (encoder.battery_cb != NULL)
|
|
|
+// encoder.battery_cb();
|
|
|
+
|
|
|
+// if (encoder.vcell < VOLTAGE_CUTOFF)
|
|
|
+// Encoder_Shutdown();
|
|
|
+// }
|
|
|
+
|
|
|
+// void ICACHE_FLASH_ATTR Encoder_SetBatteryFailureCallback(battery_function_t function)
|
|
|
+// {
|
|
|
+// encoder.battery_cb = function;
|
|
|
// }
|
|
|
-//
|
|
|
+
|
|
|
// void ICACHE_FLASH_ATTR Encoder_StartBatteryMonitor(uint32_t battery_monitor_rate)
|
|
|
// {
|
|
|
-//
|
|
|
+// encoder.battery_timeout = battery_monitor_rate;
|
|
|
+
|
|
|
+// os_timer_disarm(&encoder.battery_timer);
|
|
|
+// os_timer_setfn(&encoder.battery_timer, (os_timer_func_t *)encoder.battery_cb, NULL);
|
|
|
+// os_timer_arm(&encoder.battery_timer, encoder.battery_timeout, true);
|
|
|
// }
|
|
|
-//
|
|
|
+
|
|
|
// void ICACHE_FLASH_ATTR Encoder_StopBatteryMonitor(void)
|
|
|
// {
|
|
|
-//
|
|
|
+// os_timer_disarm(&encoder.battery_timer);
|
|
|
// }
|
|
|
-//
|
|
|
-// Encoder_Battery_t ICACHE_FLASH_ATTR Encoder_GetBatteryStatus(void)
|
|
|
+
|
|
|
+// uint16_t ICACHE_FLASH_ATTR Encoder_GetVoltage(void)
|
|
|
+// {
|
|
|
+// return encoder.vcell;
|
|
|
+// }
|
|
|
+
|
|
|
+// uint16_t ICACHE_FLASH_ATTR Encoder_GetSOC(void)
|
|
|
// {
|
|
|
-//
|
|
|
+// return encoder.soc;
|
|
|
// }
|