Skip to content

Commit d92e98a

Browse files
committed
test ai commands
1 parent c76196a commit d92e98a

File tree

2 files changed

+95
-47
lines changed

2 files changed

+95
-47
lines changed

Diff for: DPVController/beep.cpp

+31-20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Includes for required header files
12
#include "constants.h"
23
#include "Blinker.h"
34
#include "BlinkSequence.h"
@@ -6,61 +7,71 @@
67
#include "motor.h"
78

89
/**
9-
* CONSTANTS
10+
* CONSTANTS - Constants for beep durations
1011
*/
11-
const long SHORT_BEEP_MS = 200;
12-
const long LONG_BEEP_MS = 600;
13-
const long PAUSE_MS = 400;
12+
const long SHORT_BEEP_MS = 200; // Duration of short beep in milliseconds
13+
const long LONG_BEEP_MS = 600; // Duration of long beep in milliseconds
14+
const long PAUSE_MS = 400; // Duration of pause between beeps in milliseconds
1415

1516
/**
16-
* VARIABLES
17+
* VARIABLES - Global timing variables
1718
*/
18-
unsigned long lastBeepTime = 0;
19-
unsigned long lastLeakBeepTime = 0;
19+
unsigned long lastBeepTime = 0; // Timestamp of last beep
20+
unsigned long lastLeakBeepTime = 0; // Timestamp of last leak alarm
2021

21-
void turnOnFunction(){digitalWrite(PIN_BEEP, HIGH);}
22+
// Helper functions to control the beeper
23+
void turnOnFunction(){digitalWrite(PIN_BEEP, HIGH);} // Turns beeper on
2224

23-
void turnOffFunction(){digitalWrite(PIN_BEEP, LOW);}
25+
void turnOffFunction(){digitalWrite(PIN_BEEP, LOW);} // Turns beeper off
2426

27+
// Creates a Blinker object with the on/off functions
2528
Blinker beepBlinker = Blinker(turnOnFunction, turnOffFunction);
2629

27-
30+
// Determines beep duration based on character
31+
// '1' = short beep, anything else = long beep
2832
long beepDuration(char c){
2933
return (c == '1') ? SHORT_BEEP_MS : LONG_BEEP_MS;
3034
}
3135

36+
// Creates a sequence of beeps with defined pauses
3237
BlinkSequence beepSequence = BlinkSequence(beepBlinker, beepDuration, PAUSE_MS);
3338

34-
3539
/**
36-
* Perform a beep for the given time. Works asynchronously.
40+
* Generates a single beep for the specified duration.
41+
* Works asynchronously (non-blocking).
42+
* @param length_ms Duration of beep in milliseconds
3743
*/
3844
void beep(long length_ms){
3945
log("Beeping for ms", length_ms);
4046
beepBlinker.blink(length_ms);
4147
}
4248

4349
/**
44-
* Perform a beep for each character in the string with a pause between beeps.
45-
* a "1" in the string will be a short beep. All others long beeps.
46-
* Works asynchronously(does not block).
50+
* Generates a sequence of beeps based on a string.
51+
* '1' generates a short beep, all other characters generate long beeps.
52+
* Works asynchronously (non-blocking).
53+
* @param sequence String containing the beep sequence
4754
*/
4855
void beep(const String& sequence) {
4956
if(EnableDebugLog) Serial.println("beepSequence:"+sequence);
5057
beepSequence.blink(sequence);
5158
}
5259

60+
// Main loop for beep functionality
5361
void beepLoop(){
5462
beepSequence.loop();
5563
beepBlinker.loop();
5664
}
5765

58-
66+
/**
67+
* Monitors leak sensor and outputs warning tone if needed
68+
* Checks sensor status every 10 seconds and beeps if leak detected
69+
* Part of DPV safety system for water ingress detection
70+
*/
5971
void BeepForLeak() {
60-
if (leakSensorState == 1 && micros() - lastBeepTime >= (10 * 1000 * 1000)) { // Every 10 seconds
61-
beep("12121212"); // Here is the desired sequence for the sound
72+
if (leakSensorState == 1 && micros() - lastBeepTime >= (10 * 1000 * 1000)) { // Check every 10 seconds
73+
beep("12121212"); // Alternates short/long for warning
6274
log("WARNING LEAK", 12121212, true);
63-
lastLeakBeepTime = micros(); // update the time of the last call
75+
lastLeakBeepTime = micros(); // Updates timestamp
6476
}
6577
}
66-

Diff for: DPVController/ledBar.cpp

+64-27
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,71 @@
33
#include "constants.h"
44

55
/**
6-
* Code that controls the two led strips
6+
* Code for controlling the two LED strips.
7+
* Enables display of various states like speed,
8+
* battery level and warnings through LED animations.
79
*/
810

911
/*
1012
* CONSTANTS
1113
*/
12-
const int LedBar_Num = 10; // Number of LEDs in the strip
13-
const int LEDBar_Brightness = 15;
14-
const int LEDBar_BrightnessSecond = 3;
14+
const int LedBar_Num = 10; // Number of LEDs per strip
15+
const int LEDBar_Brightness = 15; // Default brightness for active LEDs
16+
const int LEDBar_BrightnessSecond = 3; // Reduced brightness for secondary displays
1517

1618
/*
1719
* GLOBAL VARIABLES
1820
*/
21+
// NeoPixel object for both LED strips
1922
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LedBar_Num + LedBar2_Num, PIN_LEDBAR, NEO_GRB + NEO_KHZ800);
2023

21-
unsigned long lastOverrideTime = 0;
22-
bool isOverridden = false;
23-
int lastSpeedValue = 0;
24-
const unsigned long OVERRIDE_TIMEOUT = 30000; // 30 Sekunden in Millisekunden
24+
unsigned long lastOverrideTime = 0; // Timestamp of last override
25+
bool isOverridden = false; // Flag for active override
26+
int lastSpeedValue = 0; // Stores last speed value
27+
const unsigned long OVERRIDE_TIMEOUT = 30000; // Timeout for overrides (30 seconds)
2528

29+
/**
30+
* Initializes the LED strips and sets them to standby mode
31+
*/
2632
void ledBarSetup(){
27-
//Neopixel
2833
strip.begin();
29-
strip.show(); // Alle LEDs ausschalten
34+
strip.show(); // Turn off all LEDs
3035
setBarStandby();
3136
}
3237

33-
38+
/**
39+
* Sets the LEDs of a strip with defined colors and brightness
40+
* @param stripNumber Number of LED strip (1 or 2)
41+
* @param numLEDsOn Number of active LEDs
42+
* @param hexColorOn Hex color code for active LEDs
43+
* @param brightnessOn Brightness of active LEDs (0-100)
44+
* @param hexColorOff Hex color code for inactive LEDs
45+
* @param brightnessOff Brightness of inactive LEDs (0-100)
46+
*/
3447
void setBar(int stripNumber, int numLEDsOn, String hexColorOn, int brightnessOn, String hexColorOff, int brightnessOff) {
35-
// Make sure that stripNumber is valid (1 for the first strip, 2 for the second strip)
3648
if (stripNumber != 1 && stripNumber != 2) {
37-
return; // Unauthorized value, do nothing
49+
return; // Invalid value, abort function
3850
}
3951

40-
// Berechne den Startindex basierend auf stripNumber
4152
int startIndex = (stripNumber == 1) ? 0 : LedBar_Num;
42-
43-
// Calculate the end index based on stripNumber
4453
int endIndex = (stripNumber == 1) ? LedBar_Num : LedBar_Num + LedBar2_Num;
4554

46-
// Convert the hex color value to RGB color values for the switched-on color
55+
// Convert hex color code to RGB for active LEDs
4756
long numberOn = (long)strtol(&hexColorOn[1], NULL, 16);
4857
int redOn = numberOn >> 16;
4958
int greenOn = (numberOn >> 8) & 0xFF;
5059
int blueOn = numberOn & 0xFF;
5160

52-
// Set the LEDs according to the specified brightness and colors
61+
// Set active LEDs
5362
for (int i = startIndex; i < startIndex + numLEDsOn; i++) {
5463
int dimmed_color_r = redOn * brightnessOn / 100;
5564
int dimmed_color_g = greenOn * brightnessOn / 100;
5665
int dimmed_color_b = blueOn * brightnessOn / 100;
5766
strip.setPixelColor(i, strip.Color(dimmed_color_r, dimmed_color_g, dimmed_color_b));
5867
}
5968

60-
// Set the LEDs for the side that is switched off
69+
// Set inactive LEDs
6170
for (int i = startIndex + numLEDsOn; i < endIndex; i++) {
62-
// Convert the hex color value to RGB color values for the switched off color
6371
long numberOff = (long)strtol(&hexColorOff[1], NULL, 16);
6472
int redOff = numberOff >> 16;
6573
int greenOff = (numberOff >> 8) & 0xFF;
@@ -70,29 +78,46 @@ void setBar(int stripNumber, int numLEDsOn, String hexColorOn, int brightnessOn,
7078
strip.show(); // Update LED strips
7179
}
7280

81+
/**
82+
* Sets LED strips to standby mode
83+
*/
7384
void setBarStandby() {
7485
setBar(1,10,"#e38f09", LEDBar_BrightnessSecond, "#000000", 0);
7586
}
7687

88+
/**
89+
* Checks and handles timeouts of overrides
90+
*/
7791
void handleBarOverride() {
7892
if (isOverridden && (millis() - lastOverrideTime > OVERRIDE_TIMEOUT)) {
7993
isOverridden = false;
80-
setBarSpeed(lastSpeedValue); // Stelle Speed-Anzeige wieder her
94+
setBarSpeed(lastSpeedValue); // Restore speed display
8195
}
8296
}
8397

98+
/**
99+
* Displays current speed on LED strip
100+
* @param num Number of LEDs to activate (speed)
101+
*/
84102
void setBarSpeed(int num) {
85-
lastSpeedValue = num; // Speichern des letzten Speed-Wertes
103+
lastSpeedValue = num;
86104
if (!isOverridden) {
87105
setBar(1,num,"#cb1bf2", LEDBar_Brightness, "#000000", 0);
88106
}
89107
}
90108

109+
/**
110+
* Displays battery level on second LED strip
111+
* @param num Battery level (0-10)
112+
*/
91113
void setBarBattery(int num) {
92114
int calc = LedBar_Num-num;
93115
setBar(2,calc,"#e30b0b", LEDBar_BrightnessSecond, "#0a9e08", LEDBar_Brightness);
94116
}
95117

118+
/**
119+
* Shows leak warnings through LED animations
120+
*/
96121
void setBarLeak() {
97122
int frontLeakState = digitalRead(PIN_LEAK_FRONT);
98123
int backLeakState = digitalRead(PIN_LEAK_BACK);
@@ -102,34 +127,46 @@ void setBarLeak() {
102127
lastOverrideTime = millis();
103128

104129
if (backLeakState == LOW && frontLeakState == LOW) {
105-
setBar(1,10,"#0000FF", LEDBar_Brightness, "#0000FF", 0);
130+
setBar(1,10,"#0000FF", LEDBar_Brightness, "#0000FF", 0); // Both leaks
106131
} else if (backLeakState == LOW) {
107-
setBar(1,5,"#0000FF", LEDBar_Brightness, "#0000FF", 0);
132+
setBar(1,5,"#0000FF", LEDBar_Brightness, "#0000FF", 0); // Back leak
108133
} else if(frontLeakState == LOW) {
109-
setBar(1,5,"#0000FF", 0, "#0000FF", LEDBar_Brightness);
134+
setBar(1,5,"#0000FF", 0, "#0000FF", LEDBar_Brightness); // Front leak
110135
}
111136
}
112137
}
113138

139+
/**
140+
* Shows powerbank status
141+
* @param status true for active, false for inactive
142+
*/
114143
void setBarPowerBank(bool status) {
115144
isOverridden = true;
116145
lastOverrideTime = millis();
117146

118147
if (status){
119-
setBar(1,9,"#000000", 0, "#036ffc", LEDBar_Brightness);
148+
setBar(1,9,"#000000", 0, "#036ffc", LEDBar_Brightness); // Blue for active
120149
}
121150
else {
122-
setBar(1,9,"#000000", 0, "#ff0000", LEDBar_Brightness);
151+
setBar(1,9,"#000000", 0, "#ff0000", LEDBar_Brightness); // Red for inactive
123152
}
124153
}
125154

155+
/**
156+
* Sets a specific number of LEDs to white
157+
* @param num Number of white LEDs
158+
*/
126159
void setBarLED(int num) {
127160
isOverridden = true;
128161
lastOverrideTime = millis();
129162
int calc = LedBar_Num-num;
130163
setBar(1,calc,"#000000", 0, "#FFFFFF", LEDBar_Brightness);
131164
}
132165

166+
/**
167+
* Activates/Deactivates flasher mode
168+
* @param status true for active, false for inactive
169+
*/
133170
void setBarFlasher(bool status) {
134171
if (status){
135172
isOverridden = true;

0 commit comments

Comments
 (0)