Skip to content

Commit

Permalink
1.40
Browse files Browse the repository at this point in the history
  • Loading branch information
klausahrenberg committed Jan 3, 2024
1 parent 70de5bb commit 4ec18a3
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 22 deletions.
45 changes: 27 additions & 18 deletions src/WHtmlPages.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@ const char* HTTP_FALSE = "false";
const char* VALUE_GET = "get";

const static char HTTP_TR[] PROGMEM = R"=====(<tr>)=====";
void tr(Print* page) { page->print(FPSTR(HTTP_TR)); }
const static char HTTP_TRE[] PROGMEM = R"=====(</tr>)=====";
void trEnd(Print* page) { page->print(FPSTR(HTTP_TRE)); }
const static char HTTP_TH[] PROGMEM = R"=====(<th>)=====";
void th(Print* page) { page->print(FPSTR(HTTP_TH)); }
const static char HTTP_TH[] PROGMEM = R"=====(<th colspan='%d'>)=====";
const static char HTTP_THE[] PROGMEM = R"=====(</th>)=====";
void thEnd(Print* page) { page->print(FPSTR(HTTP_THE)); }
const static char HTTP_TD[] PROGMEM = R"=====(<td>)=====";
void td(Print* page) { page->print(FPSTR(HTTP_TD)); }
const static char HTTP_TDE[] PROGMEM = R"=====(</td>)=====";
void tdEnd(Print* page) { page->print(FPSTR(HTTP_TDE)); }

const static char HTTP_TABLE[] PROGMEM = R"=====(<table class='%s'>)=====";
const static char HTTP_TABLE_END[] PROGMEM = R"=====(</table>)=====";

const static char HTTP_HEAD_BEGIN[] PROGMEM = R"=====(
<!DOCTYPE html>
Expand Down Expand Up @@ -228,19 +225,15 @@ const static char HTTP_PASSWORD_FIELD[] PROGMEM = R"=====(
)=====";

const static char HTTP_CHECKBOX[] PROGMEM = R"=====(
<div>
<label>
<input type='checkbox' name='%s' value='true' %s>%s
</label>
</div>
<label>
<input type='checkbox' name='%s' value='true' %s>%s
</label>
)=====";

const static char HTTP_CHECKBOX_OPTION[] PROGMEM = R"=====(
<div>
<label>
<input type='checkbox' id='%s' name='%s' value='true' %s onclick='%s'>%s
</label>
</div>
<label>
<input type='checkbox' id='%s' name='%s' value='true' %s onclick='%s'>%s
</label>
)=====";

const static char HTTP_RADIO_OPTION[] PROGMEM = R"=====(
Expand Down Expand Up @@ -283,9 +276,25 @@ class WHtml {
}

static void textField(Print* page, const char* fieldName, const char* title, byte maxLength, const char* value) {
page->printf(HTTP_TEXT_FIELD, title, fieldName, String(maxLength).c_str(), value);
page->printf(HTTP_TEXT_FIELD, title, fieldName, String(maxLength).c_str(), value);
}

static void tr(Print* page) { page->print(FPSTR(HTTP_TR)); }

static void trEnd(Print* page) { page->print(FPSTR(HTTP_TRE)); }

static void th(Print* page, byte colspan = 1) { page->printf(HTTP_TH, colspan); }

static void thEnd(Print* page) { page->print(FPSTR(HTTP_THE)); }

static void td(Print* page) { page->print(FPSTR(HTTP_TD)); }

static void tdEnd(Print* page) { page->print(FPSTR(HTTP_TDE)); }

static void table(Print* page, const char* id) { page->printf(HTTP_TABLE, id); }

static void tableEnd(Print* page) { page->print(FPSTR(HTTP_TABLE_END)); }

};

#endif
7 changes: 5 additions & 2 deletions src/WNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,12 @@ class WNetwork {
// after first startup
WiFi.disconnect();
WiFi.hostname(_hostname);
#elif ESP32
WiFi.mode(WIFI_STA);
#elif ESP32
//Workaround: WiFi.setHostName now only works if: - You call it before calling WiFi.mode(WIFI_STA)
//and ensure that the mode is not WIFI_STA already before calling WiFi.setHostName (by first calling WiFi.mode(WIFI_MODE_NULL)
WiFi.mode(WIFI_MODE_NULL);
WiFi.setHostname(_hostname);
WiFi.mode(WIFI_STA);
#endif
WiFi.begin(getSsid(), getPassword());

Expand Down
4 changes: 2 additions & 2 deletions src/WProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class WProperty {
free(_value.asByteArray);
}
_value.asByteArray = (byte*) malloc(length + 1);
_value.asByteArray[0] = length;
_value.asByteArray[0] = length;
for (int i = 0; i < length; i++) {
changed = ((changed) || (_value.asByteArray[i] != newValue[i]));
_value.asByteArray[i + 1] = newValue[i];
Expand Down Expand Up @@ -379,7 +379,7 @@ class WProperty {
_notify();
}
return changed;
}
}

bool byteArrayBitValue(byte byteIndex, byte bitIndex) {
return bitRead(byteArrayValue(byteIndex), bitIndex);
Expand Down
6 changes: 6 additions & 0 deletions src/WProps.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class WProps {
return new WProperty(id, title, BYTE, "");
}

static WProperty* createByteArrayProperty(const char* id, const char* title, byte arrayLength, const byte* values) {
WProperty* result = new WProperty(id, title, BYTE_ARRAY, "");
result->asByteArray(arrayLength, values);
return result;
}

static WProperty* createDoubleProperty(const char* id, const char* title) {
return new WProperty(id, title, DOUBLE, "");
}
Expand Down

0 comments on commit 4ec18a3

Please sign in to comment.