This commit is contained in:
2025-07-22 12:17:00 +02:00
parent 84276dd1e5
commit aa198c5991
9 changed files with 431 additions and 359 deletions

24
.clang-format Normal file
View File

@@ -0,0 +1,24 @@
---
# We'll use defaults from the LLVM style, but with 4 columns indentation.
BasedOnStyle: LLVM
IndentWidth: 4
---
Language: Cpp
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Middle
AlignTrailingComments: true
BreakBeforeBraces: Custom
BraceWrapping:
BeforeElse: true
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: InlineOnly
---
Language: JavaScript
# Use 100 columns for JS.
ColumnLimit: 100
---
Language: Proto
# Don't format .proto files.
DisableFormat: true
...

5
.clang-tidy Normal file
View File

@@ -0,0 +1,5 @@
Checks: '-clang-diagnostic-*,-clang-analyzer-*,-cppcoreguidelines-*,-modernize-*,-modernize-use-trailing-return-type'
WarningsAsErrors: true
HeaderFilterRegex: ''
AnalyzeTemporaryDtors: false

6
.clangd Normal file
View File

@@ -0,0 +1,6 @@
Diagnostics:
ClangTidy:
Remove: '*'
Completion:
AllScopes: No

42
.gitignore vendored
View File

@@ -48,3 +48,45 @@ Thumbs.db
*.mov
*.wmv
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Linker files
*.ilk
# Debugger Files
*.pdb
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
# debug information files
*.dwo

File diff suppressed because one or more lines are too long

View File

@@ -17,16 +17,18 @@ framework = arduino
; framework = espidf
monitor_speed = 9600
; upload_port = COM8
build_flags = -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MODE=1
build_flags = -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MODE=1 -Wunused -Wall -Wextra
; upload_protocol = espota
; upload_port = 192.168.2.136
; upload_port = 192.168.2.128
; upload_port = 192.168.2.145
; upload_port = 192.168.2.177
upload_port = 192.168.2.177
; upload_port = 192.168.2.33
;board_build.partitions = huge_app.csv
board_build.partitions = min_spiffs.csv
check_tool = clangtidy
check_flags =
clangtidy: --checks=clang-analyser-*, -Wunused-variable
; [env:custom_table]
; platform = espressif32

View File

@@ -52,25 +52,6 @@ void dimmer(void * params);
enum Alarm alarmFired = NO_ALARM;
enum Dimmer dimmerState = NO_DIMMER;
// class MyServerCallbacks : public BLEServerCallbacks {
// bool deviceConnected = false;
// void onConnect(BLEServer * pServer) {
// Serial.println("Callback connected");
// deviceConnected = true;
// _BLEClientConnected = true;
// };
// void onDisconnect(BLEServer * pServer) {
// _BLEClientConnected = false;
// deviceConnected = false;
// }
// public:
// bool getConnectionState() { return deviceConnected; }
// };
void InitBLE(BLEServer * pServer, MyServerCallbacks * serverCallback,
MyAlarmCallback * myAlarmCallback) {
BLEDevice::init("OilCheck");
@@ -114,6 +95,7 @@ struct taskParams pvParams = {.cockpit = &cockpit,
.alarmFired = &alarmFired,
.dimmerState = &dimmerState,
.thDisplayWarning = &thDisplayWarning};
void setup() {
// //setup GPIO
@@ -138,14 +120,14 @@ void setup() {
mode = static_cast<enum NET_MODE>(EEPROM.read(MODE_ADDRESS));
if (mode == MODE_BLE) {
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(ALARM_PIN, RMT_CHANNEL_0);
config.clk_div = 160; // 80
config.tx_config.carrier_en = false;
config.tx_config.idle_level = RMT_IDLE_LEVEL_HIGH;
ESP_ERROR_CHECK(rmt_config(&config));
ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0));
rmt_config_t config = RMT_DEFAULT_CONFIG_TX(ALARM_PIN, RMT_CHANNEL_0);
config.clk_div = 160; // 80
config.tx_config.carrier_en = false;
config.tx_config.idle_level = RMT_IDLE_LEVEL_HIGH;
ESP_ERROR_CHECK(rmt_config(&config));
ESP_ERROR_CHECK(rmt_driver_install(config.channel, 0, 0));
if (mode == MODE_BLE) {
InitBLE(pServer, serverCallback, myAlarmCallback);
@@ -168,6 +150,10 @@ void setup() {
delay(1000);
// ESP.restart();
}
// ArduinoOTA.onStart(THandlerFunction fn);
cockpit.setBrightnessState(0); // minimize energy consumption
ArduinoOTA
.onStart([]() {
String type;
@@ -182,11 +168,18 @@ void setup() {
})
.onEnd([]() {
Serial.println("\nEnd");
// EEPROM.write(MODE_ADDRESS, MODE_BLE);
// EEPROM.commit();
cockpit.turnOffLeds();
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cockpit.led_data,
sizeof(cockpit.led_data) / sizeof(rmt_item32_t),
true));
})
.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
uint8_t percentage = uint8_t((progress / (total / 100)));
cockpit.progressBar(Cockpit::RED, percentage);
ESP_ERROR_CHECK(rmt_write_items(RMT_CHANNEL_0, cockpit.led_data,
sizeof(cockpit.led_data) / sizeof(rmt_item32_t),
true));
})
.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);

View File

@@ -144,6 +144,15 @@ void Cockpit::inToOutMulticolor(Color color[], uint8_t colors, int state) {
writeLEDs();
}
void Cockpit::progressBar(Color color, uint8_t percentage) {
turnOffLeds();
uint8_t leds = uint8_t(percentage * (NUM_LEDS / 100.0));
for (uint8_t i = 0; i < leds; i++) {
this->stateLEDs[i] = scaleBrightness(color);
}
this->writeLEDs();
}
void Cockpit::colorfade(int state) {
// 60 steps to get around the color circle
state = state % 60;
@@ -344,32 +353,9 @@ void Cockpit::displayBrightness(Color color) {
writeLEDs();
}
// void Cockpit::setBrightnessState(int brightnessState, int state){
// this->brightnessState = brightnessState;
// if (state < 10){
// for(int i = 0; i < this->leds; i++){
// if(i <= brightnessState){
// this->stateLEDs[i][0] = this->brightness[this->brightnessState];
// this->stateLEDs[i][1] = 0;
// this->stateLEDs[i][2] = 0;
// }
// else{
// this->stateLEDs[i][0] = 0;
// this->stateLEDs[i][1] = 0;
// this->stateLEDs[i][2] = 0;
// }
// }
// writeLEDs();
// }
// else{
// for(int i = 0; i < this->leds; i++){
// this->stateLEDs[i][0] = 0;
// this->stateLEDs[i][1] = 0;
// this->stateLEDs[i][2] = 0;
// }
// writeLEDs();
// }
// }
void Cockpit::setBrightnessState(uint8_t brightnessState) {
this->brightnessState = brightnessState;
}
void Cockpit::alternating(Color color, int state, int frequencyDivider) {
if (state % (frequencyDivider * 2) < frequencyDivider) {

View File

@@ -64,7 +64,7 @@ public:
bool buffer[BUFFER_SIZE];
rmt_item32_t led_data[BUFFER_SIZE];
Cockpit(gpio_num_t pin, int leds, int pTime, int tCycle, uint8_t brightness);
void setBrightnessState(int brightness, int state);
void setBrightnessState(uint8_t brightness);
void brightnessUp();
void brightnessDown();
void displayBrightness(Color color = {.blue = 255, .red = 0, .green = 0});
@@ -82,6 +82,8 @@ public:
void outToInMulticolor(Color color[], uint8_t colors, int state);
void inToOutMulticolor(Color color[], uint8_t colors, int state);
void progressBar(Color, uint8_t percentage);
void writeLEDs();
void writeLED(uint8_t ledNum);
void writeZero();