mirror of
https://github.com/raphnet/gc_n64_usb-v3
synced 2024-12-21 23:08:53 -05:00
Simplify config code and add disable triggers feature
This commit is contained in:
parent
5328827234
commit
95d6b2ec15
85
config.c
85
config.c
@ -42,8 +42,40 @@ static void config_set_serial(char serial[SERIAL_NUM_LEN])
|
||||
eeprom_commit();
|
||||
}
|
||||
|
||||
struct paramAndFlag {
|
||||
uint8_t param; // CFG_PARAM_* (requests.h)
|
||||
uint32_t flag; // FLAG_* (config.h)
|
||||
};
|
||||
|
||||
static struct paramAndFlag paramsAndFlags[] = {
|
||||
{ CFG_PARAM_INVERT_TRIG, FLAG_GC_INVERT_TRIGS },
|
||||
{ CFG_PARAM_FULL_SLIDERS, FLAG_GC_FULL_SLIDERS },
|
||||
{ CFG_PARAM_TRIGGERS_AS_BUTTONS, FLAG_GC_SLIDERS_AS_BUTTONS },
|
||||
{ CFG_PARAM_DISABLE_ANALOG_TRIGGERS, FLAG_DISABLE_ANALOG_TRIGGERS },
|
||||
|
||||
{ },
|
||||
};
|
||||
|
||||
uint8_t config_getSupportedParams(uint8_t *dst)
|
||||
{
|
||||
uint8_t n = 0, i;
|
||||
|
||||
dst[n++] = CFG_PARAM_MODE;
|
||||
dst[n++] = CFG_PARAM_SERIAL;
|
||||
for (i=0; i<NUM_CHANNELS; i++) {
|
||||
dst[n++] = CFG_PARAM_POLL_INTERVAL0 + i;
|
||||
}
|
||||
for (i=0; paramsAndFlags[i].flag; i++) {
|
||||
dst[n++] = paramsAndFlags[i].param;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
unsigned char config_getParam(unsigned char param, unsigned char *value, unsigned char max_len)
|
||||
{
|
||||
int i;
|
||||
|
||||
switch (param)
|
||||
{
|
||||
case CFG_PARAM_MODE:
|
||||
@ -70,22 +102,23 @@ unsigned char config_getParam(unsigned char param, unsigned char *value, unsigne
|
||||
*value = g_eeprom_data.cfg.poll_interval[3];
|
||||
return 1;
|
||||
#endif
|
||||
case CFG_PARAM_INVERT_TRIG:
|
||||
*value = (g_eeprom_data.cfg.flags & FLAG_GC_INVERT_TRIGS) ? 1 : 0;
|
||||
return 1;
|
||||
case CFG_PARAM_FULL_SLIDERS:
|
||||
*value = (g_eeprom_data.cfg.flags & FLAG_GC_FULL_SLIDERS) ? 1 : 0;
|
||||
return 1;
|
||||
case CFG_PARAM_TRIGGERS_AS_BUTTONS:
|
||||
*value = (g_eeprom_data.cfg.flags & FLAG_GC_SLIDERS_AS_BUTTONS) ? 1 : 0;
|
||||
|
||||
default:
|
||||
for (i=0; paramsAndFlags[i].flag; i++) {
|
||||
if (param == paramsAndFlags[i].param) {
|
||||
*value = (g_eeprom_data.cfg.flags & paramsAndFlags[i].flag) ? 1 : 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned char config_setParam(unsigned char param, const unsigned char *value)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!value)
|
||||
return 0;
|
||||
|
||||
@ -115,29 +148,25 @@ unsigned char config_setParam(unsigned char param, const unsigned char *value)
|
||||
g_eeprom_data.cfg.poll_interval[3] = value[0];
|
||||
break;
|
||||
#endif
|
||||
case CFG_PARAM_FULL_SLIDERS:
|
||||
if (value[0]) {
|
||||
g_eeprom_data.cfg.flags |= FLAG_GC_FULL_SLIDERS;
|
||||
} else {
|
||||
g_eeprom_data.cfg.flags &= ~FLAG_GC_FULL_SLIDERS;
|
||||
}
|
||||
break;
|
||||
case CFG_PARAM_INVERT_TRIG:
|
||||
if (value[0]) {
|
||||
g_eeprom_data.cfg.flags |= FLAG_GC_INVERT_TRIGS;
|
||||
} else {
|
||||
g_eeprom_data.cfg.flags &= ~FLAG_GC_INVERT_TRIGS;
|
||||
}
|
||||
break;
|
||||
case CFG_PARAM_TRIGGERS_AS_BUTTONS:
|
||||
if (value[0]) {
|
||||
g_eeprom_data.cfg.flags |= FLAG_GC_SLIDERS_AS_BUTTONS;
|
||||
} else {
|
||||
g_eeprom_data.cfg.flags &= ~FLAG_GC_SLIDERS_AS_BUTTONS;
|
||||
}
|
||||
|
||||
default:
|
||||
for (i=0; paramsAndFlags[i].flag; i++) {
|
||||
if (param == paramsAndFlags[i].param) {
|
||||
if (value[0]) {
|
||||
g_eeprom_data.cfg.flags |= paramsAndFlags[i].flag;
|
||||
} else {
|
||||
g_eeprom_data.cfg.flags &= ~paramsAndFlags[i].flag;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if we made it through the list without finding
|
||||
// a matching parameter, do nothing.
|
||||
if (!paramsAndFlags[i].flag) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
eeprom_commit();
|
||||
|
||||
|
3
config.h
3
config.h
@ -13,6 +13,7 @@ struct eeprom_cfg {
|
||||
#define FLAG_GC_FULL_SLIDERS 1
|
||||
#define FLAG_GC_INVERT_TRIGS 2
|
||||
#define FLAG_GC_SLIDERS_AS_BUTTONS 4
|
||||
#define FLAG_DISABLE_ANALOG_TRIGGERS 8
|
||||
|
||||
void eeprom_app_write_defaults(void);
|
||||
void eeprom_app_ready(void);
|
||||
@ -20,4 +21,6 @@ void eeprom_app_ready(void);
|
||||
unsigned char config_setParam(unsigned char param, const unsigned char *value);
|
||||
unsigned char config_getParam(unsigned char param, unsigned char *value, unsigned char max_len);
|
||||
|
||||
uint8_t config_getSupportedParams(uint8_t *dst);
|
||||
|
||||
#endif
|
||||
|
@ -39,5 +39,6 @@
|
||||
#define CFG_PARAM_INVERT_TRIG 0x24
|
||||
#define CFG_PARAM_TRIGGERS_AS_BUTTONS 0x25
|
||||
|
||||
#define CFG_PARAM_DISABLE_ANALOG_TRIGGERS 0x32
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user