VIA V3 - The Custom UI Update (#18222)
This commit is contained in:
parent
575b0e33fa
commit
bc6f8dc8b0
68 changed files with 751 additions and 886 deletions
|
@ -102,113 +102,142 @@ void backlight_set_value( uint8_t *data )
|
|||
}
|
||||
}
|
||||
|
||||
void raw_hid_receive_kb( uint8_t *data, uint8_t length )
|
||||
{
|
||||
uint8_t *command_id = &(data[0]);
|
||||
uint8_t *command_data = &(data[1]);
|
||||
switch ( *command_id )
|
||||
{
|
||||
case id_get_keyboard_value:
|
||||
{
|
||||
switch( command_data[0])
|
||||
{
|
||||
case id_oled_default_mode:
|
||||
{
|
||||
uint8_t default_oled = eeprom_read_byte((uint8_t*)EEPROM_DEFAULT_OLED);
|
||||
command_data[1] = default_oled;
|
||||
break;
|
||||
}
|
||||
case id_oled_mode:
|
||||
{
|
||||
command_data[1] = oled_mode;
|
||||
break;
|
||||
}
|
||||
case id_encoder_modes:
|
||||
{
|
||||
command_data[1] = enabled_encoder_modes;
|
||||
break;
|
||||
}
|
||||
case id_encoder_custom:
|
||||
{
|
||||
uint8_t custom_encoder_idx = command_data[1];
|
||||
uint16_t keycode = retrieve_custom_encoder_config(custom_encoder_idx, ENC_CUSTOM_CW);
|
||||
command_data[2] = keycode >> 8;
|
||||
command_data[3] = keycode & 0xFF;
|
||||
keycode = retrieve_custom_encoder_config(custom_encoder_idx, ENC_CUSTOM_CCW);
|
||||
command_data[4] = keycode >> 8;
|
||||
command_data[5] = keycode & 0xFF;
|
||||
keycode = retrieve_custom_encoder_config(custom_encoder_idx, ENC_CUSTOM_PRESS);
|
||||
command_data[6] = keycode >> 8;
|
||||
command_data[7] = keycode & 0xFF;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
*command_id = id_unhandled;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case id_set_keyboard_value:
|
||||
{
|
||||
switch(command_data[0]){
|
||||
void custom_set_value(uint8_t *data) {
|
||||
uint8_t *value_id = &(data[0]);
|
||||
uint8_t *value_data = &(data[1]);
|
||||
|
||||
switch ( *value_id ) {
|
||||
case id_oled_default_mode:
|
||||
{
|
||||
eeprom_update_byte((uint8_t*)EEPROM_DEFAULT_OLED, command_data[1]);
|
||||
break;
|
||||
eeprom_update_byte((uint8_t*)EEPROM_DEFAULT_OLED, value_data[0]);
|
||||
break;
|
||||
}
|
||||
case id_oled_mode:
|
||||
{
|
||||
oled_mode = command_data[1];
|
||||
oled_request_wakeup();
|
||||
break;
|
||||
oled_mode = value_data[0];
|
||||
oled_request_wakeup();
|
||||
break;
|
||||
}
|
||||
case id_encoder_modes:
|
||||
{
|
||||
enabled_encoder_modes = command_data[1];
|
||||
eeprom_update_byte((uint8_t*)EEPROM_ENABLED_ENCODER_MODES, enabled_encoder_modes);
|
||||
break;
|
||||
uint8_t index = value_data[0];
|
||||
uint8_t enable = value_data[1];
|
||||
enabled_encoder_modes = (enabled_encoder_modes & ~(1<<index)) | (enable<<index);
|
||||
eeprom_update_byte((uint8_t*)EEPROM_ENABLED_ENCODER_MODES, enabled_encoder_modes);
|
||||
break;
|
||||
}
|
||||
case id_encoder_custom:
|
||||
{
|
||||
uint8_t custom_encoder_idx = command_data[1];
|
||||
uint8_t encoder_behavior = command_data[2];
|
||||
uint16_t keycode = (command_data[3] << 8) | command_data[4];
|
||||
set_custom_encoder_config(custom_encoder_idx, encoder_behavior, keycode);
|
||||
break;
|
||||
uint8_t custom_encoder_idx = value_data[0];
|
||||
uint8_t encoder_behavior = value_data[1];
|
||||
uint16_t keycode = (value_data[2] << 8) | value_data[3];
|
||||
set_custom_encoder_config(custom_encoder_idx, encoder_behavior, keycode);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
void custom_get_value(uint8_t *data) {
|
||||
uint8_t *value_id = &(data[0]);
|
||||
uint8_t *value_data = &(data[1]);
|
||||
|
||||
switch ( *value_id ) {
|
||||
case id_oled_default_mode:
|
||||
{
|
||||
*command_id = id_unhandled;
|
||||
break;
|
||||
uint8_t default_oled = eeprom_read_byte((uint8_t*)EEPROM_DEFAULT_OLED);
|
||||
value_data[0] = default_oled;
|
||||
break;
|
||||
}
|
||||
case id_oled_mode:
|
||||
{
|
||||
value_data[0] = oled_mode;
|
||||
break;
|
||||
}
|
||||
case id_encoder_modes:
|
||||
{
|
||||
uint8_t index = value_data[0];
|
||||
value_data[1] = (enabled_encoder_modes & (1<<index)) ? 1 : 0;
|
||||
break;
|
||||
}
|
||||
case id_encoder_custom:
|
||||
{
|
||||
uint8_t custom_encoder_idx = value_data[0];
|
||||
uint8_t encoder_behavior = value_data[1];
|
||||
uint16_t keycode = retrieve_custom_encoder_config(custom_encoder_idx, encoder_behavior);
|
||||
value_data[2] = keycode >> 8;
|
||||
value_data[3] = keycode & 0xFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case id_lighting_set_value:
|
||||
{
|
||||
backlight_set_value(command_data);
|
||||
break;
|
||||
}
|
||||
|
||||
// TODO
|
||||
// Refactor so this keyboard uses QMK Core backlight code,
|
||||
// then change this to via_custom_value_command_kb() so it
|
||||
// only handles the custom values not the backlight
|
||||
// (i.e. use QMK Core default handler for backlight values).
|
||||
//
|
||||
void via_custom_value_command(uint8_t *data, uint8_t length) {
|
||||
uint8_t *command_id = &(data[0]);
|
||||
uint8_t *channel_id = &(data[1]);
|
||||
uint8_t *value_id_and_data = &(data[2]);
|
||||
|
||||
if ( *channel_id == id_qmk_backlight_channel ) {
|
||||
switch ( *command_id )
|
||||
{
|
||||
case id_custom_set_value:
|
||||
{
|
||||
backlight_set_value(value_id_and_data);
|
||||
break;
|
||||
}
|
||||
case id_custom_get_value:
|
||||
{
|
||||
backlight_get_value(value_id_and_data);
|
||||
break;
|
||||
}
|
||||
case id_custom_save:
|
||||
{
|
||||
backlight_config_save();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
// Unhandled message.
|
||||
*command_id = id_unhandled;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if ( *channel_id == id_custom_channel ) {
|
||||
switch ( *command_id )
|
||||
{
|
||||
case id_custom_set_value:
|
||||
{
|
||||
custom_set_value(value_id_and_data);
|
||||
break;
|
||||
}
|
||||
case id_custom_get_value:
|
||||
{
|
||||
custom_get_value(value_id_and_data);
|
||||
break;
|
||||
}
|
||||
case id_custom_save:
|
||||
{
|
||||
// values are saved in custom_set_value()
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
// Unhandled message.
|
||||
*command_id = id_unhandled;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
case id_lighting_get_value:
|
||||
{
|
||||
backlight_get_value(command_data);
|
||||
break;
|
||||
}
|
||||
case id_lighting_save:
|
||||
{
|
||||
backlight_config_save();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
// Unhandled message.
|
||||
*command_id = id_unhandled;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// DO NOT call raw_hid_send(data,length) here, let caller do this
|
||||
|
||||
*command_id = id_unhandled;
|
||||
|
||||
// DO NOT call raw_hid_send(data,length) here, let caller do this
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue