Adjust colors in preferences

This commit is contained in:
Spacehuhn 2022-07-07 00:56:20 +02:00
parent 3ed846ed0a
commit c1a5e54b03
5 changed files with 70 additions and 22 deletions

View File

@ -46,18 +46,18 @@ void setup() {
// ========== Setup Mode ========== //
if (mode == SETUP) {
led::setColor(0, 0, 20); // Set LED to blue
led::setColor(preferences::getSetupColor()); // Set LED to blue
while (true) {
if (selector::changed()) {
mode = selector::read() ? SETUP : ATTACK;
if (mode == ATTACK) {
preferences::load(); // Reload the settings (in case the main script path changed)
preferences::load(); // Reload the settings (in case the main script path changed)
led::setColor(128, 0, 0); // Turn LED red
attack::start(); // Start keystroke injection attack
led::setColor(0, 0, 20); // Set LED to blue
led::setColor(preferences::getAttackColor()); // Turn LED red
attack::start(); // Start keystroke injection attack
led::setColor(preferences::getSetupColor()); // Set LED to blue
mode = SETUP;
}
@ -67,20 +67,20 @@ void setup() {
}
// ========== Setup Mode ========== //
else if (mode == ATTACK) {
delay(1000); // Wait 1s to give the computer time to initialize the keyboard
delay(1000); // Wait 1s to give the computer time to initialize the keyboard
led::setColor(128, 0, 0); // Turn LED red
attack::start(); // Start keystroke injection attack
led::setColor(0, 30, 0); // Turn LED green
led::setColor(preferences::getAttackColor()); // Turn LED red
attack::start(); // Start keystroke injection attack
led::setColor(preferences::getIdleColor()); // Turn LED green
while (true) {
if (selector::changed()) {
mode = selector::read() ? SETUP : ATTACK;
if (mode == ATTACK) {
led::setColor(128, 0, 0); // Turn LED red
attack::start(); // Start keystroke injection attack
led::setColor(0, 30, 0); // Turn LED green
led::setColor(preferences::getAttackColor()); // Turn LED red
attack::start(); // Start keystroke injection attack
led::setColor(preferences::getIdleColor()); // Turn LED green
}
}
delay(100);

View File

@ -55,6 +55,10 @@ namespace led {
}
}
void setColor(int* color) {
setColor(color[0], color[1], color[2]);
}
void setColor(int r, int g, int b) {
for (size_t i = 0; i<led.numPixels(); i++) {
led.setPixelColor(i, r, g, b);

View File

@ -7,6 +7,7 @@
namespace led {
void init();
void setEnable(bool enabled);
void setColor(int* color);
void setColor(int r, int g, int b);
void start_blink(uint8_t r, uint8_t g, uint8_t b, unsigned long intv);
void stop_blink();

View File

@ -26,6 +26,10 @@ namespace preferences {
std::string main_script { "main.script" };
int attack_color[3] { 128, 0, 0 };
int setup_color[3] { 0, 0, 20 };
int idle_color[3] { 0, 30, 0 };
// ======== PUBLIC ======== //
void load() {
// Read config file
@ -46,17 +50,40 @@ namespace preferences {
}
// Fetch values.
enable_msc = config_doc["enable_msc"].as<bool>();
enable_led = config_doc["enable_led"].as<bool>();
hid_vid = config_doc["hid_vid"].as<std::string>();
hid_pid = config_doc["hid_pid"].as<std::string>();
hid_rev = config_doc["hid_rev"].as<std::string>();
msc_vid = config_doc["msc_vid"].as<std::string>();
msc_pid = config_doc["msc_pid"].as<std::string>();
msc_rev = config_doc["msc_rev"].as<std::string>();
enable_msc = config_doc["enable_msc"].as<bool>();
enable_led = config_doc["enable_led"].as<bool>();
hid_vid = config_doc["hid_vid"].as<std::string>();
hid_pid = config_doc["hid_pid"].as<std::string>();
hid_rev = config_doc["hid_rev"].as<std::string>();
msc_vid = config_doc["msc_vid"].as<std::string>();
msc_pid = config_doc["msc_pid"].as<std::string>();
msc_rev = config_doc["msc_rev"].as<std::string>();
default_layout = config_doc["default_layout"].as<std::string>();
default_delay = config_doc["default_delay"].as<int>();
main_script = config_doc["main_script"].as<std::string>();
main_script = config_doc["main_script"].as<std::string>();
JsonArray attack_color_array = config_doc["attack_color"].as<JsonArray>();
for (size_t i = 0; i<attack_color_array.size() && i<3; ++i) {
attack_color[i] = attack_color_array[i].as<int>();
}
JsonArray setup_color_array = config_doc["setup_color"].as<JsonArray>();
for (size_t i = 0; i<setup_color_array.size() && i<3; ++i) {
setup_color[i] = setup_color_array[i].as<int>();
}
JsonArray idle_color_array = config_doc["idle_color"].as<JsonArray>();
for (size_t i = 0; i<idle_color_array.size() && i<3; ++i) {
idle_color[i] = idle_color_array[i].as<int>();
}
}
bool mscEnabled() {
@ -102,4 +129,16 @@ namespace preferences {
std::string getMainScript() {
return main_script;
}
int* getAttackColor() {
return attack_color;
}
int* getSetupColor() {
return setup_color;
}
int* getIdleColor() {
return idle_color;
}
}

View File

@ -20,6 +20,10 @@ namespace preferences {
std::string getDefaultLayout();
int getDefaultDelay();
std::string getMainScript();
int* getAttackColor();
int* getSetupColor();
int* getIdleColor();
}