]> git.donarmstrong.com Git - qmk_firmware.git/blob - quantum/api/api_sysex.c
Merge remote-tracking branch 'upstream/master'
[qmk_firmware.git] / quantum / api / api_sysex.c
1 #include "api_sysex.h"
2
3 void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t * bytes, uint16_t length) {
4     // SEND_STRING("\nTX: ");
5     // for (uint8_t i = 0; i < length; i++) {
6     //     send_byte(bytes[i]);
7     //     SEND_STRING(" ");
8     // }
9     uint8_t * precode = malloc(sizeof(uint8_t) * (length + 2));
10     precode[0] = message_type;
11     precode[1] = data_type;
12     memcpy(precode + 2, bytes, length);
13     uint8_t * encoded = malloc(sizeof(uint8_t) * (sysex_encoded_length(length + 2)));
14     uint16_t encoded_length = sysex_encode(encoded, precode, length + 2);
15     uint8_t * array = malloc(sizeof(uint8_t) * (encoded_length + 5));
16     array[0] = 0xF0;
17     array[1] = 0x00;
18     array[2] = 0x00;
19     array[3] = 0x00;
20     array[encoded_length + 4] = 0xF7;
21     memcpy(array + 4, encoded, encoded_length);
22     midi_send_array(&midi_device, encoded_length + 5, array);
23
24     // SEND_STRING("\nTD: ");
25     // for (uint8_t i = 0; i < encoded_length + 5; i++) {
26     //     send_byte(array[i]);
27     //     SEND_STRING(" ");
28     // }
29 }