Attempted to fix stuck on in reverse. Cleaned up some excessive serial logging and unused declarations. Reading mode switch on release.
This commit is contained in:
+37
-36
@@ -9,16 +9,14 @@ constexpr int LEDS_TAIL_LENGTH = 10;
|
||||
constexpr int LEDS_TAIL_BRIGHTNESS = 255;
|
||||
constexpr int LEDS_TAIL_SIDE_LENGTH = 2;
|
||||
constexpr int LEDS_TAIL_SIDE_MARGIN = 2;
|
||||
constexpr int LEDS_TAIL_RIGHT_RANGE[] = {0, LEDS_TAIL_SIDE_LENGTH};
|
||||
constexpr int LEDS_TAIL_LEFT_RANGE[] = {LEDS_TAIL_LENGTH - LEDS_TAIL_SIDE_LENGTH, LEDS_TAIL_SIDE_LENGTH};
|
||||
|
||||
constexpr int LEDS_LEFT_PIN = PA5;
|
||||
constexpr int LEDS_RIGHT_PIN = PA7;
|
||||
|
||||
/* default configuration right lamp (left from the front)
|
||||
RING EDGE
|
||||
29 30 31 32 33 34 35 37 0 1 2 3 4 5 6 7 8 9 10
|
||||
28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11
|
||||
31 32 33 34 35 36 37 38 0 1 2 3 4 5 6 7 8 9 10 11
|
||||
30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12
|
||||
*/
|
||||
constexpr int LEDS_TOP_LENGTH = 12;
|
||||
constexpr int LEDS_BOTTOM_LENGTH = 11;
|
||||
@@ -91,9 +89,7 @@ uint32_t colorHSV(float hue, float sat = 1.0, float val = 1.0) {
|
||||
|
||||
const uint32_t COLOR_OFF = ledsTail.Color(0, 0, 0, 0);
|
||||
const uint32_t COLOR_WHITE = ledsTail.Color(0, 0, 0, 255);
|
||||
const uint32_t COLOR_WHITE_FULL = ledsTail.Color(255, 255, 255, 255);
|
||||
const uint32_t COLOR_WHITE_DIM = ledsTail.Color(0, 0, 0, 100);
|
||||
const uint32_t COLOR_RED_DIM = ledsTail.Color(150, 0, 0, 0);
|
||||
const uint32_t COLOR_RED = ledsTail.Color(255, 0, 0, 0);
|
||||
const uint32_t COLOR_AMBER = colorHSV(10); // easier value fade
|
||||
const uint32_t COLOR_POLICE_BLUE = ledsTail.Color(0, 0, 255, 0);
|
||||
@@ -116,8 +112,6 @@ unsigned long indicatorRightStart = 0;
|
||||
bool indicatorLeftActive = false;
|
||||
bool indicatorRightActive = false;
|
||||
|
||||
bool policeActive = false;
|
||||
|
||||
void setup() {
|
||||
// initialize digital pin LED_BUILTIN as an output.
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
@@ -315,11 +309,11 @@ void animatePolice() {
|
||||
}
|
||||
|
||||
if (policeFrame < 6) {
|
||||
ledsHeadLeft.fill(COLOR_WHITE_DIM, LEDS_EDGE_LENGTH, LEDS_EDGE_LENGTH + LEDS_RING_LENGTH);
|
||||
ledsHeadRight.fill(COLOR_WHITE, LEDS_EDGE_LENGTH, LEDS_EDGE_LENGTH + LEDS_RING_LENGTH);
|
||||
ledsHeadLeft.fill(COLOR_WHITE_DIM, LEDS_EDGE_LENGTH, LEDS_RING_LENGTH);
|
||||
ledsHeadRight.fill(COLOR_WHITE, LEDS_EDGE_LENGTH, LEDS_RING_LENGTH);
|
||||
} else {
|
||||
ledsHeadLeft.fill(COLOR_WHITE, LEDS_EDGE_LENGTH, LEDS_EDGE_LENGTH + LEDS_RING_LENGTH);
|
||||
ledsHeadRight.fill(COLOR_WHITE_DIM, LEDS_EDGE_LENGTH, LEDS_EDGE_LENGTH + LEDS_RING_LENGTH);
|
||||
ledsHeadLeft.fill(COLOR_WHITE, LEDS_EDGE_LENGTH, LEDS_RING_LENGTH);
|
||||
ledsHeadRight.fill(COLOR_WHITE_DIM, LEDS_EDGE_LENGTH, LEDS_RING_LENGTH);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -469,7 +463,8 @@ void animate(long now) {
|
||||
animateKitt();
|
||||
}
|
||||
|
||||
if (now - lastPedalRelease < 1500) {
|
||||
// lastPedalRelease is 0 until the first release, prevents brake lights right after boot
|
||||
if (lastPedalRelease > 0 && now - lastPedalRelease < 1500) {
|
||||
animateBrake();
|
||||
}
|
||||
|
||||
@@ -497,11 +492,15 @@ void render() {
|
||||
bool isOff = false;
|
||||
|
||||
void shutdown() {
|
||||
// digitalWrite(PIN_BUCK, BUCK_OFF);
|
||||
// when STLink or USB prevents full power cut, loop keeps running, only shut down once
|
||||
if (isOff) {
|
||||
return;
|
||||
}
|
||||
|
||||
Serial.println("SHUTTING DOWN");
|
||||
|
||||
Serial.println("BUCK OFF");
|
||||
digitalWrite(PIN_BUCK, LOW);
|
||||
digitalWrite(PIN_BUCK, BUCK_OFF);
|
||||
|
||||
delay(100);
|
||||
|
||||
@@ -532,16 +531,19 @@ void loop() {
|
||||
modePressed = true;
|
||||
modePressStart = now;
|
||||
|
||||
activeMode = (Mode)((activeMode + 1) % MODE_COUNT);
|
||||
animationFrame = 0; // ensures animations start cleanly instead of halfway
|
||||
|
||||
lastButtonPress = now;
|
||||
|
||||
Serial.print("BUTTON MODE ");
|
||||
Serial.println(activeMode);
|
||||
}
|
||||
|
||||
// switch mode on release, so a long press for shutdown doesn't switch mode first
|
||||
if (buttonMode.released()) {
|
||||
if (modePressed && !isOff) {
|
||||
activeMode = (Mode)((activeMode + 1) % MODE_COUNT);
|
||||
animationFrame = 0; // ensures animations start cleanly instead of halfway
|
||||
|
||||
Serial.print("BUTTON MODE ");
|
||||
Serial.println(activeMode);
|
||||
}
|
||||
|
||||
modePressed = false;
|
||||
}
|
||||
|
||||
@@ -577,31 +579,30 @@ void loop() {
|
||||
Serial.println("BUTTON RIGHT");
|
||||
}
|
||||
|
||||
if (pedalReverse.read() == Button::PRESSED && pedalForward.read() != Button::PRESSED) {
|
||||
// only the pedal counts as activity, forward and reverse inputs can read active while parked
|
||||
if (pedal.read() == Button::PRESSED) {
|
||||
lastPedalPress = now;
|
||||
isReversing = true;
|
||||
|
||||
if (isOff) {
|
||||
restart();
|
||||
}
|
||||
|
||||
Serial.println("PEDAL REVERSE");
|
||||
} else {
|
||||
isReversing = false;
|
||||
}
|
||||
|
||||
if (pedalForward.read() == Button::PRESSED) {
|
||||
lastPedalPress = now;
|
||||
|
||||
if (isOff) {
|
||||
restart();
|
||||
}
|
||||
|
||||
Serial.println("PEDAL FORWARD");
|
||||
}`3
|
||||
if (pedal.pressed()) {
|
||||
Serial.println("PEDAL PRESSED");
|
||||
}
|
||||
|
||||
if (pedal.released()) {
|
||||
lastPedalRelease = now;
|
||||
|
||||
Serial.println("PEDAL RELEASED");
|
||||
}
|
||||
|
||||
const bool wasReversing = isReversing;
|
||||
isReversing = pedalReverse.read() == Button::PRESSED && pedalForward.read() != Button::PRESSED;
|
||||
|
||||
if (isReversing != wasReversing) {
|
||||
Serial.println(isReversing ? "REVERSE ON" : "REVERSE OFF");
|
||||
}
|
||||
|
||||
if (!isOff && now - lastFrame >= ANIMATION_INTERVAL) {
|
||||
|
||||
Reference in New Issue
Block a user