mirror of
https://github.com/SasaKaranovic/winfidel-sensor.git
synced 2026-07-08 17:52:35 +02:00
Adding explicit config option to enable/disable WiFi, USB-to-Serial and Serial printing. Printing measurements to Serial is now always on by default.
This commit is contained in:
+699
-698
File diff suppressed because it is too large
Load Diff
@@ -4,6 +4,17 @@
|
||||
#define MDNS_NAME "winfidel"
|
||||
#define WIFI_HOSTNAME "WInFiDEL by SK"
|
||||
|
||||
#ifndef CONFIG_PRINT_MEASUREMENTS_USB_CDC
|
||||
#define CONFIG_PRINT_MEASUREMENTS_USB_CDC 1 // Set to `1` if we want serial (USB-to-Serial) printout for every measurement.
|
||||
#endif // CONFIG_PRINT_MEASUREMENTS_USB_CDC
|
||||
|
||||
#ifndef CONFIG_PRINT_MEASUREMENTS_UART_GPIO
|
||||
#define CONFIG_PRINT_MEASUREMENTS_UART_GPIO 1 // Set to `1` if we want serial (TX GPIO) printout for every measurement.
|
||||
#endif // CONFIG_PRINT_MEASUREMENTS_UART_GPIO
|
||||
|
||||
#ifndef CONFIG_ENABLE_WIFI
|
||||
#define CONFIG_ENABLE_WIFI 1 // Set to `1` if we want to use WiFi (ie not requred for Serial only application)
|
||||
#endif
|
||||
|
||||
#define CALIBRATION_POINT_SAMPLE_COUNT 32 // Number of ADC samples to take for new calibration point
|
||||
#define CALIBRATION_POINT_ACCURACY_POINT 50 // We expect all CALIBRATION_POINT_SAMPLE_COUNT samples to be
|
||||
@@ -21,7 +32,6 @@
|
||||
#define CAL_POINT_FIRST { .adc = ADC_MIN, .mm = ADC_MIN_EQUALS_MM }
|
||||
#define CAL_POINT_LAST { .adc = ADC_MAX, .mm = ADC_MAX_EQUALS_MM }
|
||||
|
||||
#define PRINT_MEASUREMENT_OVER_SERIAL // Define if we want serial printout for every measurement
|
||||
|
||||
#define ADC_MAX_SAMPLES 64 // Maximum number of ADC samples we can take in one measurement cycle
|
||||
#define ADC_SAMPLES_PER_MEASUREMENT_CYCLE 16 // How many samples to take for each measurement cycle
|
||||
@@ -87,4 +97,18 @@ typedef struct calibration
|
||||
} calibration_t;
|
||||
|
||||
|
||||
// Note during build that certain features have been disabled
|
||||
#if !CONFIG_ENABLE_WIFI
|
||||
#pragma message "-- Note: WiFi is DISBLED in this build!"
|
||||
#endif
|
||||
|
||||
#if !CONFIG_PRINT_MEASUREMENTS_USB_CDC
|
||||
#pragma message "-- Note: Printing measurements over USB-CDC is DISABLED!"
|
||||
#endif
|
||||
|
||||
#if !CONFIG_PRINT_MEASUREMENTS_UART_GPIO
|
||||
#pragma message "-- Note: Printing measurements over SERIAL is DISABLED!"
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+25
-10
@@ -7,17 +7,21 @@
|
||||
#include "include/PersistSettings.h"
|
||||
#include "config_winfidel.h"
|
||||
|
||||
bool bStatusLED = false;
|
||||
|
||||
#if CONFIG_ENABLE_WIFI
|
||||
WiFiManager wifiManager;
|
||||
AsyncWebServer server(80);
|
||||
volatile int WiFi_status = WL_IDLE_STATUS;
|
||||
const char mdnsName[] = MDNS_NAME;
|
||||
const char wifiName[] = WIFI_HOSTNAME;
|
||||
uint8_t dbgOTApercent = 100;
|
||||
bool bStatusLED = false;
|
||||
#ifdef PRINT_MEASUREMENT_OVER_SERIAL
|
||||
#endif //CONFIG_ENABLE_WIFI
|
||||
|
||||
#if CONFIG_PRINT_MEASUREMENTS_USB_CDC
|
||||
int SerialInByte = 0;
|
||||
bool bSerialPrintoutRequested = false;
|
||||
#endif
|
||||
#endif // CONFIG_PRINT_MEASUREMENTS_USB_CDC
|
||||
|
||||
void setup()
|
||||
{
|
||||
@@ -31,16 +35,21 @@ void setup()
|
||||
LED_RED_ON();
|
||||
|
||||
// Configure Serial communication
|
||||
Serial.begin(115200);
|
||||
Serial.println("Wireless Inline Filament Estimator, Low-Cost - WInFiDEL");
|
||||
WiFi.setHostname(wifiName);
|
||||
Serial.begin(115200); // USB-to-UART
|
||||
Serial0.begin(115200); // TX/RX GPIOS
|
||||
|
||||
// wifiManager.resetSettings(); // Wipe WiFi settings. Uncomment for WiFi manager testing
|
||||
Serial.println("Wireless Inline Filament Estimator, Low-Cost - WInFiDEL");
|
||||
Serial0.println("Wireless Inline Filament Estimator, Low-Cost - WInFiDEL");
|
||||
|
||||
#if CONFIG_ENABLE_WIFI
|
||||
WiFi.setHostname(wifiName);
|
||||
#endif // CONFIG_ENABLE_WIFI
|
||||
|
||||
delay(500);
|
||||
|
||||
LED_GREEN_ON();
|
||||
|
||||
#if CONFIG_ENABLE_WIFI
|
||||
bool res;
|
||||
res = wifiManager.autoConnect("SK-WInFiDEL-Setup");
|
||||
|
||||
@@ -67,12 +76,14 @@ void setup()
|
||||
|
||||
// Add service to MDNS-SD
|
||||
MDNS.addService("http", "tcp", 80);
|
||||
#endif // CONFIG_ENABLE_WIFI
|
||||
|
||||
EEPROM.begin(sizeof(calibration_t));
|
||||
calibration_init();
|
||||
|
||||
adc_init();
|
||||
|
||||
#if CONFIG_ENABLE_WIFI
|
||||
Serial.print("Starting WebServer...");
|
||||
setupWebServer();
|
||||
server.begin();
|
||||
@@ -120,6 +131,7 @@ void setup()
|
||||
});
|
||||
ArduinoOTA.begin();
|
||||
Serial.println("Arduino OTA is on");
|
||||
#endif // CONFIG_ENABLE_WIFI
|
||||
|
||||
// Debug message to signal we are initialized and entering loop
|
||||
Serial.println("Ready to go.");
|
||||
@@ -137,9 +149,12 @@ void setup()
|
||||
void loop()
|
||||
{
|
||||
Measurements_Tick();
|
||||
ArduinoOTA.handle();
|
||||
|
||||
#ifdef PRINT_MEASUREMENT_OVER_SERIAL
|
||||
#if CONFIG_ENABLE_WIFI
|
||||
ArduinoOTA.handle();
|
||||
#endif // CONFIG_ENABLE_WIFI
|
||||
|
||||
#ifdef CONFIG_PRINT_MEASUREMENTS_USB_CDC
|
||||
int available = Serial.available();
|
||||
if(available > 0)
|
||||
{
|
||||
@@ -154,5 +169,5 @@ void loop()
|
||||
LED_SERIAL_OFF();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif // CONFIG_PRINT_MEASUREMENTS_USB_CDC
|
||||
}
|
||||
|
||||
@@ -116,7 +116,8 @@ void Measurements_Tick(void)
|
||||
LED_MEASUREMENT_ON();
|
||||
}
|
||||
|
||||
#ifdef PRINT_MEASUREMENT_OVER_SERIAL
|
||||
// Measurement printing over USB-CDC
|
||||
#ifdef CONFIG_PRINT_MEASUREMENTS_USB_CDC
|
||||
if (bSerialPrintoutRequested && (Serial.availableForWrite()>9))
|
||||
{
|
||||
Serial.print(">");
|
||||
@@ -132,7 +133,15 @@ void Measurements_Tick(void)
|
||||
LED_SERIAL_OFF();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif // CONFIG_PRINT_MEASUREMENTS_USB_CDC
|
||||
|
||||
// Measurement printing over Serial
|
||||
#ifdef CONFIG_PRINT_MEASUREMENTS_UART_GPIO
|
||||
Serial0.print(">");
|
||||
Serial0.print(gReadingLast);
|
||||
Serial0.print("mm\r\n");
|
||||
#endif //CONFIG_PRINT_MEASUREMENTS_UART_GPIO
|
||||
|
||||
|
||||
// Set next update timestamp
|
||||
nNextMeasurementTick = millis() + 200;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define __WINFIDEL_FW_VERSION_H__
|
||||
|
||||
#define VERSION_MAJOR 2025
|
||||
#define VERSION_MINOR 2
|
||||
#define VERSION_PATCH 22
|
||||
#define VERSION_MINOR 10
|
||||
#define VERSION_PATCH 17
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user