mirror of
https://github.com/lumapu/ahoy.git
synced 2025-07-23 03:07:12 +02:00
* made ethernet pinout configurable
* combined common network functions into class * seperated wifi station from AP mode
This commit is contained in:
parent
4fc61dc01f
commit
a44a5833ca
12 changed files with 540 additions and 25 deletions
|
@ -37,14 +37,19 @@
|
|||
|
||||
#define WEB_SERIAL_BUF_SIZE 2048
|
||||
|
||||
const char* const pinArgNames[] = {"pinCs", "pinCe", "pinIrq", "pinSclk", "pinMosi", "pinMiso", "pinLed0", "pinLed1", "pinLed2", "pinLedHighActive", "pinLedLum", "pinCmtSclk", "pinSdio", "pinCsb", "pinFcsb", "pinGpio3"};
|
||||
const char* const pinArgNames[] = {
|
||||
"pinCs", "pinCe", "pinIrq", "pinSclk", "pinMosi", "pinMiso", "pinLed0",
|
||||
"pinLed1", "pinLed2", "pinLedHighActive", "pinLedLum", "pinCmtSclk",
|
||||
"pinSdio", "pinCsb", "pinFcsb", "pinGpio3"
|
||||
#if defined (ETHERNET)
|
||||
, "ethCs", "ethSclk", "ethMiso", "ethMosi", "ethIrq", "ethRst"
|
||||
#endif
|
||||
};
|
||||
|
||||
template <class HMSYSTEM>
|
||||
class Web {
|
||||
public:
|
||||
Web(void) : mWeb(80), mEvts("/events") {
|
||||
memset(mSerialBuf, 0, WEB_SERIAL_BUF_SIZE);
|
||||
}
|
||||
Web(void) : mWeb(80), mEvts("/events") {}
|
||||
|
||||
void setup(IApp *app, HMSYSTEM *sys, settings_t *config) {
|
||||
mApp = app;
|
||||
|
@ -101,11 +106,17 @@ class Web {
|
|||
|
||||
void tickSecond() {
|
||||
if (mSerialClientConnnected) {
|
||||
if(nullptr == mSerialBuf)
|
||||
return;
|
||||
|
||||
if (mSerialBufFill > 0) {
|
||||
mEvts.send(mSerialBuf, "serial", millis());
|
||||
memset(mSerialBuf, 0, WEB_SERIAL_BUF_SIZE);
|
||||
mSerialBufFill = 0;
|
||||
}
|
||||
} else if(nullptr != mSerialBuf) {
|
||||
delete[] mSerialBuf;
|
||||
mSerialBuf = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,6 +188,9 @@ class Web {
|
|||
if (!mSerialClientConnnected)
|
||||
return;
|
||||
|
||||
if(nullptr == mSerialBuf)
|
||||
return;
|
||||
|
||||
msg.replace("\r\n", "<rn>");
|
||||
if (mSerialAddTime) {
|
||||
if ((13 + mSerialBufFill) < WEB_SERIAL_BUF_SIZE) {
|
||||
|
@ -293,6 +307,10 @@ class Web {
|
|||
void onConnect(AsyncEventSourceClient *client) {
|
||||
DPRINTLN(DBG_VERBOSE, "onConnect");
|
||||
|
||||
if(nullptr == mSerialBuf) {
|
||||
mSerialBuf = new char[WEB_SERIAL_BUF_SIZE];
|
||||
memset(mSerialBuf, 0, WEB_SERIAL_BUF_SIZE);
|
||||
}
|
||||
mSerialClientConnnected = true;
|
||||
|
||||
if (client->lastId())
|
||||
|
@ -482,7 +500,12 @@ class Web {
|
|||
|
||||
|
||||
// pinout
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
#if defined(ETHERNET)
|
||||
for (uint8_t i = 0; i < 22; i++)
|
||||
#else
|
||||
for (uint8_t i = 0; i < 16; i++)
|
||||
#endif
|
||||
{
|
||||
uint8_t pin = request->arg(String(pinArgNames[i])).toInt();
|
||||
switch(i) {
|
||||
case 0: mConfig->nrf.pinCs = ((pin != 0xff) ? pin : DEF_NRF_CS_PIN); break;
|
||||
|
@ -501,11 +524,23 @@ class Web {
|
|||
case 13: mConfig->cmt.pinCsb = pin; break;
|
||||
case 14: mConfig->cmt.pinFcsb = pin; break;
|
||||
case 15: mConfig->cmt.pinIrq = pin; break;
|
||||
|
||||
#if defined(ETHERNET)
|
||||
case 16: mConfig->sys.eth.pinCs = pin; break;
|
||||
case 17: mConfig->sys.eth.pinSclk = pin; break;
|
||||
case 18: mConfig->sys.eth.pinMiso = pin; break;
|
||||
case 19: mConfig->sys.eth.pinMosi = pin; break;
|
||||
case 20: mConfig->sys.eth.pinIrq = pin; break;
|
||||
case 21: mConfig->sys.eth.pinRst = pin; break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
mConfig->nrf.enabled = (request->arg("nrfEnable") == "on");
|
||||
mConfig->cmt.enabled = (request->arg("cmtEnable") == "on");
|
||||
#if defined(ETHERNET)
|
||||
mConfig->sys.eth.enabled = (request->arg("ethEn") == "on");
|
||||
#endif
|
||||
|
||||
// ntp
|
||||
if (request->arg("ntpAddr") != "") {
|
||||
|
@ -906,7 +941,7 @@ class Web {
|
|||
settings_t *mConfig = nullptr;
|
||||
|
||||
bool mSerialAddTime = true;
|
||||
char mSerialBuf[WEB_SERIAL_BUF_SIZE];
|
||||
char *mSerialBuf = nullptr;
|
||||
uint16_t mSerialBufFill = 0;
|
||||
bool mSerialClientConnnected = false;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue