Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfixes #108

Merged
merged 3 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ int audio_init(int audio_buffer_size, const char* output_device_name) {
int m8_device_id = -1;
int devcount_in = 0; // audio input device count

// wait for system to initialize possible new audio devices
SDL_Delay(500);

devcount_in = SDL_GetNumAudioDevices(SDL_TRUE);

if (devcount_in < 1) {
Expand All @@ -26,6 +29,7 @@ int audio_init(int audio_buffer_size, const char* output_device_name) {
} else {
for (i = 0; i < devcount_in; i++) {
// Check if input device exists before doing anything else
SDL_LogDebug(SDL_LOG_CATEGORY_AUDIO, "%s", SDL_GetAudioDeviceName(i, SDL_TRUE));
if (SDL_strstr(SDL_GetAudioDeviceName(i, SDL_TRUE), "M8") != NULL) {
SDL_Log("M8 Audio Input device found: %s",
SDL_GetAudioDeviceName(i, SDL_TRUE));
Expand Down
5 changes: 4 additions & 1 deletion fx_cube.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <SDL.h>
#include "SDL2_inprint.h"
#include "SDL_pixels.h"

#define target_width 320
#define target_height 240
Expand Down Expand Up @@ -66,6 +67,8 @@ void fx_cube_init(SDL_Renderer *target_renderer, SDL_Color foreground_color) {
SDL_Texture *og_target = SDL_GetRenderTarget(fx_renderer);

SDL_SetRenderTarget(fx_renderer, texture_text);
SDL_SetRenderDrawColor(fx_renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(fx_renderer);

inprint(fx_renderer, text_disconnected, 168, 230, 0xFFFFFF, 0x000000);
inprint(fx_renderer, text_m8c, 2, 2, 0xFFFFFF, 0x000000);
Expand Down Expand Up @@ -93,7 +96,7 @@ void fx_cube_update() {
SDL_Texture *og_texture = SDL_GetRenderTarget(fx_renderer);

SDL_SetRenderTarget(fx_renderer, texture_cube);
SDL_SetRenderDrawColor(fx_renderer, 0, 0, 0, 200);
SDL_SetRenderDrawColor(fx_renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(fx_renderer);

int seconds = SDL_GetTicks() / 1000;
Expand Down
9 changes: 7 additions & 2 deletions input.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <SDL.h>
#include <stdio.h>

#include "SDL_timer.h"
#include "config.h"
#include "input.h"
#include "render.h"
Expand Down Expand Up @@ -392,8 +393,12 @@ void handle_sdl_events(config_params_s *conf) {
case SDL_WINDOWEVENT:
if (event.window.event == SDL_WINDOWEVENT_RESIZED)
{
SDL_Log("Resizing window...");
key = (input_msg_s){special, msg_reset_display};
static uint32_t ticks_window_resized = 0;
if (SDL_GetTicks() - ticks_window_resized > 500) {
SDL_Log("Resizing window...");
key = (input_msg_s){special, msg_reset_display};
ticks_window_resized = SDL_GetTicks();
}
}
break;

Expand Down
5 changes: 3 additions & 2 deletions input.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define INPUT_H_

#include <stdint.h>
#include "config.h"

typedef enum input_buttons_t {
INPUT_UP,
Expand Down Expand Up @@ -38,6 +39,6 @@ typedef struct input_msg_s {

int initialize_game_controllers();
void close_game_controllers();
input_msg_s get_input_msg();
input_msg_s get_input_msg(config_params_s *conf);

#endif
#endif
10 changes: 7 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ int main(int argc, char *argv[]) {
if (run == WAIT_FOR_DEVICE && init_serial(0) == 1) {

if (conf.audio_enabled == 1) {
if (audio_init(conf.audio_buffer_size, conf.audio_device_name) == 0) {
SDL_Log("Cannot initialize audio, exiting.");
run = QUIT;
if (audio_init(conf.audio_buffer_size, conf.audio_device_name) ==
0) {
SDL_Log("Cannot initialize audio");
conf.audio_enabled = 0;
}
}

Expand Down Expand Up @@ -251,6 +252,9 @@ int main(int argc, char *argv[]) {
port_inited = 0;
run = WAIT_FOR_DEVICE;
close_serial_port();
if (conf.audio_enabled == 1) {
audio_destroy();
}
/* we'll make one more loop to see if the device is still there
* but just sending zero bytes. if it doesn't get detected when
* resetting the port, it will disconnect */
Expand Down