Removed msc_vid, msc_pid, msc_rev

Because it had no affect anyway. There's only one VID and PID used anyway.
This commit is contained in:
Spacehuhn 2023-06-28 10:39:15 +02:00
parent 92c4089d6d
commit 5a7ddd5845
6 changed files with 47 additions and 97 deletions

View File

@ -30,8 +30,7 @@ void setup() {
// Load setting and set USB Device IDs // Load setting and set USB Device IDs
preferences::reset(); preferences::reset();
preferences::load(); preferences::load();
hid::setID(preferences::getHidVid(), preferences::getHidPid(), preferences::getHidRev()); hid::setID(preferences::getVID(), preferences::getPID(), preferences::getVersion());
msc::setID(preferences::getMscVid().c_str(), preferences::getMscPid().c_str(), preferences::getMscRev().c_str());
// Read mode from selector switch // Read mode from selector switch
selector::init(); selector::init();

View File

@ -61,9 +61,9 @@
"title": "Enable HID in setup mode", "title": "Enable HID in setup mode",
"default": true "default": true
}, },
"hid_vid": { "vid": {
"type": "string", "type": "string",
"title": "USB Keyboard Vendor ID", "title": "USB Vendor ID",
"pattern": "^[0-9A-F]{4}$", "pattern": "^[0-9A-F]{4}$",
"default": "16D0", "default": "16D0",
"examples": [ "examples": [
@ -72,9 +72,9 @@
"minLength": 4, "minLength": 4,
"maxLength": 4 "maxLength": 4
}, },
"hid_pid": { "pid": {
"type": "string", "type": "string",
"title": "USB Keyboard Product ID", "title": "USB Product ID",
"pattern": "^[0-9A-F]{4}$", "pattern": "^[0-9A-F]{4}$",
"default": "11A4", "default": "11A4",
"examples": [ "examples": [
@ -83,28 +83,13 @@
"minLength": 4, "minLength": 4,
"maxLength": 4 "maxLength": 4
}, },
"hid_rev": { "rev": {
"type": "string", "type": "string",
"title": "USB Keyboard Product Revision", "title": "USB Product Revision (0100 => 1.0)",
"default": "0100", "default": "0100",
"minLength": 4, "minLength": 4,
"maxLength": 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": { "default_layout": {
"type": "string", "type": "string",
"title": "Default Keyboard Layout", "title": "Default Keyboard Layout",

View File

@ -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() { void enableDrive() {
usb_msc.setReadWriteCallback(read_cb, write_cb, flush_cb); usb_msc.setReadWriteCallback(read_cb, write_cb, flush_cb);
usb_msc.setCapacity(flash.size() / 512, 512); usb_msc.setCapacity(flash.size() / 512, 512);

View File

@ -9,7 +9,6 @@ namespace msc {
bool format(const char* drive_name = "USB Nova"); bool format(const char* drive_name = "USB Nova");
void print(); void print();
void setID(const char* vid, const char* pid, const char* rev);
void enableDrive(); void enableDrive();
bool changed(); bool changed();
@ -17,7 +16,7 @@ namespace msc {
bool open(const char* path, bool add_to_stack = true); bool open(const char* path, bool add_to_stack = true);
bool openNextFile(); bool openNextFile();
void close(); void close();
uint32_t getPosition(); uint32_t getPosition();

View File

@ -25,13 +25,9 @@ namespace preferences {
bool enable_led; bool enable_led;
bool enable_hid; bool enable_hid;
std::string hid_vid; std::string vid;
std::string hid_pid; std::string pid;
std::string hid_rev; std::string version;
std::string msc_vid; // max. 8 chars
std::string msc_pid; // max. 16 chars
std::string msc_rev; // max. 4 chars
std::string default_layout; std::string default_layout;
int default_delay; int default_delay;
@ -43,7 +39,7 @@ namespace preferences {
int idle_color[4]; int idle_color[4];
bool format; bool format;
std::string drive_name; std::string drive_name;
bool disable_capslock; bool disable_capslock;
bool run_on_indicator; bool run_on_indicator;
@ -53,7 +49,8 @@ namespace preferences {
// Array help functions // Array help functions
void add_array(JsonDocument& doc, const char* name, int* array, int size) { void add_array(JsonDocument& doc, const char* name, int* array, int size) {
JsonArray jarr = doc.createNestedArray(name); 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]); jarr.add(array[i]);
} }
} }
@ -65,13 +62,9 @@ namespace preferences {
root["enable_led"] = enable_led; root["enable_led"] = enable_led;
root["enable_hid"] = enable_hid; root["enable_hid"] = enable_hid;
root["hid_vid"] = hid_vid; root["vid"] = vid;
root["hid_pid"] = hid_pid; root["pid"] = pid;
root["hid_rev"] = hid_rev; root["version"] = version;
root["msc_vid"] = msc_vid;
root["msc_pid"] = msc_pid;
root["msc_rev"] = msc_rev;
root["default_layout"] = default_layout; root["default_layout"] = default_layout;
root["default_delay"] = default_delay; root["default_delay"] = default_delay;
@ -83,14 +76,15 @@ namespace preferences {
add_array(root, "idle_color", idle_color, 4); add_array(root, "idle_color", idle_color, 4);
root["disable_capslock"] = disable_capslock; root["disable_capslock"] = disable_capslock;
root["run_on_indicator"] = run_on_indicator; root["run_on_indicator"] = run_on_indicator;
root["initial_delay"] = initial_delay; root["initial_delay"] = initial_delay;
} }
void read_array(JsonDocument& doc, const char* name, int* array, int size) { void read_array(JsonDocument& doc, const char* name, int* array, int size) {
JsonVariant val = doc[name]; JsonVariant val = doc[name];
if(val.isNull()) return;
if (val.isNull()) return;
JsonArray jarr = val.as<JsonArray>(); JsonArray jarr = val.as<JsonArray>();
@ -99,10 +93,11 @@ namespace preferences {
} }
} }
template <typename T> template<typename T>
void read_item(JsonDocument& doc, const char* name, T& val) { void read_item(JsonDocument& doc, const char* name, T& val) {
JsonVariant new_val = doc[name]; JsonVariant new_val = doc[name];
if(new_val.isNull()) return;
if (new_val.isNull()) return;
val = new_val.as<T>(); val = new_val.as<T>();
} }
@ -134,13 +129,9 @@ namespace preferences {
read_item<bool>(config_doc, "enable_led", enable_led); read_item<bool>(config_doc, "enable_led", enable_led);
read_item<bool>(config_doc, "enable_hid", enable_hid); read_item<bool>(config_doc, "enable_hid", enable_hid);
read_item<std::string>(config_doc, "hid_vid", hid_vid); read_item<std::string>(config_doc, "vid", vid);
read_item<std::string>(config_doc, "hid_pid", hid_pid); read_item<std::string>(config_doc, "pid", pid);
read_item<std::string>(config_doc, "hid_rev", hid_rev); read_item<std::string>(config_doc, "version", version);
read_item<std::string>(config_doc, "msc_vid", msc_vid);
read_item<std::string>(config_doc, "msc_pid", msc_pid);
read_item<std::string>(config_doc, "msc_rev", msc_rev);
read_item<std::string>(config_doc, "default_layout", default_layout); read_item<std::string>(config_doc, "default_layout", default_layout);
read_item<int>(config_doc, "default_delay", default_delay); read_item<int>(config_doc, "default_delay", default_delay);
@ -158,9 +149,9 @@ namespace preferences {
} }
disable_capslock = config_doc["disable_capslock"].as<bool>(); disable_capslock = config_doc["disable_capslock"].as<bool>();
run_on_indicator = config_doc["run_on_indicator"].as<bool>(); run_on_indicator = config_doc["run_on_indicator"].as<bool>();
initial_delay = config_doc["initial_delay"].as<int>(); initial_delay = config_doc["initial_delay"].as<int>();
} }
void save() { void save() {
@ -183,22 +174,18 @@ namespace preferences {
debug("Saved "); debug("Saved ");
debugln(PREFERENCES_PATH); debugln(PREFERENCES_PATH);
} }
void reset() { void reset() {
enable_msc = false; enable_msc = false;
enable_led = true; enable_led = true;
enable_hid = true; enable_hid = true;
hid_vid = "16D0"; vid = "16D0";
hid_pid = "11A4"; pid = "11A4";
hid_rev = "0100"; version = "0100";
msc_vid = "SpHuhn"; // max. 8 chars
msc_pid = "USB Nova"; // max. 16 chars
msc_rev = "1.0"; // max. 4 chars
default_layout = "US"; default_layout = "US";
default_delay = 5; default_delay = 5;
main_script = "main_script.txt"; main_script = "main_script.txt";
@ -217,7 +204,7 @@ namespace preferences {
idle_color[2] = 0; idle_color[2] = 0;
idle_color[3] = 0; idle_color[3] = 0;
format = false; format = false;
drive_name = "USB Nova"; drive_name = "USB Nova";
disable_capslock = true; disable_capslock = true;
@ -225,7 +212,7 @@ namespace preferences {
initial_delay = 1000; initial_delay = 1000;
} }
void print() { void print() {
// Create a new JSON document (and string buffer) // Create a new JSON document (and string buffer)
DynamicJsonDocument json_doc(JSON_SIZE); DynamicJsonDocument json_doc(JSON_SIZE);
@ -255,28 +242,16 @@ namespace preferences {
return enable_hid; return enable_hid;
} }
uint16_t getHidVid() { uint16_t getVID() {
return std::stoi(hid_vid, nullptr, 16); return std::stoi(vid, nullptr, 16);
} }
uint16_t getHidPid() { uint16_t getPID() {
return std::stoi(hid_pid, nullptr, 16); return std::stoi(pid, nullptr, 16);
} }
uint16_t getHidRev() { uint16_t getVersion() {
return std::stoi(hid_rev, nullptr, 16); return std::stoi(version, nullptr, 16);
}
std::string getMscVid() {
return msc_vid;
}
std::string getMscPid() {
return msc_pid;
}
std::string getMscRev() {
return msc_rev;
} }
std::string getDefaultLayout() { std::string getDefaultLayout() {
@ -318,7 +293,7 @@ namespace preferences {
bool getRunOnIndicator() { bool getRunOnIndicator() {
return run_on_indicator; return run_on_indicator;
} }
int getInitialDelay() { int getInitialDelay() {
return initial_delay; return initial_delay;
} }

View File

@ -14,13 +14,9 @@ namespace preferences {
bool ledEnabled(); bool ledEnabled();
bool hidEnabled(); bool hidEnabled();
uint16_t getHidVid(); uint16_t getVID();
uint16_t getHidPid(); uint16_t getPID();
uint16_t getHidRev(); uint16_t getVersion();
std::string getMscVid();
std::string getMscPid();
std::string getMscRev();
std::string getDefaultLayout(); std::string getDefaultLayout();
int getDefaultDelay(); int getDefaultDelay();
@ -33,7 +29,7 @@ namespace preferences {
bool getFormat(); bool getFormat();
std::string getDriveName(); std::string getDriveName();
bool getDisableCapslock(); bool getDisableCapslock();
bool getRunOnIndicator(); bool getRunOnIndicator();