Skip to content

Commit

Permalink
Support for array of seg and velocity
Browse files Browse the repository at this point in the history
state json can now support array of segments and velocity
  • Loading branch information
chillfactor032 committed Jun 3, 2024
1 parent 15486ca commit 2e25fc1
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions usermods/FlashEffect/flash_effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bool flash_enable = true;

struct FlashData {
uint32_t start_ms;
uint8_t velocity;
bool start_requested;
};

Expand Down Expand Up @@ -102,13 +103,22 @@ struct FlashEffect : Usermod {
}
JsonObject flash = root["flash"];
if(flash.isNull()) return;
auto seg_obj = flash["seg_id"];
if(seg_obj.isNull()) return;
uint16_t seg_id = seg_obj;
if (seg_id >= 256) return;
flash_data[seg_id].start_ms = millis();
flash_data[seg_id].start_requested = true;
Serial.printf("flash_effect seg_id=%d\n", seg_id);
uint8_t velocity = 64;
if(!flash["vel"].isNull()){
velocity = flash["vel"];
}
JsonArray seg_arr = flash["seg"];
if(seg_arr.isNull()) return;
uint8_t seg_id;
for(uint8_t i = 0; i < seg_arr.size(); i++){
seg_id = flash["seg"][i];
if(seg_id>=256) continue;
flash_data[seg_id].start_ms = millis();
flash_data[seg_id].velocity = velocity;
flash_data[seg_id].start_requested = true;
Serial.printf("flash_effect seg_id=%d vel=%d\n", seg_id, velocity);
}
//Serial.printf("flash_effect seg_id=%d\n", seg_id);
}

/*
Expand Down

0 comments on commit 2e25fc1

Please sign in to comment.