mirror of
https://github.com/lumapu/ahoy.git
synced 2025-04-28 17:56:21 +02:00
0.8.112
* improved wizard * converted ePaper and Ethernet to hal-SPI * improved network connection
This commit is contained in:
parent
9d8ef19290
commit
b291ad1f4d
12 changed files with 142 additions and 433 deletions
|
@ -1,362 +0,0 @@
|
|||
diff --git a/src/GxEPD2_EPD.cpp b/src/GxEPD2_EPD.cpp
|
||||
index 8df8bef..91d7f49 100644
|
||||
--- a/src/GxEPD2_EPD.cpp
|
||||
+++ b/src/GxEPD2_EPD.cpp
|
||||
@@ -19,9 +19,9 @@
|
||||
|
||||
GxEPD2_EPD::GxEPD2_EPD(int16_t cs, int16_t dc, int16_t rst, int16_t busy, int16_t busy_level, uint32_t busy_timeout,
|
||||
uint16_t w, uint16_t h, GxEPD2::Panel p, bool c, bool pu, bool fpu) :
|
||||
- WIDTH(w), HEIGHT(h), panel(p), hasColor(c), hasPartialUpdate(pu), hasFastPartialUpdate(fpu),
|
||||
+ WIDTH(w), HEIGHT(h), panel(p), hasColor(c), hasPartialUpdate(pu), hasFastPartialUpdate(fpu), _sck(-1), _mosi(-1),
|
||||
_cs(cs), _dc(dc), _rst(rst), _busy(busy), _busy_level(busy_level), _busy_timeout(busy_timeout), _diag_enabled(false),
|
||||
- _pSPIx(&SPI), _spi_settings(4000000, MSBFIRST, SPI_MODE0)
|
||||
+ _spi_settings(4000000, MSBFIRST, SPI_MODE0)
|
||||
{
|
||||
_initial_write = true;
|
||||
_initial_refresh = true;
|
||||
@@ -71,27 +71,30 @@ void GxEPD2_EPD::init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset
|
||||
{
|
||||
pinMode(_busy, INPUT);
|
||||
}
|
||||
- _pSPIx->begin();
|
||||
- if (_busy == MISO) // may be overridden
|
||||
- {
|
||||
- pinMode(_busy, INPUT);
|
||||
- }
|
||||
- if (_dc == MISO) // may be overridden, TTGO T5 V2.66
|
||||
- {
|
||||
- pinMode(_dc, OUTPUT);
|
||||
- }
|
||||
- if (_cs == MISO) // may be overridden
|
||||
+ if (_sck < 0) SPI.begin();
|
||||
+}
|
||||
+
|
||||
+void GxEPD2_EPD::init(int16_t sck, int16_t mosi, uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration, bool pulldown_rst_mode)
|
||||
+{
|
||||
+ if ((sck >= 0) && (mosi >= 0))
|
||||
{
|
||||
- pinMode(_cs, INPUT);
|
||||
- }
|
||||
+ _sck = sck;
|
||||
+ _mosi = mosi;
|
||||
+ digitalWrite(_sck, LOW);
|
||||
+ digitalWrite(_mosi, LOW);
|
||||
+ pinMode(_sck, OUTPUT);
|
||||
+ pinMode(_mosi, OUTPUT);
|
||||
+ } else _sck = -1;
|
||||
+ init(serial_diag_bitrate, initial, reset_duration, pulldown_rst_mode);
|
||||
}
|
||||
|
||||
void GxEPD2_EPD::end()
|
||||
{
|
||||
- _pSPIx->end();
|
||||
if (_cs >= 0) pinMode(_cs, INPUT);
|
||||
if (_dc >= 0) pinMode(_dc, INPUT);
|
||||
if (_rst >= 0) pinMode(_rst, INPUT);
|
||||
+ if (_sck >= 0) pinMode(_sck, INPUT);
|
||||
+ if (_mosi >= 0) pinMode(_mosi, INPUT);
|
||||
}
|
||||
|
||||
void GxEPD2_EPD::setBusyCallback(void (*busyCallback)(const void*), const void* busy_callback_parameter)
|
||||
@@ -100,12 +103,6 @@ void GxEPD2_EPD::setBusyCallback(void (*busyCallback)(const void*), const void*
|
||||
_busy_callback_parameter = busy_callback_parameter;
|
||||
}
|
||||
|
||||
-void GxEPD2_EPD::selectSPI(SPIClass& spi, SPISettings spi_settings)
|
||||
-{
|
||||
- _pSPIx = &spi;
|
||||
- _spi_settings = spi_settings;
|
||||
-}
|
||||
-
|
||||
void GxEPD2_EPD::_reset()
|
||||
{
|
||||
if (_rst >= 0)
|
||||
@@ -174,115 +171,201 @@ void GxEPD2_EPD::_waitWhileBusy(const char* comment, uint16_t busy_time)
|
||||
|
||||
void GxEPD2_EPD::_writeCommand(uint8_t c)
|
||||
{
|
||||
- _pSPIx->beginTransaction(_spi_settings);
|
||||
+ _beginTransaction(_spi_settings);
|
||||
if (_dc >= 0) digitalWrite(_dc, LOW);
|
||||
if (_cs >= 0) digitalWrite(_cs, LOW);
|
||||
- _pSPIx->transfer(c);
|
||||
+ _spi_write(c);
|
||||
if (_cs >= 0) digitalWrite(_cs, HIGH);
|
||||
if (_dc >= 0) digitalWrite(_dc, HIGH);
|
||||
- _pSPIx->endTransaction();
|
||||
+ _endTransaction();
|
||||
}
|
||||
|
||||
void GxEPD2_EPD::_writeData(uint8_t d)
|
||||
{
|
||||
- _pSPIx->beginTransaction(_spi_settings);
|
||||
+ _beginTransaction(_spi_settings);
|
||||
if (_cs >= 0) digitalWrite(_cs, LOW);
|
||||
- _pSPIx->transfer(d);
|
||||
+ _spi_write(d);
|
||||
if (_cs >= 0) digitalWrite(_cs, HIGH);
|
||||
- _pSPIx->endTransaction();
|
||||
+ _endTransaction();
|
||||
}
|
||||
|
||||
void GxEPD2_EPD::_writeData(const uint8_t* data, uint16_t n)
|
||||
{
|
||||
- _pSPIx->beginTransaction(_spi_settings);
|
||||
+ _beginTransaction(_spi_settings);
|
||||
if (_cs >= 0) digitalWrite(_cs, LOW);
|
||||
- for (uint16_t i = 0; i < n; i++)
|
||||
+ for (uint8_t i = 0; i < n; i++)
|
||||
{
|
||||
- _pSPIx->transfer(*data++);
|
||||
+ _spi_write(*data++);
|
||||
}
|
||||
if (_cs >= 0) digitalWrite(_cs, HIGH);
|
||||
- _pSPIx->endTransaction();
|
||||
+ _endTransaction();
|
||||
}
|
||||
|
||||
void GxEPD2_EPD::_writeDataPGM(const uint8_t* data, uint16_t n, int16_t fill_with_zeroes)
|
||||
{
|
||||
- _pSPIx->beginTransaction(_spi_settings);
|
||||
+ _beginTransaction(_spi_settings);
|
||||
if (_cs >= 0) digitalWrite(_cs, LOW);
|
||||
- for (uint16_t i = 0; i < n; i++)
|
||||
+ for (uint8_t i = 0; i < n; i++)
|
||||
{
|
||||
- _pSPIx->transfer(pgm_read_byte(&*data++));
|
||||
+ _spi_write(pgm_read_byte(&*data++));
|
||||
}
|
||||
while (fill_with_zeroes > 0)
|
||||
{
|
||||
- _pSPIx->transfer(0x00);
|
||||
+ _spi_write(0x00);
|
||||
fill_with_zeroes--;
|
||||
}
|
||||
if (_cs >= 0) digitalWrite(_cs, HIGH);
|
||||
- _pSPIx->endTransaction();
|
||||
+ _endTransaction();
|
||||
}
|
||||
|
||||
void GxEPD2_EPD::_writeDataPGM_sCS(const uint8_t* data, uint16_t n, int16_t fill_with_zeroes)
|
||||
{
|
||||
- _pSPIx->beginTransaction(_spi_settings);
|
||||
+ _beginTransaction(_spi_settings);
|
||||
for (uint8_t i = 0; i < n; i++)
|
||||
{
|
||||
if (_cs >= 0) digitalWrite(_cs, LOW);
|
||||
- _pSPIx->transfer(pgm_read_byte(&*data++));
|
||||
+ _spi_write(pgm_read_byte(&*data++));
|
||||
if (_cs >= 0) digitalWrite(_cs, HIGH);
|
||||
}
|
||||
while (fill_with_zeroes > 0)
|
||||
{
|
||||
if (_cs >= 0) digitalWrite(_cs, LOW);
|
||||
- _pSPIx->transfer(0x00);
|
||||
+ _spi_write(0x00);
|
||||
fill_with_zeroes--;
|
||||
if (_cs >= 0) digitalWrite(_cs, HIGH);
|
||||
}
|
||||
- _pSPIx->endTransaction();
|
||||
+ _endTransaction();
|
||||
}
|
||||
|
||||
void GxEPD2_EPD::_writeCommandData(const uint8_t* pCommandData, uint8_t datalen)
|
||||
{
|
||||
- _pSPIx->beginTransaction(_spi_settings);
|
||||
+ _beginTransaction(_spi_settings);
|
||||
if (_dc >= 0) digitalWrite(_dc, LOW);
|
||||
if (_cs >= 0) digitalWrite(_cs, LOW);
|
||||
- _pSPIx->transfer(*pCommandData++);
|
||||
+ _spi_write(*pCommandData++);
|
||||
if (_dc >= 0) digitalWrite(_dc, HIGH);
|
||||
for (uint8_t i = 0; i < datalen - 1; i++) // sub the command
|
||||
{
|
||||
- _pSPIx->transfer(*pCommandData++);
|
||||
+ _spi_write(*pCommandData++);
|
||||
}
|
||||
if (_cs >= 0) digitalWrite(_cs, HIGH);
|
||||
- _pSPIx->endTransaction();
|
||||
+ _endTransaction();
|
||||
}
|
||||
|
||||
void GxEPD2_EPD::_writeCommandDataPGM(const uint8_t* pCommandData, uint8_t datalen)
|
||||
{
|
||||
- _pSPIx->beginTransaction(_spi_settings);
|
||||
+ _beginTransaction(_spi_settings);
|
||||
if (_dc >= 0) digitalWrite(_dc, LOW);
|
||||
if (_cs >= 0) digitalWrite(_cs, LOW);
|
||||
- _pSPIx->transfer(pgm_read_byte(&*pCommandData++));
|
||||
+ _spi_write(pgm_read_byte(&*pCommandData++));
|
||||
if (_dc >= 0) digitalWrite(_dc, HIGH);
|
||||
for (uint8_t i = 0; i < datalen - 1; i++) // sub the command
|
||||
{
|
||||
- _pSPIx->transfer(pgm_read_byte(&*pCommandData++));
|
||||
+ _spi_write(pgm_read_byte(&*pCommandData++));
|
||||
}
|
||||
if (_cs >= 0) digitalWrite(_cs, HIGH);
|
||||
- _pSPIx->endTransaction();
|
||||
+ _endTransaction();
|
||||
}
|
||||
|
||||
void GxEPD2_EPD::_startTransfer()
|
||||
{
|
||||
- _pSPIx->beginTransaction(_spi_settings);
|
||||
+ _beginTransaction(_spi_settings);
|
||||
if (_cs >= 0) digitalWrite(_cs, LOW);
|
||||
}
|
||||
|
||||
void GxEPD2_EPD::_transfer(uint8_t value)
|
||||
{
|
||||
- _pSPIx->transfer(value);
|
||||
+ _spi_write(value);
|
||||
}
|
||||
|
||||
void GxEPD2_EPD::_endTransfer()
|
||||
{
|
||||
if (_cs >= 0) digitalWrite(_cs, HIGH);
|
||||
- _pSPIx->endTransaction();
|
||||
+ _endTransaction();
|
||||
+}
|
||||
+
|
||||
+void GxEPD2_EPD::_beginTransaction(const SPISettings& settings)
|
||||
+{
|
||||
+ if (_sck < 0) SPI.beginTransaction(settings);
|
||||
+}
|
||||
+
|
||||
+void GxEPD2_EPD::_spi_write(uint8_t data)
|
||||
+{
|
||||
+ if (_sck < 0) SPI.transfer(data);
|
||||
+ else
|
||||
+ {
|
||||
+#if defined (ESP8266)
|
||||
+ yield();
|
||||
+#endif
|
||||
+ for (int i = 0; i < 8; i++)
|
||||
+ {
|
||||
+ digitalWrite(_mosi, (data & 0x80) ? HIGH : LOW);
|
||||
+ data <<= 1;
|
||||
+ digitalWrite(_sck, HIGH);
|
||||
+ digitalWrite(_sck, LOW);
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void GxEPD2_EPD::_endTransaction()
|
||||
+{
|
||||
+ if (_sck < 0) SPI.endTransaction();
|
||||
+}
|
||||
+
|
||||
+uint8_t GxEPD2_EPD::_readData()
|
||||
+{
|
||||
+ uint8_t data = 0;
|
||||
+ _beginTransaction(_spi_settings);
|
||||
+ if (_cs >= 0) digitalWrite(_cs, LOW);
|
||||
+ if (_sck < 0)
|
||||
+ {
|
||||
+ data = SPI.transfer(0);
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ pinMode(_mosi, INPUT);
|
||||
+ for (int i = 0; i < 8; i++)
|
||||
+ {
|
||||
+ data <<= 1;
|
||||
+ digitalWrite(_sck, HIGH);
|
||||
+ data |= digitalRead(_mosi);
|
||||
+ digitalWrite(_sck, LOW);
|
||||
+ }
|
||||
+ pinMode(_mosi, OUTPUT);
|
||||
+ }
|
||||
+ if (_cs >= 0) digitalWrite(_cs, HIGH);
|
||||
+ _endTransaction();
|
||||
+ return data;
|
||||
+}
|
||||
+
|
||||
+void GxEPD2_EPD::_readData(uint8_t* data, uint16_t n)
|
||||
+{
|
||||
+ _beginTransaction(_spi_settings);
|
||||
+ if (_cs >= 0) digitalWrite(_cs, LOW);
|
||||
+ if (_sck < 0)
|
||||
+ {
|
||||
+ for (uint8_t i = 0; i < n; i++)
|
||||
+ {
|
||||
+ *data++ = SPI.transfer(0);
|
||||
+ }
|
||||
+ }
|
||||
+ else
|
||||
+ {
|
||||
+ pinMode(_mosi, INPUT);
|
||||
+ for (uint8_t i = 0; i < n; i++)
|
||||
+ {
|
||||
+ *data = 0;
|
||||
+ for (int i = 0; i < 8; i++)
|
||||
+ {
|
||||
+ *data <<= 1;
|
||||
+ digitalWrite(_sck, HIGH);
|
||||
+ *data |= digitalRead(_mosi);
|
||||
+ digitalWrite(_sck, LOW);
|
||||
+ }
|
||||
+ data++;
|
||||
+ }
|
||||
+ pinMode(_mosi, OUTPUT);
|
||||
+ }
|
||||
+ if (_cs >= 0) digitalWrite(_cs, HIGH);
|
||||
+ _endTransaction();
|
||||
}
|
||||
diff --git a/src/GxEPD2_EPD.h b/src/GxEPD2_EPD.h
|
||||
index 34c1145..c480b7d 100644
|
||||
--- a/src/GxEPD2_EPD.h
|
||||
+++ b/src/GxEPD2_EPD.h
|
||||
@@ -8,6 +8,10 @@
|
||||
// Version: see library.properties
|
||||
//
|
||||
// Library: https://github.com/ZinggJM/GxEPD2
|
||||
+// To use SW SPI with GxEPD2:
|
||||
+// add the special call to the added init method BEFORE the normal init method:
|
||||
+// display.epd2.init(SW_SCK, SW_MOSI, 115200, true, 20, false); // define or replace SW_SCK, SW_MOSI
|
||||
+// display.init(115200); // needed to init upper level
|
||||
|
||||
#ifndef _GxEPD2_EPD_H_
|
||||
#define _GxEPD2_EPD_H_
|
||||
@@ -35,6 +39,7 @@ class GxEPD2_EPD
|
||||
uint16_t w, uint16_t h, GxEPD2::Panel p, bool c, bool pu, bool fpu);
|
||||
virtual void init(uint32_t serial_diag_bitrate = 0); // serial_diag_bitrate = 0 : disabled
|
||||
virtual void init(uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration = 10, bool pulldown_rst_mode = false);
|
||||
+ virtual void init(int16_t sck, int16_t mosi, uint32_t serial_diag_bitrate, bool initial, uint16_t reset_duration = 20, bool pulldown_rst_mode = false);
|
||||
virtual void end(); // release SPI and control pins
|
||||
// Support for Bitmaps (Sprites) to Controller Buffer and to Screen
|
||||
virtual void clearScreen(uint8_t value) = 0; // init controller memory and screen (default white)
|
||||
@@ -97,7 +102,6 @@ class GxEPD2_EPD
|
||||
{
|
||||
return (a > b ? a : b);
|
||||
};
|
||||
- void selectSPI(SPIClass& spi, SPISettings spi_settings);
|
||||
protected:
|
||||
void _reset();
|
||||
void _waitWhileBusy(const char* comment = 0, uint16_t busy_time = 5000);
|
||||
@@ -111,17 +115,22 @@ class GxEPD2_EPD
|
||||
void _startTransfer();
|
||||
void _transfer(uint8_t value);
|
||||
void _endTransfer();
|
||||
+ void _beginTransaction(const SPISettings& settings);
|
||||
+ void _spi_write(uint8_t data);
|
||||
+ void _endTransaction();
|
||||
+ public:
|
||||
+ uint8_t _readData();
|
||||
+ void _readData(uint8_t* data, uint16_t n);
|
||||
protected:
|
||||
- int16_t _cs, _dc, _rst, _busy, _busy_level;
|
||||
+ int16_t _cs, _dc, _rst, _busy, _busy_level, _sck, _mosi;;
|
||||
uint32_t _busy_timeout;
|
||||
bool _diag_enabled, _pulldown_rst_mode;
|
||||
- SPIClass* _pSPIx;
|
||||
SPISettings _spi_settings;
|
||||
bool _initial_write, _initial_refresh;
|
||||
bool _power_is_on, _using_partial_mode, _hibernating;
|
||||
bool _init_display_done;
|
||||
uint16_t _reset_duration;
|
||||
- void (*_busy_callback)(const void*);
|
||||
+ void (*_busy_callback)(const void*);
|
||||
const void* _busy_callback_parameter;
|
||||
};
|
||||
|
|
@ -28,9 +28,6 @@ def applyPatch(libName, patchFile):
|
|||
# list of patches to apply (relative to /src)
|
||||
applyPatch("ESPAsyncWebServer-esphome", "../patches/AsyncWeb_Prometheus.patch")
|
||||
|
||||
#if env['PIOENV'][:13] == "opendtufusion":
|
||||
#applyPatch("GxEPD2", "../patches/GxEPD2_SW_SPI.patch")
|
||||
#el
|
||||
if (env['PIOENV'][:5] == "esp32") or (env['PIOENV'][:13] == "opendtufusion"):
|
||||
applyPatch("GxEPD2", "../patches/GxEPD2_HAL.patch")
|
||||
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
# Development Changes
|
||||
|
||||
## 0.8.112 - 2024-04-24
|
||||
* improved wizard
|
||||
* converted ePaper and Ethernet to hal-SPI
|
||||
* improved network connection
|
||||
|
||||
## 0.8.111 - 2024-04-17
|
||||
* fix MqTT discovery field `ALARM_MES_ID` #1591
|
||||
* fix Wifi reconnect for ESP32 #1589 #1575
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
//-------------------------------------
|
||||
#define VERSION_MAJOR 0
|
||||
#define VERSION_MINOR 8
|
||||
#define VERSION_PATCH 111
|
||||
#define VERSION_PATCH 112
|
||||
//-------------------------------------
|
||||
typedef struct {
|
||||
uint8_t ch;
|
||||
|
|
|
@ -23,30 +23,20 @@ class AhoyEthernet : public AhoyNetwork {
|
|||
|
||||
mEthSpi.begin(mConfig->sys.eth.pinMiso, mConfig->sys.eth.pinMosi, mConfig->sys.eth.pinSclk, mConfig->sys.eth.pinCs, mConfig->sys.eth.pinIrq, mConfig->sys.eth.pinRst);
|
||||
ETH.setHostname(mConfig->sys.deviceName);
|
||||
|
||||
// static IP
|
||||
setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
|
||||
return ETH.config(ip, gateway, mask, dns1, dns2);
|
||||
});
|
||||
}
|
||||
|
||||
void tickNetworkLoop() override {
|
||||
if(mAp.isEnabled())
|
||||
mAp.tickLoop();
|
||||
|
||||
switch(mStatus) {
|
||||
case NetworkState::DISCONNECTED:
|
||||
if(mConnected) {
|
||||
mConnected = false;
|
||||
mOnNetworkCB(false);
|
||||
mAp.enable();
|
||||
void OnEvent(WiFiEvent_t event) override {
|
||||
switch(event) {
|
||||
case ARDUINO_EVENT_ETH_CONNECTED:
|
||||
if(NetworkState::CONNECTED != mStatus) {
|
||||
mStatus = NetworkState::CONNECTED;
|
||||
DPRINTLN(DBG_INFO, F("Network connected"));
|
||||
setStaticIp();
|
||||
}
|
||||
break;
|
||||
|
||||
case NetworkState::CONNECTED:
|
||||
break;
|
||||
|
||||
case NetworkState::GOT_IP:
|
||||
case ARDUINO_EVENT_ETH_GOT_IP:
|
||||
mStatus = NetworkState::GOT_IP;
|
||||
if(!mConnected) {
|
||||
mAp.disable();
|
||||
mConnected = true;
|
||||
|
@ -55,13 +45,39 @@ class AhoyEthernet : public AhoyNetwork {
|
|||
mOnNetworkCB(true);
|
||||
}
|
||||
break;
|
||||
|
||||
case ARDUINO_EVENT_ETH_STOP:
|
||||
[[fallthrough]];
|
||||
case ARDUINO_EVENT_ETH_DISCONNECTED:
|
||||
mStatus = NetworkState::DISCONNECTED;
|
||||
if(mConnected) {
|
||||
mConnected = false;
|
||||
mOnNetworkCB(false);
|
||||
mAp.enable();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void tickNetworkLoop() override {
|
||||
if(mAp.isEnabled())
|
||||
mAp.tickLoop();
|
||||
}
|
||||
|
||||
String getIp(void) override {
|
||||
return ETH.localIP().toString();
|
||||
}
|
||||
|
||||
private:
|
||||
void setStaticIp() override {
|
||||
setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
|
||||
return ETH.config(ip, gateway, mask, dns1, dns2);
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
AhoyEthernetSpi mEthSpi;
|
||||
};
|
||||
|
|
|
@ -50,7 +50,8 @@ class AhoyEthernetSpi {
|
|||
mHostDevice = (14 == pin_sclk) ? SPI2_HOST : SPI3_HOST;
|
||||
#endif
|
||||
|
||||
mSpiPatcher = SpiPatcher::getInstance(mHostDevice);
|
||||
mSpiPatcher = SpiPatcher::getInstance(mHostDevice, false);
|
||||
mSpiPatcher->initBus(pin_mosi, pin_miso, pin_sclk, SPI_DMA_CH_AUTO);
|
||||
|
||||
spi_device_interface_config_t devcfg = {
|
||||
.command_bits = 16, // actually address phase
|
||||
|
|
|
@ -28,7 +28,6 @@ class AhoyNetwork {
|
|||
|
||||
if('\0' == mConfig->sys.deviceName[0])
|
||||
snprintf(mConfig->sys.deviceName, DEVNAME_LEN, "%s", DEF_DEVICE_NAME);
|
||||
WiFi.hostname(mConfig->sys.deviceName);
|
||||
|
||||
mAp.setup(&mConfig->sys);
|
||||
|
||||
|
@ -117,13 +116,17 @@ class AhoyNetwork {
|
|||
|
||||
void scan(void) {
|
||||
mScanActive = true;
|
||||
if(NetworkState::GOT_IP != mStatus)
|
||||
if(mWifiConnecting) {
|
||||
mWifiConnecting = false;
|
||||
WiFi.disconnect();
|
||||
}
|
||||
WiFi.scanNetworks(true, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
virtual void setStaticIp() = 0;
|
||||
|
||||
void setupIp(std::function<bool(IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2)> cb) {
|
||||
if(mConfig->sys.ip.ip[0] != 0) {
|
||||
IPAddress ip(mConfig->sys.ip.ip);
|
||||
|
@ -136,7 +139,7 @@ class AhoyNetwork {
|
|||
}
|
||||
}
|
||||
|
||||
void OnEvent(WiFiEvent_t event) {
|
||||
virtual void OnEvent(WiFiEvent_t event) {
|
||||
switch(event) {
|
||||
case SYSTEM_EVENT_STA_CONNECTED:
|
||||
[[fallthrough]];
|
||||
|
@ -231,6 +234,9 @@ class AhoyNetwork {
|
|||
uint32_t *mUtcTimestamp = nullptr;
|
||||
bool mConnected = false;
|
||||
bool mScanActive = false;
|
||||
#if !defined(ETHERNET)
|
||||
bool mWifiConnecting = false;
|
||||
#endif
|
||||
|
||||
OnNetworkCB mOnNetworkCB;
|
||||
OnTimeCB mOnTimeCB;
|
||||
|
|
|
@ -17,16 +17,15 @@ class AhoyWifi : public AhoyNetwork {
|
|||
void begin() override {
|
||||
mAp.enable();
|
||||
|
||||
// static IP
|
||||
setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
|
||||
return WiFi.config(ip, gateway, mask, dns1, dns2);
|
||||
});
|
||||
if(String(FB_WIFI_SSID) == mConfig->sys.stationSsid)
|
||||
return; // no station wifi defined
|
||||
|
||||
WiFi.setHostname(mConfig->sys.deviceName);
|
||||
#if !defined(AP_ONLY)
|
||||
WiFi.setScanMethod(WIFI_ALL_CHANNEL_SCAN);
|
||||
WiFi.setSortMethod(WIFI_CONNECT_AP_BY_SIGNAL);
|
||||
WiFi.begin(mConfig->sys.stationSsid, mConfig->sys.stationPwd, WIFI_ALL_CHANNEL_SCAN);
|
||||
mWifiConnecting = true;
|
||||
|
||||
DBGPRINT(F("connect to network '"));
|
||||
DBGPRINT(mConfig->sys.stationSsid);
|
||||
|
@ -34,24 +33,19 @@ class AhoyWifi : public AhoyNetwork {
|
|||
#endif
|
||||
}
|
||||
|
||||
void tickNetworkLoop() override {
|
||||
if(mAp.isEnabled())
|
||||
mAp.tickLoop();
|
||||
|
||||
switch(mStatus) {
|
||||
case NetworkState::DISCONNECTED:
|
||||
if(mConnected) {
|
||||
mConnected = false;
|
||||
mOnNetworkCB(false);
|
||||
MDNS.end();
|
||||
begin();
|
||||
void OnEvent(WiFiEvent_t event) override {
|
||||
switch(event) {
|
||||
case SYSTEM_EVENT_STA_CONNECTED:
|
||||
if(NetworkState::CONNECTED != mStatus) {
|
||||
mStatus = NetworkState::CONNECTED;
|
||||
mWifiConnecting = false;
|
||||
DPRINTLN(DBG_INFO, F("Network connected"));
|
||||
setStaticIp();
|
||||
}
|
||||
break;
|
||||
|
||||
case NetworkState::CONNECTED:
|
||||
break;
|
||||
|
||||
case NetworkState::GOT_IP:
|
||||
case SYSTEM_EVENT_STA_GOT_IP:
|
||||
mStatus = NetworkState::GOT_IP;
|
||||
if(mAp.isEnabled())
|
||||
mAp.disable();
|
||||
|
||||
|
@ -62,12 +56,42 @@ class AhoyWifi : public AhoyNetwork {
|
|||
mOnNetworkCB(true);
|
||||
}
|
||||
break;
|
||||
|
||||
case ARDUINO_EVENT_WIFI_STA_LOST_IP:
|
||||
[[fallthrough]];
|
||||
case ARDUINO_EVENT_WIFI_STA_STOP:
|
||||
[[fallthrough]];
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||
mStatus = NetworkState::DISCONNECTED;
|
||||
if(mConnected) {
|
||||
mConnected = false;
|
||||
mOnNetworkCB(false);
|
||||
MDNS.end();
|
||||
WiFi.disconnect();
|
||||
begin();
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void tickNetworkLoop() override {
|
||||
if(mAp.isEnabled())
|
||||
mAp.tickLoop();
|
||||
}
|
||||
|
||||
String getIp(void) override {
|
||||
return WiFi.localIP().toString();
|
||||
}
|
||||
|
||||
private:
|
||||
void setStaticIp() override {
|
||||
setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
|
||||
return WiFi.config(ip, gateway, mask, dns1, dns2);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
#endif /*ESP32 & !ETHERNET*/
|
||||
|
|
|
@ -18,11 +18,6 @@ class AhoyWifi : public AhoyNetwork {
|
|||
void begin() override {
|
||||
mAp.enable();
|
||||
|
||||
// static IP
|
||||
setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
|
||||
return WiFi.config(ip, gateway, mask, dns1, dns2);
|
||||
});
|
||||
|
||||
WiFi.setHostname(mConfig->sys.deviceName);
|
||||
mBSSIDList.clear();
|
||||
}
|
||||
|
@ -37,6 +32,7 @@ class AhoyWifi : public AhoyNetwork {
|
|||
case NetworkState::DISCONNECTED:
|
||||
if(mConnected) {
|
||||
mConnected = false;
|
||||
mWifiConnecting = false;
|
||||
mOnNetworkCB(false);
|
||||
mAp.enable();
|
||||
MDNS.end();
|
||||
|
@ -76,16 +72,19 @@ class AhoyWifi : public AhoyNetwork {
|
|||
}
|
||||
DBGPRINTLN("");
|
||||
WiFi.begin(mConfig->sys.stationSsid, mConfig->sys.stationPwd, 0, &bssid[0]);
|
||||
mWifiConnecting = true;
|
||||
break;
|
||||
|
||||
case NetworkState::CONNECTING:
|
||||
if (isTimeout(TIMEOUT)) {
|
||||
WiFi.disconnect();
|
||||
mWifiConnecting = false;
|
||||
mStatus = mBSSIDList.empty() ? NetworkState::DISCONNECTED : NetworkState::SCAN_READY;
|
||||
}
|
||||
break;
|
||||
|
||||
case NetworkState::CONNECTED:
|
||||
setStaticIp();
|
||||
break;
|
||||
|
||||
case NetworkState::GOT_IP:
|
||||
|
@ -117,6 +116,12 @@ class AhoyWifi : public AhoyNetwork {
|
|||
}
|
||||
|
||||
private:
|
||||
void setStaticIp() override {
|
||||
setupIp([this](IPAddress ip, IPAddress gateway, IPAddress mask, IPAddress dns1, IPAddress dns2) -> bool {
|
||||
return WiFi.config(ip, gateway, mask, dns1, dns2);
|
||||
});
|
||||
}
|
||||
|
||||
bool getBSSIDs() {
|
||||
bool result = false;
|
||||
int n = WiFi.scanComplete();
|
||||
|
|
|
@ -55,7 +55,6 @@ class epdHal: public GxEPD2_HalInterface, public SpiPatcherHandle {
|
|||
gpio_set_level(mPinClk, 0);
|
||||
|
||||
gpio_reset_pin(mPinCs);
|
||||
request_spi();
|
||||
spi_device_interface_config_t devcfg = {
|
||||
.command_bits = 0,
|
||||
.address_bits = 0,
|
||||
|
@ -73,7 +72,6 @@ class epdHal: public GxEPD2_HalInterface, public SpiPatcherHandle {
|
|||
.post_cb = nullptr
|
||||
};
|
||||
mSpiPatcher->addDevice(mHostDevice, &devcfg, &spi);
|
||||
release_spi();
|
||||
|
||||
if(GPIO_NUM_NC != mPinRst) {
|
||||
gpio_reset_pin(mPinRst);
|
||||
|
|
|
@ -22,11 +22,19 @@ class SpiPatcher {
|
|||
// Use binary semaphore instead of mutex for performance reasons
|
||||
mutex = xSemaphoreCreateBinaryStatic(&mutex_buffer);
|
||||
xSemaphoreGive(mutex);
|
||||
mDev = dev;
|
||||
mBusState = ESP_FAIL;
|
||||
}
|
||||
|
||||
spi_bus_config_t buscfg = {
|
||||
.mosi_io_num = -1,
|
||||
.miso_io_num = -1,
|
||||
.sclk_io_num = -1,
|
||||
public:
|
||||
SpiPatcher(const SpiPatcher &other) = delete;
|
||||
void operator=(const SpiPatcher &) = delete;
|
||||
|
||||
esp_err_t initBus(int mosi = -1, int miso = -1, int sclk = -1, spi_common_dma_t dmaType = SPI_DMA_DISABLED) {
|
||||
mBusConfig = spi_bus_config_t {
|
||||
.mosi_io_num = mosi,
|
||||
.miso_io_num = miso,
|
||||
.sclk_io_num = sclk,
|
||||
.quadwp_io_num = -1,
|
||||
.quadhd_io_num = -1,
|
||||
.data4_io_num = -1,
|
||||
|
@ -37,21 +45,25 @@ class SpiPatcher {
|
|||
.flags = 0,
|
||||
.intr_flags = 0
|
||||
};
|
||||
ESP_ERROR_CHECK(spi_bus_initialize(dev, &buscfg, SPI_DMA_DISABLED));
|
||||
ESP_ERROR_CHECK((mBusState = spi_bus_initialize(mDev, &mBusConfig, dmaType)));
|
||||
|
||||
return mBusState;
|
||||
}
|
||||
|
||||
public:
|
||||
SpiPatcher(const SpiPatcher &other) = delete;
|
||||
void operator=(const SpiPatcher &) = delete;
|
||||
|
||||
static SpiPatcher* getInstance(spi_host_device_t dev) {
|
||||
static SpiPatcher* getInstance(spi_host_device_t dev, bool initialize = true) {
|
||||
if(SPI2_HOST == dev) {
|
||||
if(nullptr == InstanceHost2)
|
||||
if(nullptr == InstanceHost2) {
|
||||
InstanceHost2 = new SpiPatcher(dev);
|
||||
if(initialize)
|
||||
InstanceHost2->initBus();
|
||||
}
|
||||
return InstanceHost2;
|
||||
} else { // SPI3_HOST
|
||||
if(nullptr == InstanceHost3)
|
||||
if(nullptr == InstanceHost3) {
|
||||
InstanceHost3 = new SpiPatcher(dev);
|
||||
if(initialize)
|
||||
InstanceHost3->initBus();
|
||||
}
|
||||
return InstanceHost3;
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +71,7 @@ class SpiPatcher {
|
|||
~SpiPatcher() { vSemaphoreDelete(mutex); }
|
||||
|
||||
inline void addDevice(spi_host_device_t host_id, const spi_device_interface_config_t *dev_config, spi_device_handle_t *handle) {
|
||||
assert(mBusState == ESP_OK);
|
||||
if(SPI2_HOST == host_id)
|
||||
mHost2Cnt++;
|
||||
if(SPI3_HOST == host_id)
|
||||
|
@ -71,6 +84,7 @@ class SpiPatcher {
|
|||
}
|
||||
|
||||
inline void request(SpiPatcherHandle* handle) {
|
||||
assert(mBusState == ESP_OK);
|
||||
xSemaphoreTake(mutex, portMAX_DELAY);
|
||||
|
||||
if (mCurHandle != handle) {
|
||||
|
@ -85,6 +99,7 @@ class SpiPatcher {
|
|||
}
|
||||
|
||||
inline void release() {
|
||||
assert(mBusState == ESP_OK);
|
||||
xSemaphoreGive(mutex);
|
||||
}
|
||||
|
||||
|
@ -97,6 +112,9 @@ class SpiPatcher {
|
|||
SemaphoreHandle_t mutex;
|
||||
StaticSemaphore_t mutex_buffer;
|
||||
uint8_t mHost2Cnt = 0, mHost3Cnt = 0;
|
||||
spi_host_device_t mDev = SPI3_HOST;
|
||||
esp_err_t mBusState = ESP_FAIL;
|
||||
spi_bus_config_t mBusConfig;
|
||||
};
|
||||
|
||||
#endif /*ESP32*/
|
||||
|
|
|
@ -232,7 +232,7 @@
|
|||
ml("div", {class: "row my-4"}, ml("div", {class: "col a-r"}, ml("input", {type: "button", class:"btn hide", id: "btn", value: "{#BTN_FINISH}", onclick: () => {redirect()}}, null))),
|
||||
ml("div", {class: "row mt-5"}, ml("div", {class: "col a-c"}, ml("a", {onclick: () => {redirect()}}, "{#STOP_WIZARD}")))
|
||||
)
|
||||
v = setInterval(() => {getAjax('/api/setup/getip', printIp)}, 500);
|
||||
v = setInterval(() => {getAjax('/api/setup/getip', printIp)}, 1000);
|
||||
}
|
||||
|
||||
function redirect() {
|
||||
|
@ -240,7 +240,7 @@
|
|||
}
|
||||
|
||||
function printIp(obj) {
|
||||
if("0.0.0.0" != obj["ip"]) {
|
||||
if("0.0.0.0" != obj.ip) {
|
||||
clearInterval(v)
|
||||
setHide("btn", false)
|
||||
document.getElementById("state").innerHTML = "{#NETWORK_SUCCESS}" + obj.ip
|
||||
|
@ -272,12 +272,12 @@
|
|||
getAjax("/api/setup", ((o) => c.append(step1(o.eth))));
|
||||
/*ELSE*/
|
||||
function nets(obj) {
|
||||
clearInterval(v)
|
||||
v = setInterval(() => {getAjax('/api/setup/networks', nets)}, 4000)
|
||||
|
||||
if(!obj.success)
|
||||
return;
|
||||
|
||||
clearInterval(v)
|
||||
v = setInterval(() => {getAjax('/api/setup/networks', nets)}, 5000)
|
||||
|
||||
var e = document.getElementById("net");
|
||||
if(obj.networks.length > 0) {
|
||||
var a = []
|
||||
|
@ -289,7 +289,8 @@
|
|||
e.replaceChildren(...a)
|
||||
}
|
||||
|
||||
redirIp = obj.ip + "/index"
|
||||
if("0.0.0.0" != obj.ip)
|
||||
redirIp = "http://" + obj.ip + "/index"
|
||||
}
|
||||
|
||||
c.append(step1())
|
||||
|
|
Loading…
Add table
Reference in a new issue