Procházet zdrojové kódy

put everything on timers

eLandon_Miix před 4 roky
rodič
revize
bbacad144d
5 změnil soubory, kde provedl 79 přidání a 51 odebrání
  1. 3 2
      include/oscmgr.h
  2. 3 0
      include/wifimgr.h
  3. 27 12
      src/main.cpp
  4. 3 2
      src/oscmgr.cpp
  5. 43 35
      src/wifimgr.cpp

+ 3 - 2
include/oscmgr.h

@@ -2,9 +2,8 @@
 #include "WiFi.h"
 // #include "AsyncUDP.h"
 #include <WiFiUdp.h>
-#include <ESPmDNS.h>
 #include <OSCMessage.h>
-
+#include <ESPmDNS.h>
 
 
 
@@ -13,6 +12,8 @@ void sendOSC_3f(const char * adress, float parameter, float parameter2, float pa
 
 extern bool calib_flag;
 
+
+
 void printTest(OSCMessage &msg) ;
 void OSCcb_calibGyro(OSCMessage &msg) ;
 void setup_OSC(IPAddress _UDP_Out_IP, int _UDP_Out_Port, int _UDP_In_Port);

+ 3 - 0
include/wifimgr.h

@@ -19,4 +19,7 @@ using WebServerClass = WebServer;
 extern AutoConnect portal;
 extern AutoConnectAux configAux;
 
+String saveAux_cb (AutoConnectAux& aux, PageArgument& arg);
+String loadAux_cb (AutoConnectAux& aux, PageArgument& arg);
+
 void setup_wifimgr();

+ 27 - 12
src/main.cpp

@@ -29,15 +29,21 @@ extern void lcd_wakeup();
 #include "oscmgr.h"
 #include "imu.h"
 
+
+int portal_rate = 40;
+long int portal_last_sent;
+
 ///////////////////////   SENSOR   ////////////////////////////////////
 
-int sensor_rate = 10;
-long int last_sent;
+int sensor_rate = 40;
+long int sensor_last_sent;
 
-///////////////////////      TFT   ////////////////////////////////////
+///////////////////////      LCD   ////////////////////////////////////
 
 long int idle ;
 long int idle_offset;
+int lcd_rate = 100;
+long int lcd_last_sent;
 
 void lcd_sleep(){
   M5.Lcd.sleep();
@@ -179,7 +185,9 @@ void setup() {
 
 void loop() {
 
-  idle = millis()-idle_offset;
+  unsigned long current_time = millis();
+
+  idle = current_time-idle_offset;
   if(idle>60000){
     lcd_sleep();
   }
@@ -215,13 +223,16 @@ void loop() {
       calibGyro();
     }
   handle_imu();
-
-  portal.handleClient();
+//send sensor data 
+  if(current_time-portal_last_sent>portal_rate){
+    portal_last_sent = current_time;
+    portal.handleClient();
+  }
   handle_OSC(); 
-  
+
   //send sensor data 
-  if(millis()-last_sent>sensor_rate){
-    last_sent = millis();
+  if(current_time-sensor_last_sent>sensor_rate){
+    sensor_last_sent = current_time;
     sendOSC_3f("/gyro", gyroX, gyroY, gyroZ);
     sendOSC_3f("/acc", accX, accY, accZ);
     sendOSC_3f("/ahrs", yaw_ahrs, pitch_ahrs, roll_ahrs);
@@ -229,9 +240,13 @@ void loop() {
     sendOSC_3f("/ahrs_smooth", yaw_smooth.get(), pitch_smooth.get(), roll_smooth.get());
   }
 
-
-  drawNetworkInfo(0, 65);
-  drawSensorInfo(0, 120);
+//update CD
+//send sensor data 
+  if(current_time-lcd_last_sent>lcd_rate){
+    lcd_last_sent = current_time;
+    drawNetworkInfo(0, 65);
+    drawSensorInfo(0, 120);
+  }
 
 
 }

+ 3 - 2
src/oscmgr.cpp

@@ -49,6 +49,7 @@ void OSCcb_calibGyro(OSCMessage &msg){
 }
 
 
+
 void setup_OSC( IPAddress _UDP_Out_IP, int _UDP_Out_Port, int _UDP_In_Port){
 
     UDP_Out_IP = _UDP_Out_IP;
@@ -67,10 +68,10 @@ void setup_OSC( IPAddress _UDP_Out_IP, int _UDP_Out_Port, int _UDP_In_Port){
 
     MDNS.addService("_osc", "_udp", _UDP_In_Port);
     MDNS.addServiceTxt("_osc", "_udp",  "board", "imu");
-  
+    UDP_OSC.stop();
     UDP_OSC.begin(_UDP_In_Port);
 
-     sendOSC("/connected", 'imu');
+    sendOSC("/connected", 'imu');
 }
 
 void handle_OSC() {

+ 43 - 35
src/wifimgr.cpp

@@ -27,13 +27,7 @@ static const char PAGE_CONFIG[] PROGMEM = R"(
       "value": "<hr style=\"height:1px;border-width:0;color:gray;background-color:#52a6ed\">",
       "posterior": "par"
     },
-    {
-      "name": "HOSTNAME",
-      "type": "ACInput",
-      "label": "Hostname",
-      "placeholder": "This area accepts hostname patterns",
-      "pattern": "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$"
-    },
+    
     {
       "name": "OSC_SECTION_TEXT",
       "type": "ACText",
@@ -63,6 +57,14 @@ static const char PAGE_CONFIG[] PROGMEM = R"(
       "pattern": "\\d*"
     },
     {
+      "name": "HOSTNAME",
+      "type": "ACInput",
+      "label": "Hostname",
+      "apply": "text",
+      "placeholder": "This area accepts hostname patterns",
+      "pattern": "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\\-]*[A-Za-z0-9])$"
+    },
+    {
       "name": "hr2",
       "type": "ACElement",
       "value": "<hr style=\"height:1px;border-width:0;color:gray;background-color:#52a6ed\">",
@@ -121,31 +123,7 @@ AutoConnectConfig config;
 AutoConnectAux  configAux;
 AutoConnectAux  saveAux;
 
-
-/////////////////////////       SETUP       //////////////////////////////////
-
-
-void setup_wifimgr(void) {
-    // Responder of root page handled directly from WebServer class.
-  server.on("/", []() {
-    String content = "<head> <meta http-equiv=\"refresh\" content=\"0; URL=/config\" /></head>";
-    content += AUTOCONNECT_LINK(COG_24);
-    server.send(200, "text/html", content);
-  });
-
-  server.on("/reset", []() {
-    String content = "<head> <meta http-equiv=\"refresh\" content=\"15; URL=/config\" /></head>";
-    content += "waiting 15s for sensor to reboot";
-    server.send(200, "text/html", content);
-    delay(100);
-    ESP.restart();
-  });
-
-  // Load a custom web page described in JSON as PAGE_ELEMENT and
-  // register a handler. This handler will be invoked from
-  // AutoConnectSubmit named the Load defined on the same page.
-  configAux.load(FPSTR(PAGE_CONFIG));
-  configAux.on([] (AutoConnectAux& aux, PageArgument& arg) {
+String loadAux_cb (AutoConnectAux& aux, PageArgument& arg) {
     if (portal.where() == "/config") {
       // Use the AutoConnect::where function to identify the referer.
       // Since this handler only supports AutoConnectSubmit called the
@@ -160,10 +138,10 @@ void setup_wifimgr(void) {
       FlashFS.end();
     }
     return String();
-  });
+  }
 
-  saveAux.load(FPSTR(PAGE_SAVE));
-  saveAux.on([] (AutoConnectAux& aux, PageArgument& arg) {
+
+String saveAux_cb (AutoConnectAux& aux, PageArgument& arg) {
     // You can validate input values ​​before saving with
     // AutoConnectInput::isValid function.
     // Verification is using performed regular expression set in the
@@ -195,8 +173,37 @@ void setup_wifimgr(void) {
     }
     FlashFS.end();
     return String();
+  }
+
+
+/////////////////////////       SETUP       //////////////////////////////////
+
+
+void setup_wifimgr(void) {
+    // Responder of root page handled directly from WebServer class.
+  server.on("/", []() {
+    String content = "<head> <meta http-equiv=\"refresh\" content=\"0; URL=/config\" /></head>";
+    content += AUTOCONNECT_LINK(COG_24);
+    server.send(200, "text/html", content);
   });
 
+  server.on("/reset", []() {
+    String content = "<head> <meta http-equiv=\"refresh\" content=\"15; URL=/config\" /></head>";
+    content += "waiting 15s for sensor to reboot";
+    server.send(200, "text/html", content);
+    delay(100);
+    ESP.restart();
+  });
+
+  // Load a custom web page described in JSON as PAGE_ELEMENT and
+  // register a handler. This handler will be invoked from
+  // AutoConnectSubmit named the Load defined on the same page.
+  configAux.load(FPSTR(PAGE_CONFIG));
+  configAux.on(loadAux_cb);
+
+  saveAux.load(FPSTR(PAGE_SAVE));
+  saveAux.on(saveAux_cb);
+
   //Read config file to start with good config values
   FlashFS.begin();
   File param = FlashFS.open(CONFIG_FILE, "r");
@@ -214,4 +221,5 @@ void setup_wifimgr(void) {
   config.hostName = hostname;
   portal.config(config);
   portal.begin();
+  
 }