api_sysex.c 1.0 KB

1234567891011121314151617181920212223242526272829
  1. #include "api_sysex.h"
  2. void send_bytes_sysex(uint8_t message_type, uint8_t data_type, uint8_t * bytes, uint16_t length) {
  3. // SEND_STRING("\nTX: ");
  4. // for (uint8_t i = 0; i < length; i++) {
  5. // send_byte(bytes[i]);
  6. // SEND_STRING(" ");
  7. // }
  8. uint8_t * precode = malloc(sizeof(uint8_t) * (length + 2));
  9. precode[0] = message_type;
  10. precode[1] = data_type;
  11. memcpy(precode + 2, bytes, length);
  12. uint8_t * encoded = malloc(sizeof(uint8_t) * (sysex_encoded_length(length + 2)));
  13. uint16_t encoded_length = sysex_encode(encoded, precode, length + 2);
  14. uint8_t * array = malloc(sizeof(uint8_t) * (encoded_length + 5));
  15. array[0] = 0xF0;
  16. array[1] = 0x00;
  17. array[2] = 0x00;
  18. array[3] = 0x00;
  19. array[encoded_length + 4] = 0xF7;
  20. memcpy(array + 4, encoded, encoded_length);
  21. midi_send_array(&midi_device, encoded_length + 5, array);
  22. // SEND_STRING("\nTD: ");
  23. // for (uint8_t i = 0; i < encoded_length + 5; i++) {
  24. // send_byte(array[i]);
  25. // SEND_STRING(" ");
  26. // }
  27. }