mark: wip work to move stuff around

This commit is contained in:
KonradIT
2026-04-06 19:05:34 +02:00
parent f6011579ee
commit db38367705
21 changed files with 734 additions and 710 deletions
-110
View File
@@ -1,110 +0,0 @@
#pragma once
#ifdef WIFI_SCANNING_ENABLED
#include "WiFi.h"
#endif
#ifdef BT_SCANNING_ENABLED
#include <BLEAdvertisedDevice.h>
#include <BLEDevice.h>
#include <BLEScan.h>
#include <BLEUtils.h>
#endif
#include "DFRobot_OSD.h"
void setOSD() {}
// TODO: Make Async Scan
// https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/scan-examples.html#async-scan
void scanWiFi(DFRobot_OSD osd)
{
osd.clear();
osd.displayString(14, 2, "Scanning WiFi..");
int n = WiFi.scanNetworks();
#ifdef PRINT_DEBUG
Serial.println("scan done");
if (n == 0)
{
Serial.println("no networks found");
}
#endif
if (n > 0)
{
#ifdef PRINT_DEBUG
Serial.print(n);
Serial.println(" networks found");
#endif
for (int i = 0; i < n; ++i)
{
// Print SSID and RSSI for each network found
#ifdef PRINT_DEBUG
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i));
Serial.print(" (");
Serial.print(WiFi.RSSI(i));
Serial.print(")");
Serial.println((WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*");
#endif
osd.displayString(i + 1, 1,
"WF:" + String((WiFi.SSID(i) + ":" + WiFi.RSSI(i))));
}
}
osd.displayChar(14, 1, 0x10f);
}
//**********************
// BLE devices scan.
//***********************
// TODO: Make Async Scan
// https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLETests/SampleAsyncScan.cpp
void scanBT(DFRobot_OSD osd)
{
osd.clear();
osd.displayString(14, 2, "Scanning BT...");
cycleCnt++;
BLEDevice::init("");
BLEScan *pBLEScan = BLEDevice::getScan();
// active scan uses more power, but get results faster
pBLEScan->setActiveScan(true);
// TODO: adjust interval and window
pBLEScan->setInterval(0x50);
pBLEScan->setWindow(0x30);
#ifdef SERIAL_PRINT
Serial.printf("Start BLE scan for %d seconds...\n", BT_SCAN_TIME);
#endif
BLEScanResults foundDevices = pBLEScan->start(BT_SCAN_TIME);
int count = foundDevices.getCount();
#ifdef PRINT_DEBUG
Serial.printf("Found devices: %d \n", count);
#endif
present = false;
for (int i = 0; i < count; i++)
{
BLEAdvertisedDevice device = foundDevices.getDevice(i);
String currDevAddr = device.getAddress().toString().c_str();
String deviceName;
if (device.haveName())
{
deviceName = device.getName().c_str();
}
else
{
deviceName = currDevAddr;
}
#ifdef PRINT_DEBUG
Serial.printf("Found device #%s/%s with RSSI: %d \n", currDevAddr, deviceName,
device.getRSSI());
#endif
osd.displayString(i + 1, 1,
"BT:" + deviceName + ":" + String(device.getRSSI()) + " \n");
}
#ifdef PRINT_DEBUG
Serial.println("Scan done!");
Serial.printf("Cycle counter: %d, Free heap: %d \n", cycleCnt, ESP.getFreeHeap());
#endif
osd.displayChar(14, 1, 0x10f);
scanFinished = true;
}
-55
View File
@@ -1,55 +0,0 @@
#include "FS.h"
#include <LittleFS.h>
// Initialize LittleFS
void initLittleFS()
{
if (!LittleFS.begin(true))
{
Serial.println("An error has occurred while mounting LittleFS");
}
Serial.println("LittleFS mounted successfully");
}
String readFile(fs::FS &fs, const char *path)
{
Serial.printf("Reading file: %s\r\n", path);
File file = fs.open(path);
if (!file || file.isDirectory())
{
Serial.println("- failed to open file for reading");
return String("");
}
String content;
Serial.println("- read from file:");
while (file.available())
{
content = file.readStringUntil('\n');
}
file.close();
return content;
}
void writeFile(fs::FS &fs, const char *path, const char *message)
{
Serial.printf("Writing file: %s\r\n", path);
Serial.printf("Content: %s\r\n", message);
File file = fs.open(path, FILE_WRITE);
if (!file)
{
Serial.println("- failed to open file for writing");
return;
}
if (file.print(message))
{
Serial.println("- file written");
delay(500);
}
else
{
Serial.println("- write failed");
}
file.close();
}
-207
View File
@@ -1,207 +0,0 @@
// Search for parameter in HTTP POST request
const String SSID = "ssid";
const String PASS = "pass";
const String IP = "ip";
const String GATEWAY = "gateway";
const String FSTART = "fstart";
const String FEND = "fend";
// File paths to save input values permanently
// const char *ssidPath = "/ssid.txt";
// Variables to save values from HTML form
String ssid = "LoraSA", pass = "1234567890", ip = "192.168.1.100",
gateway = "192.168.1.1", fstart = "", fend = "", smpls = "";
#ifdef WEB_SERVER
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <LittleFS.h>
#include <WiFi.h>
// Create AsyncWebServer object on port 80
AsyncWebServer server(80);
IPAddress localIP;
// Set your Gateway IP address
IPAddress localGateway;
IPAddress subnet(255, 255, 0, 0);
// Timer variables
unsigned long previousMillis = 0;
const long interval = 10000; // interval to wait for Wi-Fi connection (milliseconds)
// Initialize WiFi
bool initWiFi()
{
Serial.println("SSID:" + ssid);
Serial.println("PSWD:" + pass);
Serial.println("IP:" + ip);
Serial.println("SUB:" + subnet);
Serial.println("GATAWAY:" + gateway);
if (ssid == "" || ip == "")
{
Serial.println("Undefined SSID or IP address.");
return false;
}
WiFi.mode(WIFI_STA);
localIP.fromString(ip.c_str());
localGateway.fromString(gateway.c_str());
if (!WiFi.config(localIP, localGateway, subnet))
{
Serial.println("STA Failed to configure");
return false;
}
WiFi.begin(ssid.c_str(), pass.c_str());
Serial.println("Connecting to WiFi...");
unsigned long currentMillis = millis();
previousMillis = currentMillis;
while (WiFi.status() != WL_CONNECTED)
{
currentMillis = millis();
if (currentMillis - previousMillis >= interval)
{
Serial.println("Failed to connect.");
return false;
}
}
Serial.println(WiFi.localIP());
return true;
}
void serverServer()
{
// Route for root / web page
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
{ request->send(LittleFS, "/index.html", "text/html"); });
server.serveStatic("/", LittleFS, "/");
server.on("/", HTTP_POST,
[](AsyncWebServerRequest *request)
{
int params = request->params();
for (int i = 0; i < params; i++)
{
Serial.println("Parameter " + String(i) + ": " +
request->getParam(i)->value());
}
Serial.println(request->params());
String p;
if (request->hasParam(IP, true))
{
p = request->getParam(IP, true)->value();
writeParameterToParameterFile(IP, p);
}
if (request->hasParam(IP, true))
{
p = request->getParam(IP, true)->value();
writeParameterToParameterFile(IP, p);
}
if (request->hasParam(IP, true))
{
p = request->getParam(IP, true)->value();
writeParameterToParameterFile(IP, p);
}
if (request->hasParam(GATEWAY, true))
{
p = request->getParam(GATEWAY, true)->value();
writeParameterToParameterFile(GATEWAY, p);
}
if (request->hasParam(FSTART, true))
{
p = request->getParam(FSTART, true)->value();
writeParameterToParameterFile(FSTART, p);
}
if (request->hasParam(FEND, true))
{
p = request->getParam(FEND, true)->value();
writeParameterToParameterFile(FEND, p);
}
if (request->hasParam("samples", true))
{
p = request->getParam("samples", true)->value();
writeParameterToParameterFile("samples", p);
}
request->send(200, "text/plain",
"Done. ESP will restart, connect to your router and "
"go to IP address: " +
ip);
delay(3000);
ESP.restart();
});
/* // Route to set GPIO state to HIGH
server.on("/on", HTTP_GET,
[](AsyncWebServerRequest *request)
{
digitalWrite(ledPin, HIGH);
request->send(LittleFS, "/index.html", "text/html", false,
processor);
});
// Route to set GPIO state to LOW
server.on("/off", HTTP_GET,
[](AsyncWebServerRequest *request)
{
digitalWrite(ledPin, LOW);
request->send(LittleFS, "/index.html", "text/html", false,
processor);
});*/
server.begin();
}
void serverStart()
{
if (initWiFi())
{
Serial.println("Setting Secure WIFI (Access Point)");
serverServer();
}
else
{
// Connect to Wi-Fi network with default SSID and password
Serial.println("Setting AP (Access Point)");
// NULL sets an open Access Point
WiFi.softAP("LoraSA", NULL);
IPAddress IP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(IP);
serverServer();
}
}
#endif
void writeParameterToFile(String value, String file)
{
// Write file to save value
writeFile(LittleFS, file.c_str(), value.c_str());
}
void writeParameterToParameterFile(String param, String value)
{
String file = String("/" + param + ".txt");
// Write file to save value
writeParameterToFile(value, file.c_str());
}
String readParameterFromParameterFile(String param)
{
String file = String("/" + param + ".txt");
return readFile(LittleFS, file.c_str());
}
-63
View File
@@ -1,63 +0,0 @@
// Joystick integration
constexpr int JOY_X_PIN = 19;
int cursor_x_position = 0;
// Not integrated yet constexpr int JOY_Y_PIN = N/A;
constexpr int JOY_BTN_PIN = 46;
bool joy_btn_clicked = false;
// Joystick integration
bool joy_btn_click()
{
joy_btn_clicked = true;
// is the output from the pushbutton inside the joystick. Its normally open. If we
// use a pull-up resistor in this pin, the SW pin will be HIGH
// when it is not pressed, and LOW when Pressed.
return digitalRead(JOY_BTN_PIN) == HIGH ? false : true;
}
int joyXMid = 0;
int cal_X = 0, cal_Y = 0;
void calibrate_joy()
{
for (int i = 0; i < 100; i++)
{
cal_X += analogRead(JOY_X_PIN);
}
// calibrate center
joyXMid = cal_X / 100;
}
int MID = 100; // 10 mid point delta arduino, use 4 for attiny
int get_joy_x(bool logical = false)
{
int joyX = analogRead(JOY_X_PIN);
/*
Serial.print("Calibrated_X_Voltage = ");
Serial.print(joyXMid);
Serial.print("X_Voltage = ");
Serial.print(joyX);
Serial.print("\t");
*/
if (logical)
{
// 4095
if (joyX < joyXMid - MID)
{
return -1;
}
// 0-5
else if (joyX > joyXMid + MID)
{
return 1;
}
else
{
return 0;
}
}
return joyX;
}
+17
View File
@@ -0,0 +1,17 @@
#pragma once
#include <Arduino.h>
#include <radio.h>
extern bool radioIsScan;
extern RadioModule *radio2;
int16_t initForScan(float freq);
bool setFrequency(float curr_freq);
void init_radio();
float getRSSI(void *param);
float getCAD(void *param);
#ifdef USING_LR1121
void setLRFreq(float freq);
#endif