Skip to content

Commit

Permalink
Merge pull request #725 from MartinMueller2003/main
Browse files Browse the repository at this point in the history
Restored setting time from the UI.
  • Loading branch information
forkineye authored Jan 12, 2024
2 parents 6181dd9 + 92e4ecd commit ff2dccd
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 27 deletions.
37 changes: 32 additions & 5 deletions ESPixelStick/src/WebMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
#include <FS.h>
#include <LittleFS.h>

#include <time.h>
#include <sys/time.h>
#include <functional>

#ifdef SUPPORT_SENSOR_DS18B20
#include "service/SensorDS18B20.h"
#endif // def SUPPORT_SENSOR_DS18B20
Expand Down Expand Up @@ -159,6 +155,23 @@ void c_WebMgr::init ()
ProcessXJRequest (request);
});

webServer.on ("/settime", HTTP_POST | HTTP_GET | HTTP_OPTIONS, [this](AsyncWebServerRequest* request)
{
// DEBUG_V("/settime");
// DEBUG_V(String("URL: ") + request->url());
if(HTTP_OPTIONS == request->method())
{
request->send (200);
}
else
{
String newDate = request->url ().substring (String (F("/settime/")).length ());
// DEBUG_V (String ("newDate: ") + String (newDate));
ProcessSetTimeRequest (time_t(newDate.toInt()));
request->send (200);
}
});

// Reboot handler
webServer.on ("/X6", HTTP_POST | HTTP_OPTIONS, [](AsyncWebServerRequest* request)
{
Expand Down Expand Up @@ -279,7 +292,7 @@ void c_WebMgr::init ()
else
{
// DEBUG_V (String ("url: ") + String (request->url ()));
String filename = request->url ().substring (String ("/file/delete").length ());
String filename = request->url ().substring (String (F("/file/delete")).length ());
// DEBUG_V (String ("filename: ") + String (filename));
FileMgr.DeleteSdFile(filename);
request->send (200);
Expand Down Expand Up @@ -629,6 +642,7 @@ void c_WebMgr::ProcessXJRequest (AsyncWebServerRequest* client)

system[F ("freeheap")] = ESP.getFreeHeap ();
system[F ("uptime")] = millis ();
system[F ("currenttime")] = now ();
system[F ("SDinstalled")] = FileMgr.SdCardIsInstalled ();
system[F ("DiscardedRxData")] = DiscardedRxData;

Expand Down Expand Up @@ -659,6 +673,7 @@ void c_WebMgr::ProcessXJRequest (AsyncWebServerRequest* client)
if(WebJsonDoc.overflowed())
{
logcon(F("ERROR: Status Doc is too small"));
client->send (401, CN_applicationSLASHjson, F("Internal Error. Status Buffer is too small."));
}
else
{
Expand All @@ -671,6 +686,18 @@ void c_WebMgr::ProcessXJRequest (AsyncWebServerRequest* client)

} // ProcessXJRequest

//-----------------------------------------------------------------------------
void c_WebMgr::ProcessSetTimeRequest (time_t DateTime)
{
// DEBUG_START;

// DEBUG_V(String("DateTime: ") + String(DateTime));
setTime(DateTime);
// DEBUG_V(String("now: ") + String(now()));

// DEBUG_END;
} // ProcessSetTimeRequest

//-----------------------------------------------------------------------------
void c_WebMgr::FirmwareUpload (AsyncWebServerRequest* request,
String filename,
Expand Down
3 changes: 2 additions & 1 deletion ESPixelStick/src/WebMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class c_WebMgr
void GetOptions ();

void ProcessXJRequest (AsyncWebServerRequest * client);

void ProcessSetTimeRequest (time_t DateTime);

void GetDeviceOptions ();
void GetInputOptions ();
void GetOutputOptions ();
Expand Down
15 changes: 15 additions & 0 deletions ESPixelStick/src/output/OutputPixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ void c_OutputPixel::StartNewFrame ()
FrameAppendDataCurrentIndex = 0;
SentPixelsCount = 0;
PixelIntensityCurrentIndex = 0;
PixelIntensityCurrentColor = 0;
PrependNullPixelCurrentCount = 0;
AppendNullPixelCurrentCount = 0;
PixelPrependDataCurrentIndex = 0;
Expand Down Expand Up @@ -447,6 +448,8 @@ uint32_t IRAM_ATTR c_OutputPixel::FramePrependData()
}
// PixelIntensityCurrentIndex = 0;
// PixelPrependDataCurrentIndex = 0;
// PixelIntensityCurrentColor = 0;

}
return response;
}
Expand Down Expand Up @@ -476,6 +479,7 @@ uint32_t IRAM_ATTR c_OutputPixel::PixelPrependNulls()
// pixel is complete. Move to the next one
PixelIntensityCurrentIndex = 0;
PixelPrependDataCurrentIndex = 0;
PixelIntensityCurrentColor = 0;

if (++PrependNullPixelCurrentCount < PrependNullPixelCount)
{
Expand Down Expand Up @@ -504,6 +508,9 @@ uint32_t IRAM_ATTR c_OutputPixel::PixelSendPrependIntensity()
// pixel prepend goes here
if (PixelPrependDataCurrentIndex >= PixelPrependDataSize)
{
// reset the prepend index for the next pixel
PixelPrependDataCurrentIndex = 0;

#ifdef SUPPORT_OutputType_GECE
if (OutputType == OTYPE_t::OutputType_GECE)
{
Expand Down Expand Up @@ -589,6 +596,7 @@ uint32_t IRAM_ATTR c_OutputPixel::PixelAppendNulls()
// pixel is complete. Move to the next one
PixelIntensityCurrentIndex = 0;
PixelPrependDataCurrentIndex = 0;
PixelIntensityCurrentColor = 0;

if (++AppendNullPixelCurrentCount < AppendNullPixelCount)
{
Expand Down Expand Up @@ -665,6 +673,7 @@ uint32_t IRAM_ATTR c_OutputPixel::GetIntensityData()
PixelPrependDataCurrentIndex = 0;
PixelIntensityCurrentIndex = 0;
AppendNullPixelCurrentCount = 0;
PixelIntensityCurrentColor = 0;

FrameStateFuncPtr = &c_OutputPixel::PixelAppendNulls;
}
Expand All @@ -681,6 +690,12 @@ uint32_t IRAM_ATTR c_OutputPixel::GetIntensityData()
FrameStateFuncPtr = &c_OutputPixel::FrameDone;
}
}
// are we at the end of a pixel and are we prepending pixel data?
else if(++PixelIntensityCurrentColor >= NumIntensityBytesPerPixel)
{
PixelIntensityCurrentColor = 0;
SetStartingSendPixelState();
}

return response;
}
Expand Down
1 change: 1 addition & 0 deletions ESPixelStick/src/output/OutputPixel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class c_OutputPixel : public c_OutputCommon
uint32_t pixel_count = 100;
uint32_t SentPixelsCount = 0;
uint32_t PixelIntensityCurrentIndex = 0;
uint32_t PixelIntensityCurrentColor = 0;

uint8_t * pFramePrependData = nullptr;
uint32_t FramePrependDataSize = 0;
Expand Down
1 change: 1 addition & 0 deletions ESPixelStick/src/output/OutputSpi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "../ESPixelStick.h"
#ifdef SUPPORT_SPI_OUTPUT

#include "OutputPixel.hpp"
#include <driver/spi_master.h>
#include <esp_task.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@
#define DEFAULT_RMT_1_GPIO gpio_num_t::GPIO_NUM_13

#define DEFAULT_RMT_2_GPIO gpio_num_t::GPIO_NUM_12
#define DEFAULT_RMT_3_GPIO gpio_num_t::GPIO_NUM_14
#define DEFAULT_RMT_4_GPIO gpio_num_t::GPIO_NUM_32
#define DEFAULT_RMT_5_GPIO gpio_num_t::GPIO_NUM_33

// SPI Output
#define SUPPORT_SPI_OUTPUT
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_16
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_17
#define DEFAULT_SPI_DATA_GPIO gpio_num_t::GPIO_NUM_27
#define DEFAULT_SPI_CLOCK_GPIO gpio_num_t::GPIO_NUM_32

#define DEFAULT_I2C_SDA gpio_num_t::GPIO_NUM_3
#define DEFAULT_I2C_SCL gpio_num_t::GPIO_NUM_5
Expand All @@ -42,7 +39,7 @@
#define SD_CARD_CLK_PIN gpio_num_t::GPIO_NUM_18
#define SD_CARD_CS_PIN gpio_num_t::GPIO_NUM_4

#define DEFAULT_RELAY_GPIO gpio_num_t::GPIO_NUM_1
#define DEFAULT_RELAY_GPIO gpio_num_t::GPIO_NUM_14

// Output Types
// Not Finished - #define SUPPORT_OutputType_TLS3001
Expand Down
4 changes: 4 additions & 0 deletions html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
<td width="33%">Up Time</td>
<td><span id="x_uptime"></span></td>
</tr>
<tr>
<td width="33%">Current Time</td>
<td><span id="x_currenttime"></span></td>
</tr>
<tr>
<td width="33%" id="i_size">Flash Total</td>
<td><span id="x_size"></span></td>
Expand Down
26 changes: 26 additions & 0 deletions html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,21 @@ $(function () {
DocumentIsHidden = true;
} else {
DocumentIsHidden = false;
SetServerTime();
}
});

SetServerTime();
});

function SetServerTime()
{
// console.info("SetServerTime");
let CurrentDate = Math.floor((new Date()).getTime() / 1000);
// console.info("CurrentDate: " + CurrentDate);
SendCommand('settime/' + (CurrentDate));
} // SetServerTime

function ProcessLocalConfig(data) {
// console.info(data);
let ParsedLocalConfig = JSON.parse(data);
Expand Down Expand Up @@ -641,6 +652,10 @@ function ProcessGetFileListResponse(JsonConfigData) {
// console.info("not last. Ask for the next chunk");
RequestListOfFiles(JsonConfigData.last);
}
else
{
SetServerTime();
}
} // end expected file ID

} // ProcessGetFileListResponse
Expand Down Expand Up @@ -1796,6 +1811,17 @@ function ProcessReceivedJsonStatusMessage(JsonStat) {
str += ("0" + date.getUTCSeconds()).slice(-2);
$('#x_uptime').text(str);

date = new Date(1000 * System.currenttime);
// console.info("DateMS: " + date.getMilliseconds());
$('#x_currenttime').text(date.toUTCString());
let CurrDate = new Date();
// console.info("CurrDateMS: " + CurrDate);
let Delta = Math.abs(CurrDate.getTime() - date.getTime())/1000;
// console.info("DeltaS: " + Delta);
if(Delta > 5)
{
SetServerTime();
}
if ({}.hasOwnProperty.call(System, 'used')) {
$('#i_size').removeClass("hidden");
$('#x_size').removeClass("hidden");
Expand Down
15 changes: 0 additions & 15 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ build_flags =
${esp32git.build_flags}
-D BOARD_NAME='"d32_pro"'
-D BOARD_ESP32_LOLIN_D32_PRO
-D BOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue
-mfix-esp32-psram-cache-strategy=memw
; -D CONFIG_ESP_SYSTEM_PANIC_GDBSTUB -O0 -ggdb3 -g3
Expand All @@ -176,7 +175,6 @@ build_flags =
${esp32git.build_flags}
-D BOARD_NAME='"d32_pro_eth"'
-D BOARD_ESP32_LOLIN_D32_PRO_ETH
-D BOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue
-mfix-esp32-psram-cache-strategy=memw

Expand All @@ -193,7 +191,6 @@ build_flags =
-fexceptions
build_unflags =
-fno-exceptions
-D BOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue
-mfix-esp32-psram-cache-strategy=memw

Expand All @@ -219,9 +216,6 @@ build_flags =
${esp32git.build_flags}
-D BOARD_NAME='"d1_mini32"'
-D BOARD_ESP32_D1_MINI
-D BOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue
-mfix-esp32-psram-cache-strategy=memw

; Generic Wemos D1 Mini 32
[env:d1_mini32_eth]
Expand All @@ -231,9 +225,6 @@ build_flags =
${esp32git.build_flags}
-D BOARD_NAME='"d1_mini32_eth"'
-D BOARD_ESP32_D1_MINI_ETH
-D BOARD_HAS_PSRAM
-mfix-esp32-psram-cache-issue
-mfix-esp32-psram-cache-strategy=memw

; WT 32 ETH 01
[env:esp32_wt32eth01]
Expand All @@ -244,9 +235,6 @@ build_flags =
-D BOARD_NAME='"esp32_wt32eth01"'
-D BOARD_ESP32_WT32ETH01
-I ./.pio/packages/framework-arduinoespressif32/libraries/Ethernet/src
; -D BOARD_HAS_PSRAM
; -mfix-esp32-psram-cache-issue
; -mfix-esp32-psram-cache-strategy=memw

[env:esp32_quinled_dig_octa]
extends = esp32git
Expand Down Expand Up @@ -436,6 +424,3 @@ build_flags =
-D BOARD_NAME='"esp32_wasatch"'
-D BOARD_ESP32_WT32ETH01_WASATCH
-I ./.pio/packages/framework-arduinoespressif32/libraries/Ethernet/src
; -D BOARD_HAS_PSRAM
; -mfix-esp32-psram-cache-issue
; -mfix-esp32-psram-cache-strategy=memw

0 comments on commit ff2dccd

Please sign in to comment.