ref: 8d3fade26a10b6fe03f543ded533890c1655c0df
parent: 5df233610e0148f6781c45c81bae74fdc2b1dba4
author: Jonne Kokkonen <jonne.kokkonen@gmail.com>
date: Tue Apr 15 18:12:13 EDT 2025
Refactor display enable function to support optional reset. Renamed `m8_enable_and_reset_display` to `m8_enable_display` with an added parameter to optionally reset the display. Adjusted all function calls and implementations to align with the new signature, improving flexibility and reducing redundant reset operations.
--- a/src/backends/m8.h
+++ b/src/backends/m8.h
@@ -14,7 +14,7 @@
int m8_initialize(int verbose, const char *preferred_device);
int m8_list_devices(void);
int m8_reset_display(void);
-int m8_enable_and_reset_display(void);
+int m8_enable_display(unsigned char reset_display);
int m8_send_msg_controller(unsigned char input);
int m8_send_msg_keyjazz(unsigned char note, unsigned char velocity);
int m8_process_data(const config_params_s *conf);
--- a/src/backends/m8_libserialport.c
+++ b/src/backends/m8_libserialport.c
@@ -342,7 +342,7 @@
return 1;
}
-int m8_enable_and_reset_display() {+int m8_enable_display(const unsigned char reset_display) { SDL_Log("Enabling and resetting M8 display"); const char buf[1] = {'E'};@@ -352,7 +352,9 @@
return 0;
}
- result = m8_reset_display();
+ if (reset_display) {+ result = m8_reset_display();
+ }
return result;
}
--- a/src/backends/m8_libusb.c
+++ b/src/backends/m8_libusb.c
@@ -279,7 +279,7 @@
return 1;
}
-int m8_enable_and_reset_display() {+int m8_enable_display(const unsigned char reset_display) { if (devh == NULL) {return 0;
}
@@ -296,6 +296,7 @@
}
SDL_Delay(5);
+ if ()
result = m8_reset_display();
return result;
}
--- a/src/backends/m8_rtmidi.c
+++ b/src/backends/m8_rtmidi.c
@@ -34,7 +34,7 @@
}
static void midi_decode(const uint8_t *encoded_data, size_t length, uint8_t **decoded_data,
- size_t *decoded_length) {+ size_t *decoded_length) { if (length < m8_sysex_header_size) {// Invalid data
*decoded_data = NULL;
@@ -199,7 +199,6 @@
return !result;
}
-
int m8_initialize(const int verbose, const char *preferred_device) {int m8_midi_port_number = 0;
@@ -230,11 +229,11 @@
return 1;
}
-int m8_enable_and_reset_display(void) {+int m8_enable_display(const unsigned char reset_display) {SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "Sending enable command sysex");
rtmidi_in_set_callback(midi_in, midi_callback, NULL);
const unsigned char enable_sysex[8] = {0xF0, 0x00, 0x02, 0x61, 0x00, 0x00, 'E', 0xF7};- int result = rtmidi_out_send_message(midi_out, &enable_sysex[0], sizeof(enable_sysex));
+ const int result = rtmidi_out_send_message(midi_out, &enable_sysex[0], sizeof(enable_sysex));
if (result != 0) {SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Failed to send remote display enable command");
return 0;
@@ -251,8 +250,10 @@
}
SDL_Delay(5);
}
- result = m8_reset_display();
- return result;
+ if (reset_display) {+ return m8_reset_display();
+ }
+ return 1;
}
int m8_send_msg_controller(const unsigned char input) {--- a/src/main.c
+++ b/src/main.c
@@ -47,7 +47,7 @@
}
}
- const int m8_enabled = m8_enable_and_reset_display();
+ const int m8_enabled = m8_enable_display(0);
// Device was found; enable display and proceed to the main loop
if (m8_enabled == 1) {ctx->app_state = RUN;
@@ -54,6 +54,10 @@
ctx->device_connected = 1;
screensaver_destroy();
screensaver_initialized = 0;
+ //renderer_clear_screen();
+ SDL_Log("Device connected.");+ SDL_Delay(100); // Give the device time to initialize
+ m8_reset_display(); // Avoid display glitches.
} else {SDL_LogCritical(SDL_LOG_CATEGORY_ERROR, "Device not detected.");
ctx->app_state = QUIT;
@@ -178,12 +182,12 @@
ctx->device_connected =
handle_device_initialization(ctx->conf.wait_for_device, ctx->preferred_device);
}
- if (ctx->device_connected && m8_enable_and_reset_display()) {+ if (ctx->device_connected && m8_enable_display(0)) { if (ctx->conf.audio_enabled) {audio_initialize(ctx->conf.audio_device_name, ctx->conf.audio_buffer_size);
- m8_reset_display(); // Avoid display glitches.
}
ctx->app_state = RUN;
+ m8_reset_display(); // Avoid display glitches.
} else {SDL_LogCritical(SDL_LOG_CATEGORY_ERROR, "Device not detected.");
ctx->device_connected = 0;
--- a/src/render.h
+++ b/src/render.h
@@ -31,6 +31,4 @@
void screensaver_draw(void);
void screensaver_destroy(void);
-
-
#endif
--
⑨