Skip to content

Commit ecacbe6

Browse files
committed
fixed more issues
1 parent 1cbf545 commit ecacbe6

File tree

10 files changed

+104
-46
lines changed

10 files changed

+104
-46
lines changed

lib/gamepad/audio.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ static void *handle_queued_audio(void *data)
124124
}
125125

126126
pthread_mutex_unlock(&queued_audio_mutex);
127+
128+
return 0;
127129
}
128130

129131
void handle_audio_packet(gamepad_context_t *ctx, unsigned char *data, size_t len)
@@ -160,8 +162,6 @@ void handle_audio_packet(gamepad_context_t *ctx, unsigned char *data, size_t len
160162

161163
uint8_t vibrate_val = ap->vibrate;
162164
push_event(ctx->event_loop, VANILLA_EVENT_VIBRATE, &vibrate_val, sizeof(vibrate_val));
163-
164-
handle_queued_audio(ctx);
165165
}
166166

167167
void *listen_audio(void *x)
@@ -191,7 +191,10 @@ void *listen_audio(void *x)
191191
} while (!is_interrupted());
192192

193193
if (mic_thread_created) {
194+
// Tell thread to exit
195+
pthread_mutex_lock(&queued_audio_mutex);
194196
pthread_cond_broadcast(&queued_audio_cond);
197+
pthread_mutex_unlock(&queued_audio_mutex);
195198
pthread_join(mic_thread, 0);
196199
}
197200

lib/gamepad/command.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,13 @@ void handle_generic_packet(gamepad_context_t *info, int skt, GenericPacket *requ
191191
send_generic_response(skt, (CmdHeader *) &response);
192192
}
193193

194-
void handle_uac_uvc_packet(int skt, UvcUacPacket *request)
194+
void handle_uac_uvc_packet(gamepad_context_t *info, int skt, UvcUacPacket *request)
195195
{
196196
vanilla_log("uac/uvc - mic_enable: %u, mic_freq: %u, mic_mute: %u, mic_volume: %i, mic_volume2: %i", request->uac_uvc.mic_enable, request->uac_uvc.mic_freq, request->uac_uvc.mic_mute, request->uac_uvc.mic_volume, request->uac_uvc.mic_volume_2);
197197

198+
uint8_t mic_enabled = request->uac_uvc.mic_enable;
199+
push_event(info->event_loop, VANILLA_EVENT_MIC, &mic_enabled, sizeof(mic_enabled));
200+
198201
print_hex(&request->uac_uvc, sizeof(request->uac_uvc));
199202
vanilla_log_no_newline("\n");
200203

@@ -238,7 +241,7 @@ void handle_command_packet(gamepad_context_t *info, int skt, CmdHeader *request)
238241
}
239242
case CMD_UVC_UAC:
240243
{
241-
handle_uac_uvc_packet(skt, (UvcUacPacket *)request);
244+
handle_uac_uvc_packet(info, skt, (UvcUacPacket *)request);
242245
break;
243246
}
244247
case CMD_TIME:

lib/vanilla.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ enum VanillaEvent
7474
VANILLA_EVENT_AUDIO,
7575
VANILLA_EVENT_VIBRATE,
7676
VANILLA_EVENT_SYNC,
77-
VANILLA_EVENT_ERROR
77+
VANILLA_EVENT_ERROR,
78+
VANILLA_EVENT_MIC
7879
};
7980

8081
enum VanillaRegion

pipe/linux/wpa.c

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ void *wpa_setup_environment(void *data)
223223
interface.driver = "nl80211";
224224
interface.ifname = args->wireless_interface;
225225
interface.confname = args->wireless_config;
226-
226+
227227
struct wpa_global *wpa = wpa_supplicant_init(&params);
228228
if (!wpa) {
229229
nlprint("FAILED TO INIT WPA SUPPLICANT");
@@ -329,7 +329,7 @@ void dhcp_callback(const char *type, char **env, void *data)
329329

330330
// Send request
331331
nl_send_auto_complete(nl, msg);
332-
332+
333333
// Cleanup
334334
nlmsg_free(msg);
335335
rtnl_addr_put(ra);
@@ -359,7 +359,7 @@ int call_dhcp(const char *network_interface)
359359
nlprint("FAILED TO ALLOC NL_SOCK");
360360
goto exit;
361361
}
362-
362+
363363
int nlr = nl_connect(nl, NETLINK_ROUTE);
364364
if (nlr < 0) {
365365
nlprint("FAILED TO CONNECT NL: %i", nlr);
@@ -448,7 +448,7 @@ int open_socket(int local, in_port_t port)
448448
struct timeval tv = {0};
449449
tv.tv_usec = 250000;
450450
setsockopt(skt, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
451-
451+
452452
if (bind(skt, (const struct sockaddr *) &sa, sa_size) == -1) {
453453
nlprint("FAILED TO BIND PORT %u: %i", port, errno);
454454
close(skt);
@@ -540,7 +540,7 @@ void create_all_relays(struct sync_args *args)
540540
vid_info.local = aud_info.local = msg_info.local = cmd_info.local = hid_info.local = args->local;
541541
vid_info.client = aud_info.client = msg_info.client = cmd_info.client = hid_info.client = args->client;
542542
vid_info.client_size = aud_info.client_size = msg_info.client_size = cmd_info.client_size = hid_info.client_size = args->client_size;
543-
543+
544544
vid_info.port = PORT_VID;
545545
aud_info.port = PORT_AUD;
546546
msg_info.port = PORT_MSG;
@@ -565,7 +565,7 @@ void create_all_relays(struct sync_args *args)
565565
char buf[1024];
566566
size_t buf_len = sizeof(buf);
567567
if (wpa_ctrl_recv(args->ctrl, buf, &buf_len) == 0) {
568-
if (!memcmp(buf, "<3>CTRL-EVENT-DISCONNECTED", 26)) {
568+
if (strstr(buf, "CTRL-EVENT-DISCONNECTED")) {
569569
nlprint("Wii U disconnected, attempting to re-connect...");
570570

571571
// Let client know we lost connection
@@ -596,14 +596,14 @@ void *thread_handler(void *data)
596596
pthread_mutex_unlock(&running_mutex);
597597

598598
void *ret = args->start_routine(data);
599-
599+
600600
free(args);
601601

602602
interrupt();
603603

604604
// Locked by calling thread
605605
pthread_mutex_unlock(&action_mutex);
606-
606+
607607
return ret;
608608
}
609609

@@ -679,7 +679,7 @@ void bytes_to_str(unsigned char *data, size_t data_size, const char *separator,
679679
}
680680

681681
int create_connect_config(const char *filename, unsigned char *bssid, unsigned char *psk)
682-
{
682+
{
683683
FILE *out_file = fopen(filename, "w");
684684
if (!out_file) {
685685
nlprint("FAILED TO OPEN OUTPUT CONFIG FILE");
@@ -703,7 +703,7 @@ int create_connect_config(const char *filename, unsigned char *bssid, unsigned c
703703
" pbss=2\n"
704704
"}\n"
705705
"\n";
706-
706+
707707
char bssid_str[18];
708708
char ssid_str[17];
709709
char psk_str[65];
@@ -821,7 +821,7 @@ void *sync_with_console_internal(void *data)
821821
nlprint("CRED RECV: %.*s", buf_len, buf);
822822
}
823823

824-
if (!memcmp("<3>WPS-CRED-RECEIVED", buf, 20)) {
824+
if (strstr("WPS-SUCCESS", buf)) {
825825
nlprint("RECEIVED AUTHENTICATION FROM CONSOLE");
826826
cred_received = 1;
827827
break;
@@ -883,27 +883,27 @@ void *do_connect(void *data)
883883
while (!wpa_ctrl_pending(args->ctrl)) {
884884
sleep(2);
885885
nlprint("WAITING FOR CONNECTION");
886-
886+
887887
if (is_interrupted()) return THREADRESULT(VANILLA_ERR_GENERIC);
888888
}
889-
889+
890890
char buf[1024];
891891
size_t actual_buf_len = sizeof(buf);
892892
wpa_ctrl_recv(args->ctrl, buf, &actual_buf_len);
893893
if (!strstr(buf, "CTRL-EVENT-BSS-ADDED")
894894
&& !strstr(buf, "CTRL-EVENT-BSS-REMOVED")) {
895895
nlprint("CONN RECV: %.*s", actual_buf_len, buf);
896896
}
897-
898-
if (memcmp(buf, "<3>CTRL-EVENT-CONNECTED", 23) == 0) {
897+
898+
if (strstr(buf, "CTRL-EVENT-CONNECTED") == 0) {
899899
break;
900900
}
901-
901+
902902
if (is_interrupted()) return THREADRESULT(VANILLA_ERR_GENERIC);
903903
}
904-
904+
905905
nlprint("CONNECTED TO CONSOLE");
906-
906+
907907
// Use DHCP on interface
908908
int r = call_dhcp(args->wireless_interface);
909909
if (r != VANILLA_SUCCESS) {
@@ -912,7 +912,7 @@ void *do_connect(void *data)
912912
} else {
913913
nlprint("DHCP ESTABLISHED");
914914
}
915-
915+
916916
create_all_relays(args);
917917
}
918918

@@ -1015,7 +1015,7 @@ void pipe_listen(int local, const char *wireless_interface, const char *log_file
10151015
memcpy(args->psk, cmd.connection.psk.psk, sizeof(cmd.connection.psk.psk));
10161016
args->start_routine = vanilla_connect_to_console;
10171017
}
1018-
1018+
10191019
// Acknowledge
10201020
cmd.control_code = VANILLA_PIPE_CC_BIND_ACK;
10211021
if (sendto(skt, &cmd, sizeof(cmd.control_code), 0, (const struct sockaddr *) &addr, addr_size) == -1) {
@@ -1065,4 +1065,4 @@ void pipe_listen(int local, const char *wireless_interface, const char *log_file
10651065
int vanilla_has_config()
10661066
{
10671067
return (access(get_wireless_connect_config_filename(), F_OK) == 0);
1068-
}
1068+
}

rpi/game/game_main.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ void *vpi_event_handler(void *data)
7373
case VANILLA_EVENT_ERROR:
7474
vpi_game_set_error(*(int *)event.data);
7575
break;
76+
case VANILLA_EVENT_MIC:
77+
vui_mic_enabled_set(vui, event.data[0]);
78+
break;
7679
}
7780

7881
vanilla_free_event(&event);
@@ -101,7 +104,7 @@ void vpi_show_toast(const char *message)
101104
vui_strncpy(vpi_toast_string, message, sizeof(vpi_toast_string));
102105

103106
gettimeofday(&vpi_toast_expiry, 0);
104-
107+
105108
// Toast lasts for 2 seconds
106109
vpi_toast_expiry.tv_sec += 2;
107110

@@ -116,7 +119,7 @@ void vpi_get_toast(int *number, char *output, size_t output_size, struct timeval
116119

117120
if (number)
118121
*number = vpi_toast_number;
119-
122+
120123
if (output && output_size) {
121124
vui_strncpy(output, vpi_toast_string, output_size);
122125
}
@@ -126,4 +129,4 @@ void vpi_get_toast(int *number, char *output, size_t output_size, struct timeval
126129
}
127130

128131
pthread_mutex_unlock(&vpi_toast_mutex);
129-
}
132+
}

rpi/menu/menu.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@
1313
#include "menu_main.h"
1414
#include "platform.h"
1515

16+
void vpi_mic_callback(void *userdata, const uint8_t *data, size_t len)
17+
{
18+
vanilla_send_audio(data, len);
19+
}
20+
1621
void vpi_menu_init(vui_context_t *vui)
1722
{
23+
// Set microphone callback
24+
vui_mic_callback_set(vui, vpi_mic_callback, 0);
25+
1826
// Start with main menu
1927
vpi_menu_main(vui, 0);
2028
}
@@ -64,4 +72,4 @@ void vpi_menu_action(vui_context_t *vui, vpi_extra_action_t action)
6472
break;
6573
}
6674
}
67-
}
75+
}

rpi/ui/ui.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ vui_context_t *vui_alloc(int width, int height)
2525
vui->font_height_handler = 0;
2626
vui->text_open_handler = 0;
2727
vui->power_state_handler = 0;
28+
vui->mic_callback = 0;
29+
vui->mic_enabled_handler = 0;
2830
vui->quit = 0;
2931
vui_reset(vui);
3032
return vui;
@@ -372,7 +374,7 @@ void vui_process_mousedown(vui_context_t *ctx, int x, int y)
372374
if (!button_pressed) {
373375
for (int i = 0; i < ctx->textedit_count; i++) {
374376
vui_textedit_t *edit = &ctx->textedits[i];
375-
377+
376378
if (edit->visible && edit->enabled && point_inside_textedit(edit, x, y)) {
377379
new_active_textedit = i;
378380
break;
@@ -403,7 +405,7 @@ void vui_process_mouseup(vui_context_t *ctx, int x, int y)
403405
// No button was mousedown'd, do nothing here
404406
return;
405407
}
406-
408+
407409
release_button(ctx, point_inside_button(&ctx->buttons[ctx->button_active], x, y));
408410
}
409411

@@ -428,13 +430,13 @@ int vui_start_passive_animation(vui_context_t *ctx, vui_anim_step_callback_t ste
428430
}
429431

430432
ctx->passive_animation_count++;
431-
433+
432434
// Set layer defaults
433435
vui_animation_t *a = &ctx->passive_animations[cur_anim];
434436
a->step = step;
435437
a->step_data = step_data;
436438
gettimeofday(&a->start_time, NULL);
437-
439+
438440
return cur_anim;
439441
}
440442

@@ -461,11 +463,11 @@ void vui_update(vui_context_t *ctx)
461463

462464
if (ctx->animation_enabled) {
463465
int64_t diff = (now.tv_sec - ctx->animation.start_time.tv_sec) * 1000000 + (now.tv_usec - ctx->animation.start_time.tv_usec);
464-
466+
465467
if (diff > ctx->animation.length) {
466468
diff = ctx->animation.length;
467469
}
468-
470+
469471
if (ctx->animation.step)
470472
ctx->animation.step(ctx, diff, ctx->animation.step_data);
471473

@@ -532,7 +534,7 @@ int vui_layer_create(vui_context_t *ctx)
532534
}
533535

534536
ctx->layers++;
535-
537+
536538
// Set layer defaults
537539
ctx->layer_opacity[cur_layer] = 1.0f;
538540

@@ -541,7 +543,7 @@ int vui_layer_create(vui_context_t *ctx)
541543
layerbg->g = 0;
542544
layerbg->b = 0;
543545
layerbg->a = 0;
544-
546+
545547
return cur_layer;
546548
}
547549

@@ -635,7 +637,7 @@ int vui_textedit_create(vui_context_t *ctx, int x, int y, int w, int h, const ch
635637
edit->size = size;
636638

637639
edit->cursor = 0;
638-
640+
639641
vui_textedit_update_text(ctx, index, initial_text);
640642
vui_textedit_update_visible(ctx, index, 1);
641643
vui_textedit_update_enabled(ctx, index, 1);
@@ -907,3 +909,16 @@ vui_power_state_t vui_power_state_get(vui_context_t *ctx, int *percent)
907909
return VUI_POWERSTATE_UNKNOWN;
908910
}
909911
}
912+
913+
void vui_mic_enabled_set(vui_context_t *ctx, int enabled)
914+
{
915+
if (ctx->mic_enabled_handler) {
916+
ctx->mic_enabled_handler(ctx, enabled, ctx->mic_enabled_handler_data);
917+
}
918+
}
919+
920+
void vui_mic_callback_set(vui_context_t *ctx, vui_mic_callback_t callback, void *userdata)
921+
{
922+
ctx->mic_callback = callback;
923+
ctx->mic_callback_data = userdata;
924+
}

0 commit comments

Comments
 (0)