qmk_settings: retrieve supported settings

This commit is contained in:
Ilya Zhuravlev 2021-07-01 15:10:05 -04:00
parent 2affa3ac05
commit 2848a74f62
3 changed files with 23 additions and 0 deletions

View File

@ -64,6 +64,26 @@ void qmk_settings_reset(void) {
save_settings();
}
void qmk_settings_query(uint16_t qsid_gt, void *buffer, size_t sz) {
/* set all FFs, so caller can identify when all settings are retrieved by looking for an 0xFFFF entry */
memset(buffer, 0xFF, sz);
size_t buffer_offset = 0;
for (size_t i = 0; i < sizeof(protos)/sizeof(*protos); ++i) {
uint16_t qsid;
/* if output buffer has no space left, bail out */
if (buffer_offset + sizeof(qsid) > sz)
break;
qsid = pgm_read_word(&protos[i].qsid);
if (qsid > qsid_gt) {
memcpy((char*)buffer + buffer_offset, &qsid, sizeof(qsid));
buffer_offset += sizeof(qsid);
}
}
}
int qmk_settings_get(uint16_t qsid, void *setting, size_t maxsz) {
const qmk_settings_proto_t *proto = find_setting(qsid);
if (!proto || pgm_read_word(&proto->sz) > maxsz)

View File

@ -58,6 +58,7 @@ typedef struct {
void qmk_settings_init(void);
void qmk_settings_reset(void);
void qmk_settings_query(uint16_t qsid_gt, void *buffer, size_t sz);
int qmk_settings_get(uint16_t qsid, void *setting, size_t maxsz);
int qmk_settings_set(uint16_t qsid, const void *setting, size_t maxsz);

View File

@ -165,6 +165,8 @@ void vial_handle_cmd(uint8_t *msg, uint8_t length) {
break;
}
case vial_qmk_settings_query: {
uint16_t qsid_greater_than = msg[2] | (msg[3] << 8);
qmk_settings_query(qsid_greater_than, msg, length);
break;
}
case vial_qmk_settings_get: {