Skip to content

Commit

Permalink
lamp default state fix easytarget#204
Browse files Browse the repository at this point in the history
  • Loading branch information
easytarget committed Mar 9, 2022
1 parent 322187c commit cb78162
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
1 change: 1 addition & 0 deletions app_httpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ static esp_err_t cmd_handler(httpd_req_t *req){
if (filesystem) removePrefs(SPIFFS);
}
else if(!strcmp(variable, "reboot")) {
if (lampVal != -1) setLamp(0); // kill the lamp; otherwise it can remain on during the soft-reboot
esp_task_wdt_init(3,true); // schedule a a watchdog panic event for 3 seconds in the future
esp_task_wdt_add(NULL);
periph_module_disable(PERIPH_I2C0_MODULE); // try to shut I2C down properly
Expand Down
41 changes: 20 additions & 21 deletions esp32-cam-webserver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -666,24 +666,13 @@ void setup() {
* Camera setup complete; initialise the rest of the hardware.
*/

// Initialise and set the lamp
if (lampVal != -1) {
ledcSetup(lampChannel, pwmfreq, pwmresolution); // configure LED PWM channel
if (autoLamp) setLamp(0); // set default value
else setLamp(lampVal);
#if defined(LAMP_PIN)
ledcAttachPin(LAMP_PIN, lampChannel); // attach the GPIO pin to the channel
#endif
} else {
Serial.println("No lamp, or lamp disabled in config");
}

// Having got this far; start Wifi and loop until we are connected or have started an AccessPoint
// Start Wifi and loop until we are connected or have started an AccessPoint
while ((WiFi.status() != WL_CONNECTED) && !accesspoint) {
WifiSetup();
delay(1000);
}

// Set up OTA
if (otaEnabled) {
// Start OTA once connected
Serial.println("Setting up OTA");
Expand Down Expand Up @@ -736,7 +725,22 @@ void setup() {
Serial.println("Time functions disabled");
}

// Now we have a network we can start the two http handlers for the UI and Stream.
// Gather static values used when dumping status; these are slow functions, so just do them once during startup
sketchSize = ESP.getSketchSize();
sketchSpace = ESP.getFreeSketchSpace();
sketchMD5 = ESP.getSketchMD5();

// Initialise and set the lamp
if (lampVal != -1) {
ledcSetup(lampChannel, pwmfreq, pwmresolution); // configure LED PWM channel
ledcAttachPin(LAMP_PIN, lampChannel); // attach the GPIO pin to the channel
if (autoLamp) setLamp(0); // set default value
else setLamp(lampVal);
} else {
Serial.println("No lamp, or lamp disabled in config");
}

// Start the camera server
startCameraServer(httpPort, streamPort);

if (critERR.length() == 0) {
Expand All @@ -752,16 +756,11 @@ void setup() {
Serial.printf("\r\nCamera unavailable due to initialisation errors.\r\n\r\n");
}

// Used when dumping status; these are slow functions, so just do them once during startup
sketchSize = ESP.getSketchSize();
sketchSpace = ESP.getFreeSketchSpace();
sketchMD5 = ESP.getSketchMD5();
// Info line; use for Info messages; eg 'This is a Beta!' warnings, etc. as necesscary
// Serial.print("\r\nThis is the 4.1 beta\r\n");

// As a final init step chomp out the serial buffer in case we have recieved mis-keys or garbage during startup
while (Serial.available()) Serial.read();

// Info line; use for Info messages; eg 'This is a Beta!' warnings, etc. as necesscary
// Serial.print("\r\nThis is the 4.1 beta\r\n");
}

void loop() {
Expand Down
2 changes: 1 addition & 1 deletion myconfig.sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ struct station stationList[] = {{"ssid1", "pass1", true},
// #define LAMP_DISABLE

// Define the startup lamp power setting (as a percentage, defaults to 0%)
// Saved (SPIFFS) user settings will override this
// #define LAMP_DEFAULT 0

// Assume the module used has a SPIFFS/LittleFS partition, and use that for persistent setting storage
Expand Down Expand Up @@ -190,4 +191,3 @@ struct station stationList[] = {{"ssid1", "pass1", true},
// For clone modules that have camera module and SPIFFS startup issues try setting
// this very low (start at 2MHZ and increase):
// #define XCLK_FREQ_MHZ 2

0 comments on commit cb78162

Please sign in to comment.