Browse Source

make changes, but something is horribly broken and I'm a little scared

curiousmuch 4 years ago
parent
commit
3d6f5f0459

+ 0 - 1
hal/lsm6ds3.c

@@ -156,7 +156,6 @@ void ICACHE_FLASH_ATTR LSM6DS3_EnableMotion(void)
 	Sensor_IO_Set_Register(LSM6DS3_WAKE_UP_THS, 0x01); 									         // set thres 32/64*2G = 1G
 	Sensor_IO_Set_Register(LSM6DS3_WAKE_UP_DUR, 0x02); 									         // zero duration
 	Sensor_IO_Set_Register(LSM6DS3_MD1_CFG, LSM6DS3_INT1_WU);								     // set interrupt for INTX (1 is connected to PBA)
-
 }
 
 void ICACHE_FLASH_ATTR LSM6DS3_DisableMotion(void)

+ 5 - 0
include/interface/encoder_interface.h

@@ -30,5 +30,10 @@
 
 void ICACHE_FLASH_ATTR Encoder_Shutdown(void);
 void ICACHE_FLASH_ATTR Encoder_Restart(void);
+//uint16_t ICACHE_FLASH_ATTR Encoder_GetVoltage(void);
+//uint16_t ICACHE_FLASH_ATTR Encoder_GetSOC(void);
+// void ICACHE_FLASH_ATTR Encoder_StartBatteryMonitor(uint32_t);
+// void ICACHE_FLASH_ATTR Encoder_StopBatteryMonitor(void);
+// void ICACHE_FLASH_ATTR Encoder_SetBatteryFailureCallback(battery_function_t);
 
 #endif

+ 3 - 0
include/user_config.h

@@ -42,6 +42,9 @@ User-Agent: rBoot-Sample/1.0\r\n\
 Accept: */*\r\n\r\n"
 #define OTA_NETWORK_TIMEOUT  10000 // ms
 
+
+#define BATTERY_CHECK_INTERVAL 600000
+
 // This needs to be changed to support a logging library
 #if defined(DEBUG_ON)
 #define INFO( format, ... ) os_printf( format, ## __VA_ARGS__ )

+ 54 - 30
interface/encoder_interface.c

@@ -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; 
 // }

+ 3 - 1
interface/ideasx_interface.c

@@ -126,9 +126,11 @@ void ICACHE_FLASH_ATTR IdeasX_Connect(void)
 
 void ICACHE_FLASH_ATTR IdeasX_Disconnect(void)
 {
+    MQTT_Disconnect(&mqttClient);                     // stop MQTT process 
+                                                      // clear queue [needs to be done]
+    //os_timer_disarm(&ideasX_health.health_timer);     // disable Health timer
     if (ideasX_config.fail_cb != NULL)
         ideasX_config.fail_cb();
-    MQTT_Disconnect(&mqttClient);
 }
 
 void ICACHE_FLASH_ATTR ideasX_system_config_init(void)

+ 9 - 1
user/user_main.c

@@ -217,14 +217,21 @@ void user_init(void)
     os_printf("\tIdeasX Encoder - (curiousmuch.org)\n");
     os_printf("----------------------------------------------------------\n\n");
 
+
+
+
     // Intialize UART and Wi-Fi
     WiFi_Initialize();
     IdeasX_Init();
+ while(1)
+        system_soft_wdt_feed();
     Encoder_InitIO();
     Encoder_InitIMU(); 
     Encoder_DisableIOInterrupts();
     Encoder_EnableIMUI2CInterface(true);
-   // IO_Shutdown();                       // set the shutdown pin for testing purporses
+   // IO_Shutdown();                       // set the shutdown pin for testing 
+
+   
 
     WiFi_SetCallbacks(wifi_success_cb, wifi_fail_cb);
     IdeasX_SetStatusCallbacks(ideasX_success_cb, ideasX_fail_cb);
@@ -232,5 +239,6 @@ void user_init(void)
     Encoder_DisableDebounceTimer();
     Encoder_SetIMUCallback(imu_cb);
 
+  
     system_init_done_cb(app_init);
 }