fix aligning U8G2 fonts / improv protocol fix

This commit is contained in:
Nic Limper
2023-08-05 22:05:33 +02:00
parent 84bfb18261
commit 66cc62339f
4 changed files with 35 additions and 67 deletions

View File

@@ -34,8 +34,6 @@ class WifiManager {
const int SERIAL_BUFFER_SIZE = 64;
char serialBuffer[64];
int serialIndex = 0;
uint8_t x_buffer[16];
uint8_t x_position = 0;
String WiFi_SSID();
String WiFi_psk();
@@ -58,6 +56,8 @@ class WifiManager {
#endif
extern WifiManager wm;
// **** Improv Wi-Fi ****
// https://www.improv-wifi.com/
// https://github.com/jnthas/improv-wifi-demo

View File

@@ -357,6 +357,12 @@ void drawString(TFT_eSprite &spr, String content, int16_t posx, int16_t posy, St
setU8G2Font(font, u8f);
u8f.setForegroundColor(color);
u8f.setBackgroundColor(PAL_WHITE);
if (align == TC_DATUM) {
posx -= u8f.getUTF8Width(content.c_str()) / 2;
}
if (align == TR_DATUM) {
posx -= u8f.getUTF8Width(content.c_str());
}
u8f.setCursor(posx, posy);
u8f.print(content);

View File

@@ -42,7 +42,6 @@ void timeTask(void* parameter) {
if (now % 5 == 0 || apInfo.state != AP_STATE_ONLINE || config.runStatus != RUNSTATUS_RUN) wsSendSysteminfo();
if (now % 300 == 6 && config.runStatus != RUNSTATUS_STOP) saveDB("/current/tagDB.json");
if (apInfo.state == AP_STATE_ONLINE) contentRunner();
vTaskDelay(1000 / portTICK_PERIOD_MS);
@@ -50,6 +49,9 @@ void timeTask(void* parameter) {
}
void setup() {
Serial.begin(115200);
Serial.print(">\n");
xTaskCreate(ledTask, "ledhandler", 2000, NULL, 2, NULL);
vTaskDelay(10 / portTICK_PERIOD_MS);
@@ -70,9 +72,6 @@ void setup() {
#endif
#endif
Serial.begin(115200);
Serial.print(">\n");
// pinTest();
#ifdef BOARD_HAS_PSRAM
if (!psramInit()) {
@@ -134,7 +133,7 @@ void setup() {
loadDB("/current/tagDB.json");
// tagDBOwner = xSemaphoreCreateMutex();
xTaskCreate(APTask, "AP Process", 6000, NULL, 2, NULL);
xTaskCreate(networkProcess, "Wifi", 2000, NULL, configMAX_PRIORITIES - 10, NULL);
xTaskCreate(networkProcess, "Wifi", 6000, NULL, configMAX_PRIORITIES - 10, NULL);
vTaskDelay(10 / portTICK_PERIOD_MS);
config.runStatus = RUNSTATUS_INIT;

View File

@@ -4,7 +4,13 @@
#include <WiFi.h>
#include <esp_wifi.h>
#include "newproto.h"
#include "tag_db.h"
#include "web.h"
uint8_t WifiManager::apClients = 0;
uint8_t x_buffer[100];
uint8_t x_position = 0;
WifiManager::WifiManager() {
_reconnectIntervalCheck = 5000;
@@ -160,52 +166,12 @@ void WifiManager::pollSerial() {
if (parse_improv_serial_byte(x_position, receivedChar, x_buffer, onCommandCallback, onErrorCallback)) {
x_buffer[x_position++] = receivedChar;
if (x_position > 100) {
x_position = 0;
Serial.println("buffer full!");
}
} else {
x_position = 0;
if (receivedChar == 27) {
memset(serialBuffer, 0, sizeof(serialBuffer));
serialIndex = 0;
Serial.println();
continue;
}
if (receivedChar == 8) {
if (serialIndex > 0) {
serialIndex--;
serialBuffer[serialIndex] = '\0';
Serial.print("\r");
Serial.print(serialBuffer);
}
continue;
}
if (receivedChar == '\r') {
continue;
}
if (receivedChar == '\n') {
serialBuffer[serialIndex] = '\0';
String command = String(serialBuffer);
if (command.startsWith("ssid ")) {
_ssid = command.substring(5);
Serial.println("\rSSID set to: " + _ssid);
} else if (command.startsWith("pass ")) {
_pass = command.substring(5);
Serial.println("\rPassword set to: " + _pass);
} else if (command.startsWith("connect")) {
connectToWifi(_ssid, _pass, true);
}
memset(serialBuffer, 0, sizeof(serialBuffer));
serialIndex = 0;
} else {
if (serialIndex < SERIAL_BUFFER_SIZE - 1) {
serialBuffer[serialIndex] = receivedChar;
serialIndex++;
Serial.print("\r");
Serial.print(serialBuffer);
}
}
}
}
}
@@ -250,21 +216,6 @@ void WifiManager::WiFiEvent(WiFiEvent_t event) {
Serial.println("Assigned IP address to client");
break;
case ARDUINO_EVENT_ETH_START:
Serial.println("Ethernet started");
break;
case ARDUINO_EVENT_ETH_STOP:
Serial.println("Ethernet stopped");
break;
case ARDUINO_EVENT_ETH_CONNECTED:
Serial.println("Ethernet connected");
break;
case ARDUINO_EVENT_ETH_DISCONNECTED:
Serial.println("Ethernet disconnected");
break;
case ARDUINO_EVENT_ETH_GOT_IP:
Serial.println("Obtained IP address");
break;
default:
Serial.println();
break;
@@ -272,6 +223,7 @@ void WifiManager::WiFiEvent(WiFiEvent_t event) {
}
// *** Improv
// https : // github.com/jnthas/improv-wifi-demo
#define STR_IMPL(x) #x
#define STR(x) STR_IMPL(x)
@@ -314,8 +266,19 @@ bool onCommandCallback(improv::ImprovCommand cmd) {
set_state(improv::STATE_PROVISIONING);
WifiManager wm;
ws.enable(false);
refreshAllPending();
saveDB("/current/tagDB.json");
ws.closeAll();
delay(100);
if (wm.connectToWifi(String(cmd.ssid.c_str()), String(cmd.password.c_str()), true)) {
Preferences preferences;
preferences.begin("wifi", false);
preferences.putString("ssid", cmd.ssid.c_str());
preferences.putString("pw", cmd.password.c_str());
preferences.end();
ws.enable(true);
set_state(improv::STATE_PROVISIONED);
std::vector<uint8_t> data = improv::build_rpc_response(improv::WIFI_SETTINGS, getLocalUrl(), false);
send_response(data);