Просмотр исходного кода

Esp32s3 test (#3836)

* Added ethernet functionality

* change smart leds to GPIO47 for now

* Make etherenet code specific for the esp32-s3 board

* Add 'sleep if idle' option for sleeping between rounds and change IO47 to IO12 for LED

* minor fix, remove space

* minor fix, add space

* remove space
allexoK 5 месяцев назад
Родитель
Сommit
247f7ee8e2

+ 8 - 0
code/components/jomjol_flowcontroll/ClassFlowControll.cpp

@@ -230,6 +230,10 @@ void ClassFlowControll::setAutoStartInterval(long &_interval)
     _interval = AutoInterval * 60 * 1000; // AutoInterval: minutes -> ms
 }
 
+void ClassFlowControll::setSleepWhileIdle(bool& _sleepwhileidle){
+    _sleepwhileidle = SleepWhileIdle;
+}
+
 ClassFlow* ClassFlowControll::CreateClassFlow(std::string _type)
 {
     ClassFlow* cfc = NULL;
@@ -575,6 +579,10 @@ bool ClassFlowControll::ReadParameter(FILE* pfile, string& aktparamgraph)
             }
         }
 
+        if ((toUpper(splitted[0]) == "SLEEPWHILEIDLE") && (splitted.size() > 1)) {
+            SleepWhileIdle = alphanumericToBoolean(splitted[1]);
+        }
+
         if ((toUpper(splitted[0]) == "DATALOGACTIVE") && (splitted.size() > 1)) {
             LogFile.SetDataLogToSD(alphanumericToBoolean(splitted[1]));
         }

+ 2 - 0
code/components/jomjol_flowcontroll/ClassFlowControll.h

@@ -37,6 +37,7 @@ protected:
 
 	bool AutoStart;
 	float AutoInterval;
+	bool SleepWhileIdle;
 	void SetInitialParameter(void);	
 	std::string aktstatusWithTime;
 	std::string aktstatus;
@@ -72,6 +73,7 @@ public:
 
 	bool getIsAutoStart();
 	void setAutoStartInterval(long &_interval);
+	void setSleepWhileIdle(bool& _sleepwhileidle);
 
 	std::string* getActStatusWithTime();
 	std::string* getActStatus();

+ 16 - 3
code/components/jomjol_flowcontroll/MainFlowControl.cpp

@@ -43,6 +43,7 @@ bool bTaskAutoFlowCreated = false;
 bool flowisrunning = false;
 
 long auto_interval = 0;
+bool sleep_while_idle = false;
 bool autostartIsEnabled = false;
 
 int countRounds = 0;
@@ -1659,6 +1660,7 @@ void task_autodoFlow(void *pvParameter)
     doInit();
 
     flowctrl.setAutoStartInterval(auto_interval);
+    flowctrl.setSleepWhileIdle(sleep_while_idle);
     autostartIsEnabled = flowctrl.getIsAutoStart();
 
     if (isSetupModusActive())
@@ -1739,9 +1741,20 @@ void task_autodoFlow(void *pvParameter)
 
         if (auto_interval > fr_delta_ms)
         {
-            const TickType_t xDelay = (auto_interval - fr_delta_ms) / portTICK_PERIOD_MS;
-            ESP_LOGD(TAG, "Autoflow: sleep for: %ldms", (long)xDelay);
-            vTaskDelay(xDelay);
+            if(sleep_while_idle){
+                vTaskDelay(10000 / portTICK_PERIOD_MS);//A little more time so the user can finish config
+                fr_delta_ms = (esp_timer_get_time() - fr_start) / 1000;
+                if (auto_interval > fr_delta_ms){
+                    LogFile.WriteToFile(ESP_LOG_INFO, TAG, "Deep sleep for " + std::to_string(auto_interval - fr_delta_ms));
+
+                    esp_sleep_enable_timer_wakeup((auto_interval - fr_delta_ms) * 1000); // Time in microseconds
+                    esp_deep_sleep_start();
+                }
+            }else{
+                const TickType_t xDelay = (auto_interval - fr_delta_ms) / portTICK_PERIOD_MS;
+                ESP_LOGD(TAG, "Autoflow: sleep for: %ldms", (long)xDelay);
+                vTaskDelay(xDelay);
+            }
         }
     }
 

+ 1 - 1
code/include/defines.h

@@ -349,7 +349,7 @@
     #define CAM_PIN_D7       GPIO_NUM_16
     #define CAM_PIN_D6       GPIO_NUM_17
     #define CAM_PIN_D5       GPIO_NUM_18
-    #define CAM_PIN_D4       GPIO_NUM_12
+    #define CAM_PIN_D4       GPIO_NUM_47
     #define CAM_PIN_D3       GPIO_NUM_10
     #define CAM_PIN_D2       GPIO_NUM_8
     #define CAM_PIN_D1       GPIO_NUM_9

+ 145 - 145
sd-card/config/config.ini

@@ -1,145 +1,145 @@
-[TakeImage]
-;RawImagesLocation = /log/source
-;RawImagesRetention = 15
-WaitBeforeTakingPicture = 2
-CamGainceiling = x8
-CamQuality = 10
-CamBrightness = 0
-CamContrast = 0
-CamSaturation = 0
-CamSharpness = 0
-CamAutoSharpness = false
-CamSpecialEffect = no_effect
-CamWbMode = auto
-CamAwb = true
-CamAwbGain = true
-CamAec = true
-CamAec2 = true
-CamAeLevel = 2
-CamAecValue = 600
-CamAgc = true
-CamAgcGain = 8
-CamBpc = true
-CamWpc = true
-CamRawGma = true
-CamLenc = true
-CamHmirror = false
-CamVflip = false
-CamDcw = true
-CamDenoise = 0
-CamZoom = false
-CamZoomOffsetX = 0
-CamZoomOffsetY = 0
-CamZoomSize = 0
-LEDIntensity = 50
-Demo = false
-
-[Alignment]
-InitialRotate = 0.0
-SearchFieldX = 20
-SearchFieldY = 20
-AlignmentAlgo = default
-/config/ref0.jpg 103 271
-/config/ref1.jpg 442 142
-
-[Digits]
-Model = /config/dig-cont_0712_s3_q.tflite
-CNNGoodThreshold = 0.5
-;ROIImagesLocation = /log/digit
-;ROIImagesRetention = 3
-main.dig1 294 126 30 54 false
-main.dig2 343 126 30 54 false
-main.dig3 391 126 30 54 false
-
-[Analog]
-Model = /config/ana-cont_1300_s2.tflite
-CNNGoodThreshold = 0.5
-;ROIImagesLocation = /log/analog
-;ROIImagesRetention = 3
-main.ana1 432 230 92 92 false
-main.ana2 379 332 92 92 false
-main.ana3 283 374 92 92 false
-main.ana4 155 328 92 92 false
-
-[PostProcessing]
-main.DecimalShift = 0
-main.AnalogDigitTransitionStart = 9.2
-main.ChangeRateThreshold = 2
-PreValueUse = true
-PreValueAgeStartup = 720
-main.AllowNegativeRates = false
-main.MaxRateValue = 0.05
-;main.MaxRateType = AbsoluteChange
-main.ExtendedResolution = false
-main.IgnoreLeadingNaN = false
-ErrorMessage = true
-main.CheckDigitIncreaseConsistency = false
-
-;[MQTT]
-;Uri = mqtt://IP-ADRESS:1883
-;MainTopic = watermeter
-;ClientID = watermeter
-;user = USERNAME
-;password = PASSWORD
-RetainMessages = false
-HomeassistantDiscovery = false
-;MeterType = other
-;CACert = /config/certs/RootCA.pem
-;ClientCert = /config/certs/client.pem.crt
-;ClientKey = /config/certs/client.pem.key
-;ValidateServerCert = true
-;DomoticzTopicIn = domoticz/in
-;main.DomoticzIDX = 0
-
-;[InfluxDB]
-;Uri = undefined
-;Database = undefined
-;user = undefined
-;password = undefined
-;main.Measurement = undefined
-;main.Field = undefined
-
-;[InfluxDBv2]
-;Uri = undefined
-;Bucket = undefined
-;Org = undefined
-;Token = undefined
-;main.Measurement = undefined
-;main.Field = undefined
-
-;[Webhook]
-;Uri = undefined
-;ApiKey = undefined
-;UploadImg = 0
-
-;[GPIO]
-;MainTopicMQTT = wasserzaehler/GPIO
-;IO0 = input disabled 10 false false 
-;IO1 = input disabled 10 false false 
-;IO3 = input disabled 10 false false 
-;IO4 = built-in-led disabled 10 false false 
-;IO12 = input-pullup disabled 10 false false 
-;IO13 = input-pullup disabled 10 false false 
-LEDType = WS2812
-LEDNumbers = 2
-LEDColor = 150 150 150 
-
-[AutoTimer]
-Interval = 5
-
-[DataLogging]
-DataLogActive = true
-DataFilesRetention = 3
-
-[Debug]
-LogLevel = 1
-LogfilesRetention = 3
-
-[System]
-TimeZone = CET-1CEST,M3.5.0,M10.5.0/3
-;TimeServer = pool.ntp.org
-;Hostname = undefined
-RSSIThreshold = -75
-CPUFrequency = 160
-Tooltip = true
-SetupMode = true
+[TakeImage]
+;RawImagesLocation = /log/source
+;RawImagesRetention = 15
+WaitBeforeTakingPicture = 2
+CamGainceiling = x8
+CamQuality = 10
+CamBrightness = 0
+CamContrast = 0
+CamSaturation = 0
+CamSharpness = 0
+CamAutoSharpness = false
+CamSpecialEffect = no_effect
+CamWbMode = auto
+CamAwb = true
+CamAwbGain = true
+CamAec = true
+CamAec2 = true
+CamAeLevel = 2
+CamAecValue = 600
+CamAgc = true
+CamAgcGain = 8
+CamBpc = true
+CamWpc = true
+CamRawGma = true
+CamLenc = true
+CamHmirror = false
+CamVflip = false
+CamDcw = true
+CamDenoise = 0
+CamZoom = false
+CamZoomOffsetX = 0
+CamZoomOffsetY = 0
+CamZoomSize = 0
+LEDIntensity = 50
+Demo = false
+
+[Alignment]
+InitialRotate = 0.0
+SearchFieldX = 20
+SearchFieldY = 20
+AlignmentAlgo = default
+/config/ref0.jpg 103 271
+/config/ref1.jpg 442 142
+
+[Digits]
+Model = /config/dig-cont_0712_s3_q.tflite
+CNNGoodThreshold = 0.5
+;ROIImagesLocation = /log/digit
+;ROIImagesRetention = 3
+main.dig1 294 126 30 54 false
+main.dig2 343 126 30 54 false
+main.dig3 391 126 30 54 false
+
+[Analog]
+Model = /config/ana-cont_1300_s2.tflite
+CNNGoodThreshold = 0.5
+;ROIImagesLocation = /log/analog
+;ROIImagesRetention = 3
+main.ana1 432 230 92 92 false
+main.ana2 379 332 92 92 false
+main.ana3 283 374 92 92 false
+main.ana4 155 328 92 92 false
+
+[PostProcessing]
+main.DecimalShift = 0
+main.AnalogDigitTransitionStart = 9.2
+main.ChangeRateThreshold = 2
+PreValueUse = true
+PreValueAgeStartup = 720
+main.AllowNegativeRates = false
+main.MaxRateValue = 0.05
+;main.MaxRateType = AbsoluteChange
+main.ExtendedResolution = false
+main.IgnoreLeadingNaN = false
+ErrorMessage = true
+main.CheckDigitIncreaseConsistency = false
+
+;[MQTT]
+;Uri = mqtt://IP-ADRESS:1883
+;MainTopic = watermeter
+;ClientID = watermeter
+;user = USERNAME
+;password = PASSWORD
+RetainMessages = false
+HomeassistantDiscovery = false
+;MeterType = other
+;CACert = /config/certs/RootCA.pem
+;ClientCert = /config/certs/client.pem.crt
+;ClientKey = /config/certs/client.pem.key
+;ValidateServerCert = true
+;DomoticzTopicIn = domoticz/in
+;main.DomoticzIDX = 0
+
+;[InfluxDB]
+;Uri = undefined
+;Database = undefined
+;user = undefined
+;password = undefined
+;main.Measurement = undefined
+;main.Field = undefined
+
+;[InfluxDBv2]
+;Uri = undefined
+;Bucket = undefined
+;Org = undefined
+;Token = undefined
+;main.Measurement = undefined
+;main.Field = undefined
+
+;[Webhook]
+;Uri = undefined
+;ApiKey = undefined
+;UploadImg = 0
+
+[GPIO]
+;IO0 = input disabled 10 false false 
+;IO1 = input disabled 10 false false 
+;IO3 = input disabled 10 false false 
+;IO4 = built-in-led disabled 10 false false 
+IO12 = external-flash-ws281x disabled 10 false false 
+;IO13 = input-pullup disabled 10 false false 
+LEDType = WS2812
+LEDNumbers = 4
+LEDColor = 200 200 200
+
+[AutoTimer]
+Interval = 5
+SleepWhileIdle = false
+
+[DataLogging]
+DataLogActive = true
+DataFilesRetention = 3
+
+[Debug]
+LogLevel = 1
+LogfilesRetention = 3
+
+[System]
+TimeZone = CET-1CEST,M3.5.0,M10.5.0/3
+;TimeServer = pool.ntp.org
+;Hostname = undefined
+RSSIThreshold = -75
+CPUFrequency = 160
+Tooltip = true
+SetupMode = true

+ 15 - 0
sd-card/html/edit_config_template.html

@@ -1974,6 +1974,19 @@
             <td>$TOOLTIP_AutoTimer_Interval</td>
         </tr>
 
+        <tr>
+            <td class="indent1">
+                <class id="AutoTimer_SleepWhileIdle_text" style="color:black;">Sleep While Idle</class>
+            </td>
+            <td>
+                <select id="AutoTimer_SleepWhileIdle_value1">
+                    <option value="true">enabled (true)</option>
+                    <option value="false" selected>disabled (false)</option>
+                </select>
+            </td>
+            <td>$TOOLTIP_AutoTimer_SleepWhileIdle</td>
+        </tr>
+
         <!------------- Data Logging ------------------>
         <tr style="border-bottom: 2px solid lightgray;">
             <td colspan="3" style="padding-left: 0px; padding-bottom: 3px;"><h4>Data Logging</h4></td>
@@ -2402,6 +2415,7 @@ function UpdateInput() {
 
     //WriteParameter(param, category, "AutoTimer", "AutoStart", false);	
     WriteParameter(param, category, "AutoTimer", "Interval", false);
+    WriteParameter(param, category, "AutoTimer", "SleepWhileIdle", false);
 
     WriteParameter(param, category, "DataLogging", "DataLogActive", false);	
     WriteParameter(param, category, "DataLogging", "DataFilesRetention", false);	
@@ -2578,6 +2592,7 @@ function ReadParameterAll() {
 
     //ReadParameter(param, "AutoTimer", "AutoStart", false);
     ReadParameter(param, "AutoTimer", "Interval", false);
+    ReadParameter(param, "AutoTimer", "SleepWhileIdle", false);
     
     ReadParameter(param, "DataLogging", "DataLogActive", false);
     ReadParameter(param, "DataLogging", "DataFilesRetention", false);