diff --git a/USBNova.ino b/USBNova.ino index 4b9333a..50a8ac9 100644 --- a/USBNova.ino +++ b/USBNova.ino @@ -30,8 +30,7 @@ void setup() { // Load setting and set USB Device IDs preferences::reset(); preferences::load(); - hid::setID(preferences::getHidVid(), preferences::getHidPid(), preferences::getHidRev()); - msc::setID(preferences::getMscVid().c_str(), preferences::getMscPid().c_str(), preferences::getMscRev().c_str()); + hid::setID(preferences::getVID(), preferences::getPID(), preferences::getVersion()); // Read mode from selector switch selector::init(); diff --git a/schema.json b/schema.json index d2f48da..9da72a5 100644 --- a/schema.json +++ b/schema.json @@ -61,9 +61,9 @@ "title": "Enable HID in setup mode", "default": true }, - "hid_vid": { + "vid": { "type": "string", - "title": "USB Keyboard Vendor ID", + "title": "USB Vendor ID", "pattern": "^[0-9A-F]{4}$", "default": "16D0", "examples": [ @@ -72,9 +72,9 @@ "minLength": 4, "maxLength": 4 }, - "hid_pid": { + "pid": { "type": "string", - "title": "USB Keyboard Product ID", + "title": "USB Product ID", "pattern": "^[0-9A-F]{4}$", "default": "11A4", "examples": [ @@ -83,28 +83,13 @@ "minLength": 4, "maxLength": 4 }, - "hid_rev": { + "rev": { "type": "string", - "title": "USB Keyboard Product Revision", + "title": "USB Product Revision (0100 => 1.0)", "default": "0100", "minLength": 4, "maxLength": 4 }, - "msc_vid": { - "type": "string", - "title": "USB Mass Storage Vendor ID", - "default": "SpHuhn" - }, - "msc_pid": { - "type": "string", - "title": "USB Mass Storage Product ID", - "default": "USB Nova" - }, - "msc_rev": { - "type": "string", - "title": "USB Mass Storage Product Revision", - "default": "1.0" - }, "default_layout": { "type": "string", "title": "Default Keyboard Layout", diff --git a/src/msc/msc.cpp b/src/msc/msc.cpp index d08c7ac..66c548e 100644 --- a/src/msc/msc.cpp +++ b/src/msc/msc.cpp @@ -124,10 +124,6 @@ namespace msc { } } - void setID(const char* vid, const char* pid, const char* rev) { - usb_msc.setID(vid, pid, rev); // Max. 8, 16, 4 characters - } - void enableDrive() { usb_msc.setReadWriteCallback(read_cb, write_cb, flush_cb); usb_msc.setCapacity(flash.size() / 512, 512); diff --git a/src/msc/msc.h b/src/msc/msc.h index e64d173..c7bb04d 100644 --- a/src/msc/msc.h +++ b/src/msc/msc.h @@ -9,7 +9,6 @@ namespace msc { bool format(const char* drive_name = "USB Nova"); void print(); - void setID(const char* vid, const char* pid, const char* rev); void enableDrive(); bool changed(); @@ -17,7 +16,7 @@ namespace msc { bool open(const char* path, bool add_to_stack = true); bool openNextFile(); - + void close(); uint32_t getPosition(); diff --git a/src/preferences/preferences.cpp b/src/preferences/preferences.cpp index 23a9b94..ca5ed3a 100644 --- a/src/preferences/preferences.cpp +++ b/src/preferences/preferences.cpp @@ -25,13 +25,9 @@ namespace preferences { bool enable_led; bool enable_hid; - std::string hid_vid; - std::string hid_pid; - std::string hid_rev; - - std::string msc_vid; // max. 8 chars - std::string msc_pid; // max. 16 chars - std::string msc_rev; // max. 4 chars + std::string vid; + std::string pid; + std::string version; std::string default_layout; int default_delay; @@ -43,7 +39,7 @@ namespace preferences { int idle_color[4]; bool format; - std::string drive_name; + std::string drive_name; bool disable_capslock; bool run_on_indicator; @@ -53,7 +49,8 @@ namespace preferences { // Array help functions void add_array(JsonDocument& doc, const char* name, int* array, int size) { JsonArray jarr = doc.createNestedArray(name); - for(size_t i = 0; i < size; ++i) { + + for (size_t i = 0; i < size; ++i) { jarr.add(array[i]); } } @@ -65,13 +62,9 @@ namespace preferences { root["enable_led"] = enable_led; root["enable_hid"] = enable_hid; - root["hid_vid"] = hid_vid; - root["hid_pid"] = hid_pid; - root["hid_rev"] = hid_rev; - - root["msc_vid"] = msc_vid; - root["msc_pid"] = msc_pid; - root["msc_rev"] = msc_rev; + root["vid"] = vid; + root["pid"] = pid; + root["version"] = version; root["default_layout"] = default_layout; root["default_delay"] = default_delay; @@ -83,14 +76,15 @@ namespace preferences { add_array(root, "idle_color", idle_color, 4); root["disable_capslock"] = disable_capslock; - root["run_on_indicator"] = run_on_indicator; + root["run_on_indicator"] = run_on_indicator; root["initial_delay"] = initial_delay; } void read_array(JsonDocument& doc, const char* name, int* array, int size) { JsonVariant val = doc[name]; - if(val.isNull()) return; + + if (val.isNull()) return; JsonArray jarr = val.as(); @@ -99,10 +93,11 @@ namespace preferences { } } - template + template void read_item(JsonDocument& doc, const char* name, T& val) { JsonVariant new_val = doc[name]; - if(new_val.isNull()) return; + + if (new_val.isNull()) return; val = new_val.as(); } @@ -134,13 +129,9 @@ namespace preferences { read_item(config_doc, "enable_led", enable_led); read_item(config_doc, "enable_hid", enable_hid); - read_item(config_doc, "hid_vid", hid_vid); - read_item(config_doc, "hid_pid", hid_pid); - read_item(config_doc, "hid_rev", hid_rev); - - read_item(config_doc, "msc_vid", msc_vid); - read_item(config_doc, "msc_pid", msc_pid); - read_item(config_doc, "msc_rev", msc_rev); + read_item(config_doc, "vid", vid); + read_item(config_doc, "pid", pid); + read_item(config_doc, "version", version); read_item(config_doc, "default_layout", default_layout); read_item(config_doc, "default_delay", default_delay); @@ -158,9 +149,9 @@ namespace preferences { } disable_capslock = config_doc["disable_capslock"].as(); - run_on_indicator = config_doc["run_on_indicator"].as(); - - initial_delay = config_doc["initial_delay"].as(); + run_on_indicator = config_doc["run_on_indicator"].as(); + + initial_delay = config_doc["initial_delay"].as(); } void save() { @@ -183,22 +174,18 @@ namespace preferences { debug("Saved "); debugln(PREFERENCES_PATH); } - + void reset() { enable_msc = false; enable_led = true; enable_hid = true; - hid_vid = "16D0"; - hid_pid = "11A4"; - hid_rev = "0100"; - - msc_vid = "SpHuhn"; // max. 8 chars - msc_pid = "USB Nova"; // max. 16 chars - msc_rev = "1.0"; // max. 4 chars + vid = "16D0"; + pid = "11A4"; + version = "0100"; default_layout = "US"; - default_delay = 5; + default_delay = 5; main_script = "main_script.txt"; @@ -217,7 +204,7 @@ namespace preferences { idle_color[2] = 0; idle_color[3] = 0; - format = false; + format = false; drive_name = "USB Nova"; disable_capslock = true; @@ -225,7 +212,7 @@ namespace preferences { initial_delay = 1000; } - + void print() { // Create a new JSON document (and string buffer) DynamicJsonDocument json_doc(JSON_SIZE); @@ -255,28 +242,16 @@ namespace preferences { return enable_hid; } - uint16_t getHidVid() { - return std::stoi(hid_vid, nullptr, 16); + uint16_t getVID() { + return std::stoi(vid, nullptr, 16); } - uint16_t getHidPid() { - return std::stoi(hid_pid, nullptr, 16); + uint16_t getPID() { + return std::stoi(pid, nullptr, 16); } - uint16_t getHidRev() { - return std::stoi(hid_rev, nullptr, 16); - } - - std::string getMscVid() { - return msc_vid; - } - - std::string getMscPid() { - return msc_pid; - } - - std::string getMscRev() { - return msc_rev; + uint16_t getVersion() { + return std::stoi(version, nullptr, 16); } std::string getDefaultLayout() { @@ -318,7 +293,7 @@ namespace preferences { bool getRunOnIndicator() { return run_on_indicator; } - + int getInitialDelay() { return initial_delay; } diff --git a/src/preferences/preferences.h b/src/preferences/preferences.h index 062f8d5..89cf081 100644 --- a/src/preferences/preferences.h +++ b/src/preferences/preferences.h @@ -14,13 +14,9 @@ namespace preferences { bool ledEnabled(); bool hidEnabled(); - uint16_t getHidVid(); - uint16_t getHidPid(); - uint16_t getHidRev(); - - std::string getMscVid(); - std::string getMscPid(); - std::string getMscRev(); + uint16_t getVID(); + uint16_t getPID(); + uint16_t getVersion(); std::string getDefaultLayout(); int getDefaultDelay(); @@ -33,7 +29,7 @@ namespace preferences { bool getFormat(); std::string getDriveName(); - + bool getDisableCapslock(); bool getRunOnIndicator();