Skip to content

Commit

Permalink
"mall grabbing" support lol XD
Browse files Browse the repository at this point in the history
Displays battery when pitch >70
This is useful on the XR with no lightbar
Fixed two other config vars
  • Loading branch information
Relys committed Oct 14, 2023
1 parent 037e0b0 commit 70ee05e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
6 changes: 4 additions & 2 deletions src/AppConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ boolean AppConfiguration::readPreferences() {
config.lightBarLedType = doc["lightBarLedType"] | "GRB";
config.ledFrequency = doc["ledFrequency"] | "KHZ800";
config.lightBarLedFrequency = doc["lightBarLedFrequency"] | "KHZ800";
config.isLightBarReversed = doc["isLightBarReversed"] | "false";
config.isLightBarReversed = doc["isLightBarLedTypeDifferent"] | "false";
config.isLightBarReversed = doc["isLightBarReversed"] | false;
config.isLightBarReversed = doc["isLightBarLedTypeDifferent"] | false;
config.idleLightTimeout = doc["idleLightTimeout"] | 60000;
config.mallGrab = doc["mallGrab"] | false;
config.logLevel = doc["logLevel"] | Logger::SILENT;
config.mtuSize = doc["mtuSize"] | 512;
config.oddevenActive = doc["oddevenActive"] | true;
Expand Down Expand Up @@ -108,6 +109,7 @@ boolean AppConfiguration::savePreferences() {
doc["isLightBarReversed"] = config.isLightBarReversed;
doc["isLightBarLedTypeDifferent"] = config.isLightBarLedTypeDifferent;
doc["idleLightTimeout"] = config.idleLightTimeout;
doc["mallGrab"] = config.mallGrab;
doc["logLevel"] = config.logLevel;
doc["mtuSize"] = config.mtuSize;
String json = "";
Expand Down
1 change: 1 addition & 0 deletions src/AppConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ struct Config {
VISITABLE(boolean , isLightBarReversed);
VISITABLE(boolean , isLightBarLedTypeDifferent);
VISITABLE(int , idleLightTimeout);
VISITABLE(boolean , mallGrab);
VISITABLE(int , mtuSize);
VISITABLE(boolean , oddevenActive);
VISITABLE(boolean, lightsSwitch);
Expand Down
19 changes: 13 additions & 6 deletions src/ILedController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

unsigned long idleTimer = 0;

void ILedController::loop(const int *new_forward, const int *new_backward, const int *new_idle, const int *new_brake) {
void ILedController::loop(const int *new_forward, const int *new_backward, const int *new_idle, const int *new_brake, const int *new_mall_grab) {

if(!AppConfiguration::getInstance()->config.lightsSwitch) {
this->changePattern(Pattern::NONE, *(new_forward) == HIGH, false);
Expand All @@ -15,8 +15,6 @@ void ILedController::loop(const int *new_forward, const int *new_backward, const
this->changePattern(Pattern::RESCUE_FLASH_LIGHT, *(new_forward) == HIGH, false);
}

this->update();

// is there a change detected
if (old_forward != *(new_forward) || old_backward != *(new_backward)) {
if (Logger::getLogLevel() == Logger::VERBOSE) {
Expand All @@ -32,14 +30,22 @@ void ILedController::loop(const int *new_forward, const int *new_backward, const
}

//idle state???
if (old_idle != *(new_idle)) {
if (*(new_idle) == HIGH) {
if (old_idle != *(new_idle) || old_mall_grab != *(new_mall_grab)) {
if (*(new_idle) == HIGH || old_mall_grab != *(new_mall_grab)) {
if (idleTimer == 0) {
idleTimer = millis();
}
this->idleSequence();
if (AppConfiguration::getInstance()->config.mallGrab && *(new_mall_grab) == HIGH)
{
this->changePattern(Pattern::BATTERY_INDICATOR, true, false);
}
else
{
this->idleSequence();
}
}
old_idle = *(new_idle);
old_mall_grab = *(new_mall_grab);
}

if (idleTimer != 0 && AppConfiguration::getInstance()->config.idleLightTimeout > 0 &&
Expand All @@ -48,6 +54,7 @@ void ILedController::loop(const int *new_forward, const int *new_backward, const
this->changePattern(NONE, true, false);
idleTimer = 0;
}
this->update();
}


3 changes: 2 additions & 1 deletion src/ILedController.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ class ILedController {
virtual void startSequence() = 0;
virtual void changePattern(Pattern pattern, boolean isForward, boolean repeatPattern ) = 0;
virtual void update() = 0;
void loop(const int* new_forward, const int* new_backward, const int* idle, const int* new_brake);
void loop(const int* new_forward, const int* new_backward, const int* idle, const int* new_brake, const int* mall_grab);

private:
const static int bufSize = 128;
char buf[bufSize];
int old_forward = LOW;
int old_backward = LOW;
int old_idle = LOW;
int old_mall_grab= LOW;
};

class LedControllerFactory {
Expand Down
5 changes: 4 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ int new_forward = LOW;
int new_backward = LOW;
int new_brake = LOW;
int idle = LOW;
int mall_grab = LOW;
double idle_erpm = 10.0;
boolean updateInProgress = false;

Expand Down Expand Up @@ -159,11 +160,13 @@ void loop() {
new_backward = vescData.erpm < -idle_erpm ? HIGH : LOW;
idle = (abs(vescData.erpm) < idle_erpm && vescData.switchState == 0) ? HIGH : LOW;
new_brake = (abs(vescData.erpm) > idle_erpm && vescData.current < -4.0) ? HIGH : LOW;
mall_grab = (vescData.pitch > 70.0) ? HIGH : LOW;
#else
new_forward = digitalRead(PIN_FORWARD);
new_backward = digitalRead(PIN_BACKWARD);
new_brake = digitalRead(PIN_BRAKE);
idle = new_forward == LOW && new_backward == LOW;
mall_grab = LOW;
#endif

#ifdef CANBUS_ENABLED
Expand All @@ -175,7 +178,7 @@ void loop() {
#endif

// call the led controller loop
ledController->loop(&new_forward, &new_backward, &idle, &new_brake);
ledController->loop(&new_forward, &new_backward, &idle, &new_brake, &mall_grab);

// measure and check voltage
batMonitor->checkValues();
Expand Down

0 comments on commit 70ee05e

Please sign in to comment.