[tuxdroid-svn] r991 - software_suite_v2/middleware/tuxdriver/trunk/src
Status: Beta
Brought to you by:
ks156
From: eFfeM <c2m...@c2...> - 2008-04-20 18:57:15
|
Author: eFfeM Date: 2008-04-20 20:57:15 +0200 (Sun, 20 Apr 2008) New Revision: 991 Modified: software_suite_v2/middleware/tuxdriver/trunk/src/tux_sound_flash.c Log: curlies, layout Modified: software_suite_v2/middleware/tuxdriver/trunk/src/tux_sound_flash.c =================================================================== --- software_suite_v2/middleware/tuxdriver/trunk/src/tux_sound_flash.c 2008-04-20 12:19:11 UTC (rev 990) +++ software_suite_v2/middleware/tuxdriver/trunk/src/tux_sound_flash.c 2008-04-20 18:57:15 UTC (rev 991) @@ -23,14 +23,14 @@ #include <stdlib.h> #include <string.h> +#include "log.h" +#include "tux_cmd_parser.h" #include "tux_hw_status.h" #include "tux_hw_cmd.h" +#include "tux_leds.h" #include "tux_sw_status.h" #include "tux_sound_flash.h" #include "tux_usb.h" -#include "tux_cmd_parser.h" -#include "tux_leds.h" -#include "log.h" LIBLOCAL sound_flash_descriptor_t sound_flash_desc; @@ -94,19 +94,19 @@ { char tmp_str[80] = ""; - strcat(descriptor, "- Sound flash\n"); + strcat(descriptor, "- Sound flash\n"); + + sprintf(tmp_str, " Number of sounds : %d\n", + sound_flash_desc.number_of_sounds); + strcat(descriptor, tmp_str); - sprintf(tmp_str, " Number of sounds : %d\n", - sound_flash_desc.number_of_sounds); - strcat(descriptor, tmp_str); - - sprintf(tmp_str, " Last used block : %d\n", - sound_flash_desc.flash_usage); - strcat(descriptor, tmp_str); - - sprintf(tmp_str, " Available record time (sec) : %d\n", - sound_flash_desc.available_record_time); - strcat(descriptor, tmp_str); + sprintf(tmp_str, " Last used block : %d\n", + sound_flash_desc.flash_usage); + strcat(descriptor, tmp_str); + + sprintf(tmp_str, " Available record time (sec) : %d\n", + sound_flash_desc.available_record_time); + strcat(descriptor, tmp_str); return; } @@ -131,7 +131,7 @@ LIBLOCAL void tux_sound_flash_get_descripor(void) { - /* Currently, the status are sended by tuxaudio when then + /* Currently, the status are sent by tuxaudio when then * the versionning is requested */ } @@ -146,8 +146,11 @@ char track[10] = ""; if (!hw_status_table.sensors1.play_internal_sound) + { new_track = STRING_VALUE_STOP; - else { + } + else + { sprintf(track, "TRACK_%.3d", hw_status_table.sensors1.play_internal_sound); new_track = track; @@ -156,8 +159,10 @@ old_track = (char *)tux_sw_status_get_value(SW_ID_AUDIO_FLASH_PLAY); if (strcmp(new_track, old_track)) + { tux_sw_status_set_value(SW_ID_AUDIO_FLASH_PLAY, (void *)new_track, true); + } } /** @@ -173,8 +178,10 @@ old_state = *(unsigned char *)tux_sw_status_get_value(SW_ID_AUDIO_GENERAL_PLAY); if (new_state != old_state) + { tux_sw_status_set_value(SW_ID_AUDIO_GENERAL_PLAY, (void *)&new_state, true); + } } /** @@ -189,8 +196,10 @@ old_track = *(unsigned char *)tux_sw_status_get_value(SW_ID_FLASH_PROG_CURR_TRACK); if (new_track != old_track) + { tux_sw_status_set_value(SW_ID_FLASH_PROG_CURR_TRACK, (void *)&new_track, true); + } } /** @@ -205,8 +214,10 @@ old_size = *(int *)tux_sw_status_get_value(SW_ID_FLASH_PROG_LAST_TRACK_SIZE); if (new_size != old_size) + { tux_sw_status_set_value(SW_ID_FLASH_PROG_LAST_TRACK_SIZE, (void *)&new_size, true); + } } /** @@ -217,15 +228,15 @@ { #ifdef LOCK_TUX FILE *f; - char ret_str[3] = "\n"; char *ret_c; f = fopen("./track_num", "r"); - if (f) { + if (f) + { fgets(knowed_track_num, sizeof(knowed_track_num)-2, f); - ret_c = strstr(knowed_track_num, ret_str); - *(char *)ret_c = '\0'; + ret_c = strchr(knowed_track_num, '\n'); + *ret_c = '\0'; fclose(f); } #endif @@ -242,7 +253,8 @@ f = fopen("./track_num", "w"); - if (f) { + if (f) + { fprintf(f, "%d\n", sound_flash_desc.number_of_sounds); fclose(f); } @@ -263,10 +275,14 @@ sprintf(track_num_str, "%d", sound_flash_desc.number_of_sounds); if (strcmp(knowed_track_num, track_num_str)) + { ret = true; + } if (save) + { save_knowed_track_num(); + } return ret; #else @@ -280,8 +296,7 @@ LIBLOCAL bool tux_sound_flash_cmd_play(char *track_num, char *volume) { - unsigned char frame[TUX_SEND_LENGTH - 1] = {PLAY_SOUND_CMD, - 0, 0, 0}; + unsigned char frame[TUX_SEND_LENGTH - 1] = {PLAY_SOUND_CMD, 0, 0, 0}; unsigned char t_n = 1; float vol = 0; unsigned char vol2 = 0; @@ -291,11 +306,20 @@ ret &= str_to_float(volume, &vol); if (vol < 0) + { vol2 = 7; - else if (vol > 100) - vol2 = 0; + } else - vol2 = 7 - (int)(vol * 7.0 / 100.0); + { + if (vol > 100) + { + vol2 = 0; + } + else + { + vol2 = 7 - (int)(vol * 7.0 / 100.0); + } + } frame[1] = t_n; frame[2] = vol2; @@ -317,17 +341,24 @@ WAVEOUTCAPSA wa_device; if (!waveOutGetNumDevs()) + { return false; + } - for (i = 0; i < waveOutGetNumDevs(); i++) { + for (i = 0; i < waveOutGetNumDevs(); i++) + { memset(&wa_device, 0, sizeof(wa_device)); if (waveOutGetDevCapsA(i, &wa_device, sizeof(wa_device)) == 0) + { if (!strcmp(wa_device.szPname, "TuxDroid-Audio")) + { if (waveOutMessage((HWAVEOUT)WAVE_MAPPER, DRVM_MAPPER_PREFERRED_SET, i, 0) == 0) { return true; } + } + } } return false; @@ -346,7 +377,8 @@ err = waveOutMessage((HWAVEOUT)WAVE_MAPPER, DRVM_MAPPER_PREFERRED_GET, (DWORD)&po, (DWORD)&pf); - if (err == 0) { + if (err == 0) + { *(int *)idx = po; return true; } @@ -364,9 +396,12 @@ int def_idx = -1; if (!get_default_playback_idx(&def_idx)) + { return false; + } - if (waveOutGetDevCapsA(def_idx, &wa_device, sizeof(wa_device)) == 0) { + if (waveOutGetDevCapsA(def_idx, &wa_device, sizeof(wa_device)) == 0) + { sprintf(name, "%s", wa_device.szPname); return true; } @@ -384,15 +419,21 @@ WAVEOUTCAPSA wa_device; if (!waveOutGetNumDevs()) + { return false; + } - for (i = 0; i < waveOutGetNumDevs(); i++) { + for (i = 0; i < waveOutGetNumDevs(); i++) + { memset(&wa_device, 0, sizeof(wa_device)); if (waveOutGetDevCapsA(i, &wa_device, sizeof(wa_device)) == 0) - if (!strcmp(wa_device.szPname, name)) { - *(int *)idx = i; + { + if (!strcmp(wa_device.szPname, name)) + { + *idx = i; return true; } + } } return false; @@ -435,14 +476,19 @@ unsigned int vid, pid; dir = opendir("/dev/snd"); - if (dir == NULL) { + if (dir == NULL) + { printf("No sound device directory\n"); - } else { + } + else + { dinfo = readdir(dir); last_card = 255; last_device = 255; - while (dinfo != NULL) { - if (strncmp(dinfo->d_name, "pcm", 3) == 0) { + while (dinfo != NULL) + { + if (strncmp(dinfo->d_name, "pcm", 3) == 0) + { count = sscanf(dinfo->d_name, "pcmC%dD%d", &card, &device); if ((count == 2) && ((last_card != card) || (last_device != device))) @@ -451,17 +497,20 @@ last_device = device; sprintf(filename, "/proc/asound/card%d/usbbus", card); fp = fopen((const char *)filename, "r"); - if(fp != NULL) { + if(fp != NULL) + { fclose(fp); sprintf(hw_device, "hw:%d,%d", card, device); } sprintf(filename, "/proc/asound/card%d/usbid", card); fp = fopen((const char *)filename, "r"); - if(fp != NULL) { + if(fp != NULL) + { fgets(line, 81, fp); sscanf( line, "%4x:%4x", &vid, &pid); fclose(fp); - if((vid == TUX_VID) && (pid == TUX_PID)) { + if((vid == TUX_VID) && (pid == TUX_PID)) + { /* Todo log this */ sprintf(hw_audio_name, "%s", hw_device); return; @@ -491,16 +540,24 @@ get_default_playback_name(def_dev_name); if (!set_tux_as_default_playback()) + { return false; + } if (sndPlaySound(wav_path, SND_SYNC) != true) + { ret = false; + } if (!get_idx_playback_from_name(&def_idx, def_dev_name)) + { return false; + } if (!set_default_playback(def_idx)) + { return false; + } #else /* UNIX */ int r; @@ -508,7 +565,8 @@ ret = false; - if (hw_audio_name[0] != '\0') { + if (hw_audio_name[0] != '\0') + { sprintf(cmd, "aplay -D %s %s", hw_audio_name, wav_path); r = system(cmd); if (r == 0) @@ -544,7 +602,9 @@ int i; for (i = 0; i < 256; i++) + { strncat(reg_ex, tok, sizeof(tok) - 1); + } i = sscanf(src_str, reg_ex, tokens[0], ts, tokens[1], ts, tokens[2], ts, tokens[3], ts, @@ -630,21 +690,29 @@ int tmp_bc = 0; if (reflash_info.current_state != SRS_STDBY) + { return E_TUXDRV_BUSY; + } init_reflash_info(); reflash_info.wav_count = parse_wavs(tracks, &reflash_info.wav_path); if (!reflash_info.wav_count) + { return E_TUXDRV_BADWAVFILE; + } if (reflash_info.wav_count > 0) - for (i = 0; i < reflash_info.wav_count; i++) { + { + for (i = 0; i < reflash_info.wav_count; i++) + { /* open the wav file */ fp = fopen((char *)reflash_info.wav_path[i], "rb"); /* if wav_path not accessible then exit */ if (fp == NULL) + { return E_TUXDRV_BADWAVFILE; + } /* Get the size of file */ fseek(fp, 0, SEEK_END); reflash_info.wav_size[i] = ftell(fp) - 44; @@ -653,14 +721,19 @@ /* Get the needed blocks number for this sound */ tmp_bc = (int)(reflash_info.wav_size[i] / 4000); if ((int)(reflash_info.wav_size[i] % 4000) > 0) + { tmp_bc++; + } /* Add to global blocks count */ block_count += tmp_bc; } + } /* If needed blocks exceeds 127 then fail */ if (block_count > 127) + { return E_TUXDRV_WAVSIZEEXCEDED; + } reflash_info.current_state = SRS_INIT; @@ -681,9 +754,11 @@ unsigned char curr_track_for_event = 0; /* Check fux connection and radio connection */ - if (reflash_info.current_state != SRS_STDBY) { + if (reflash_info.current_state != SRS_STDBY) + { rf_state = *(bool *)tux_sw_status_get_value(SW_ID_RF_STATE); - if ((!tux_usb_connected()) || (!rf_state)) { + if ((!tux_usb_connected()) || (!rf_state)) + { reflash_info.error = SRE_RF_OFFLINE; reflash_info.current_state = SRS_FINISH; } @@ -713,7 +788,8 @@ /* Send erase cmd */ log_info("Sound reflash: Erasing"); frame[0] = ERASE_FLASH_CMD; - if (!tux_usb_send_to_tux(frame)) { + if (!tux_usb_send_to_tux(frame)) + { reflash_info.error = SRE_USB_ERROR; reflash_info.current_state = SRS_FINISH; break; @@ -731,7 +807,8 @@ reflash_info.current_wav + 1, reflash_info.wav_count); frame[0] = STORE_SOUND_CMD; - if (!tux_usb_send_to_tux(frame)) { + if (!tux_usb_send_to_tux(frame)) + { reflash_info.error = SRE_USB_ERROR; reflash_info.current_state = SRS_FINISH; break; @@ -741,10 +818,12 @@ (void *)&curr_track_for_event, true); usleep(200000); /* Play current wav track */ - if (!play_wav(reflash_info.wav_path[reflash_info.current_wav])) { + if (!play_wav(reflash_info.wav_path[reflash_info.current_wav])) + { frame[0] = CONFIRM_STORAGE_CMD; frame[1] = 0; - if (!tux_usb_send_to_tux(frame)) { + if (!tux_usb_send_to_tux(frame)) + { reflash_info.error = SRE_USB_ERROR; reflash_info.current_state = SRS_FINISH; break; @@ -757,7 +836,8 @@ usleep(200000); frame[0] = CONFIRM_STORAGE_CMD; frame[1] = 1; - if (!tux_usb_send_to_tux(frame)) { + if (!tux_usb_send_to_tux(frame)) + { reflash_info.error = SRE_USB_ERROR; reflash_info.current_state = SRS_FINISH; break; @@ -767,7 +847,9 @@ reflash_info.current_wav += 1; /* If the next track is out of limit, Goto SRS_FINISH state */ if (reflash_info.current_wav >= reflash_info.wav_count) + { reflash_info.current_state = SRS_FINISH; + } break; case SRS_FINISH: /* Enabling commands parsing */ |