- // }
-
-}
-
-uint32_t decode_uint32_chunk(uint8_t * data) {
- uint32_t part1 = *data++;
- uint32_t part2 = *data++;
- uint32_t part3 = *data++;
- uint32_t part4 = *data++;
- uint32_t part5 = *data++;
- return ((part1 & 0x1FUL) << 28) | (part2 << 21) | (part3 << 14) | (part4 << 7) | part5;
-}
-
-uint32_t decode_uint8_chunk(uint8_t * data) {
- uint32_t part4 = *data++;
- uint32_t part5 = *data++;
- return (part4 << 7) | part5;
-}
-
-void encode_uint32_chunk(uint32_t data, uint8_t * pointer) {
- *pointer++ = (data >> 28) & 0x7F;
- *pointer++ = (data >> 21) & 0x7F;
- *pointer++ = (data >> 14) & 0x7F;
- *pointer++ = (data >> 7) & 0x7F;
- *pointer++ = (data) & 0x7F;
-}
-
-void encode_uint8_chunk(uint8_t data, uint8_t * pointer) {
- *pointer++ = (data >> 7) & 0x7F;
- *pointer++ = (data) & 0x7F;
-}
-
-void sysex_buffer_callback(MidiDevice * device, uint8_t length, uint8_t * data) {
- uint8_t * pointer_copy = data;
-
- if (*data++ != 0xF0)
- return
- data++;
- data++;
- data++;
- data++;
-
- switch (*data++) {
- case 0x07: ; // Quantum action
- break;
- case 0x08: ; // Keyboard acion
- break;
- case 0x09: ; // User action
- break;
- case 0x12: ; // Set info on keyboard
- switch (*data++) {
- case 0x02: ; // set default layer
- uint8_t default_layer = decode_uint8_chunk(data);
- eeconfig_update_default_layer(default_layer);
- default_layer_set((uint32_t)default_layer);
- break;
- case 0x08: ; // set keymap options
- uint8_t keymap_options = decode_uint8_chunk(data);
- eeconfig_update_keymap(keymap_options);
- break;
- }
- break;
- case 0x13: ; // Get info from keyboard
- switch (*data++) {
- case 0x00: ; // Handshake
- send_bytes_sysex(0x00, NULL, 0);
- break;
- case 0x01: ; // Get debug state
- uint8_t debug[2];
- encode_uint8_chunk(eeprom_read_byte(EECONFIG_DEBUG), &debug);
- send_bytes_sysex(0x01, &debug, 2);
- break;
- case 0x02: ; // Get default layer
- uint8_t default_layer[2];
- encode_uint8_chunk(eeprom_read_byte(EECONFIG_DEFAULT_LAYER), &default_layer);
- send_bytes_sysex(0x02, &default_layer, 2);
- break;
- #ifdef AUDIO_ENABLE
- case 0x03: ; // Get backlight state
- uint8_t audio[2];
- encode_uint8_chunk(eeprom_read_byte(EECONFIG_AUDIO), &audio);
- send_bytes_sysex(0x03, &audio, 2);
- #endif
- case 0x04: ; // Get layer state
- uint8_t layers[5];
- encode_uint32_chunk(layer_state, &layers);
- send_bytes_sysex(0x04, &layers, 5);
- break;
- #ifdef BACKLIGHT_ENABLE
- case 0x06: ; // Get backlight state
- uint8_t backlight[2];
- encode_uint8_chunk(eeprom_read_byte(EECONFIG_BACKLIGHT), &backlight);
- send_bytes_sysex(0x06, &backlight, 2);
- #endif
- #ifdef RGBLIGHT_ENABLE
- case 0x07: ; // Get rgblight state
- uint8_t rgblight[2];
- encode_uint32_chunk(eeprom_read_dword(EECONFIG_RGBLIGHT), &rgblight);
- send_bytes_sysex(0x07, &rgblight, 5);
- #endif
- case 0x08: ; // Keymap options
- uint8_t keymap_options[2];
- encode_uint8_chunk(eeconfig_read_keymap(), &keymap_options);
- send_bytes_sysex(0x08, &keymap_options, 2);
- break;
- }
- break;
- #ifdef RGBLIGHT_ENABLE
- case 0x27: ; // RGB LED functions
- switch (*data++) {
- case 0x00: ; // Update HSV
- uint32_t hsv = decode_uint32_chunk(data);
- rgblight_sethsv(((hsv >> 16) & 0xFFFF) % 360, (hsv >> 8) & 0xFF, hsv & 0xFF);
- break;
- case 0x01: ; // Update RGB
- break;
- case 0x02: ; // Update mode
- uint8_t rgb_mode = decode_uint8_chunk(data);
- rgblight_mode(rgb_mode);
- break;
- }
- break;
- #endif
- }
-
- // SEND_STRING("\nDATA:\n");
- // while (*pointer_copy != 0xF7) {
- // send_byte(*pointer_copy++);
- // SEND_STRING(" ");
- // }
-
-}
-
-void send_unicode_midi(uint32_t unicode) {
- uint8_t chunk[5];
- encode_uint32_chunk(unicode, &chunk);
- send_bytes_sysex(0x05, &chunk, 5);