summaryrefslogtreecommitdiff
path: root/apps/settings.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings.c')
-rw-r--r--apps/settings.c384
1 files changed, 2 insertions, 382 deletions
diff --git a/apps/settings.c b/apps/settings.c
index cad5f9206c..0cf38266a6 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -932,51 +932,6 @@ void talk_setting(void *global_settings_variable)
932 talk_id(setting->lang_id,false); 932 talk_id(setting->lang_id,false);
933} 933}
934 934
935static int selected_setting; /* Used by the callback */
936
937static void dec_sound_formatter(char *buffer, int buffer_size,
938 int val, const char *unit)
939{
940 val = sound_val2phys(selected_setting, val);
941 char sign = ' ';
942 if(val < 0)
943 {
944 sign = '-';
945 val = abs(val);
946 }
947 int integer = val / 10;
948 int dec = val % 10;
949 snprintf(buffer, buffer_size, "%c%d.%d %s", sign, integer, dec, unit);
950}
951
952bool set_sound(const unsigned char * string,
953 int* variable,
954 int setting)
955{
956 int talkunit = UNIT_INT;
957 const char* unit = sound_unit(setting);
958 int numdec = sound_numdecimals(setting);
959 int steps = sound_steps(setting);
960 int min = sound_min(setting);
961 int max = sound_max(setting);
962 sound_set_type* sound_callback = sound_get_fn(setting);
963 if (*unit == 'd') /* crude reconstruction */
964 talkunit = UNIT_DB;
965 else if (*unit == '%')
966 talkunit = UNIT_PERCENT;
967 else if (*unit == 'H')
968 talkunit = UNIT_HERTZ;
969 if (!numdec)
970 return set_int(string, unit, talkunit, variable, sound_callback,
971 steps, min, max, NULL );
972 else
973 {/* Decimal number */
974 selected_setting=setting;
975 return set_int(string, unit, talkunit, variable, sound_callback,
976 steps, min, max, &dec_sound_formatter );
977 }
978}
979
980bool set_bool(const char* string, bool* variable ) 935bool set_bool(const char* string, bool* variable )
981{ 936{
982 return set_bool_options(string, variable, 937 return set_bool_options(string, variable,
@@ -985,15 +940,6 @@ bool set_bool(const char* string, bool* variable )
985 NULL); 940 NULL);
986} 941}
987 942
988/* wrapper to convert from int param to bool param in set_option */
989static void (*boolfunction)(bool);
990static void bool_funcwrapper(int value)
991{
992 if (value)
993 boolfunction(true);
994 else
995 boolfunction(false);
996}
997 943
998bool set_bool_options(const char* string, bool* variable, 944bool set_bool_options(const char* string, bool* variable,
999 const char* yes_str, int yes_voice, 945 const char* yes_str, int yes_voice,
@@ -1006,237 +952,11 @@ bool set_bool_options(const char* string, bool* variable,
1006 }; 952 };
1007 bool result; 953 bool result;
1008 954
1009 boolfunction = function;
1010 result = set_option(string, variable, BOOL, names, 2, 955 result = set_option(string, variable, BOOL, names, 2,
1011 function ? bool_funcwrapper : NULL); 956 (void (*)(int))function);
1012 return result; 957 return result;
1013} 958}
1014 959
1015static void talk_unit(int unit, int value, long (*get_talk_id)(int value))
1016{
1017 if (talk_menus_enabled())
1018 {
1019 if (get_talk_id)
1020 {
1021 talk_id(get_talk_id(value),false);
1022 }
1023 else if (unit < UNIT_LAST)
1024 { /* use the available unit definition */
1025 talk_value(value, unit, false);
1026 }
1027 else
1028 { /* say the number, followed by an arbitrary voice ID */
1029 talk_number(value, false);
1030 talk_id(unit, true);
1031 }
1032 }
1033}
1034
1035struct value_setting_data {
1036 enum optiontype type;
1037 /* used for "value" settings.. */
1038 int max;
1039 int step;
1040 int voice_unit;
1041 const char * unit;
1042 void (*formatter)(char* dest, int dest_length,
1043 int value, const char* unit);
1044 long (*get_talk_id)(int value);
1045 /* used for BOOL and "choice" settings */
1046 struct opt_items* options;
1047};
1048
1049static char * value_setting_get_name_cb(int selected_item,void * data, char *buffer)
1050{
1051 struct value_setting_data* cb_data =
1052 (struct value_setting_data*)data;
1053 if (cb_data->type == INT && !cb_data->options)
1054 {
1055 int item = cb_data->max -(selected_item*cb_data->step);
1056 if (cb_data->formatter)
1057 cb_data->formatter(buffer, MAX_PATH,item,cb_data->unit);
1058 else
1059 snprintf(buffer, MAX_PATH,"%d %s",item,cb_data->unit);
1060 }
1061 else strcpy(buffer,P2STR(cb_data->options[selected_item].string));
1062 return buffer;
1063}
1064#define type_fromvoidptr(type, value) \
1065 (type == INT)? \
1066 (int)(*(int*)(value)) \
1067 : \
1068 (bool)(*(bool*)(value))
1069static bool do_set_setting(const unsigned char* string, void *variable,
1070 int nb_items,int selected,
1071 struct value_setting_data *cb_data,
1072 void (*function)(int))
1073{
1074 int action;
1075 bool done = false;
1076 struct gui_synclist lists;
1077 int oldvalue;
1078 bool allow_wrap = true;
1079
1080 if (cb_data->type == INT)
1081 {
1082 oldvalue = *(int*)variable;
1083 if (variable == &global_settings.volume)
1084 allow_wrap = false;
1085 }
1086 else oldvalue = *(bool*)variable;
1087
1088 gui_synclist_init(&lists,value_setting_get_name_cb,(void*)cb_data,false,1);
1089 gui_synclist_set_title(&lists, (char*)string,Icon_Questionmark);
1090 gui_synclist_set_icon_callback(&lists,NULL);
1091 gui_synclist_set_nb_items(&lists,nb_items);
1092 gui_synclist_limit_scroll(&lists,true);
1093 gui_synclist_select_item(&lists, selected);
1094
1095 if (talk_menus_enabled())
1096 {
1097 if (cb_data->type == INT && !cb_data->options)
1098 talk_unit(cb_data->voice_unit, *(int*)variable, cb_data->get_talk_id);
1099 else
1100 talk_id(cb_data->options[selected].voice_id, false);
1101 }
1102
1103 gui_synclist_draw(&lists);
1104 action_signalscreenchange();
1105 while (!done)
1106 {
1107
1108 action = get_action(CONTEXT_LIST,TIMEOUT_BLOCK);
1109 if (action == ACTION_NONE)
1110 continue;
1111 if (gui_synclist_do_button(&lists,action,
1112 allow_wrap?LIST_WRAP_UNLESS_HELD:LIST_WRAP_OFF))
1113 {
1114 if (talk_menus_enabled())
1115 {
1116 int value;
1117 if (cb_data->type == INT && !cb_data->options)
1118 {
1119 value = cb_data->max -
1120 gui_synclist_get_sel_pos(&lists)*cb_data->step;
1121 talk_unit(cb_data->voice_unit, value, cb_data->get_talk_id);
1122 }
1123 else
1124 {
1125 value = gui_synclist_get_sel_pos(&lists);
1126 talk_id(cb_data->options[value].voice_id, false);
1127 }
1128 }
1129 if (cb_data->type == INT && !cb_data->options)
1130 *(int*)variable = cb_data->max -
1131 gui_synclist_get_sel_pos(&lists)*cb_data->step;
1132 else if (cb_data->type == BOOL)
1133 *(bool*)variable = gui_synclist_get_sel_pos(&lists) ? true : false;
1134 else *(int*)variable = gui_synclist_get_sel_pos(&lists);
1135 }
1136 else if (action == ACTION_STD_CANCEL)
1137 {
1138 if (cb_data->type == INT)
1139 {
1140 if (*(int*)variable != oldvalue)
1141 {
1142 gui_syncsplash(HZ/2, str(LANG_MENU_SETTING_CANCEL));
1143 *(int*)variable = oldvalue;
1144 }
1145 }
1146 else
1147 {
1148 if (*(bool*)variable != (bool)oldvalue)
1149 {
1150 gui_syncsplash(HZ/2, str(LANG_MENU_SETTING_CANCEL));
1151 *(bool*)variable = (bool)oldvalue;
1152 }
1153 }
1154 done = true;
1155 }
1156 else if (action == ACTION_STD_OK)
1157 {
1158 done = true;
1159 }
1160 else if(default_event_handler(action) == SYS_USB_CONNECTED)
1161 return true;
1162 gui_syncstatusbar_draw(&statusbars, false);
1163 if ( function )
1164 function(type_fromvoidptr(cb_data->type,variable));
1165 }
1166 if (cb_data->type == INT)
1167 {
1168 if (oldvalue != *(int*)variable)
1169 settings_save();
1170 }
1171 else if (oldvalue != *(bool*)variable)
1172 settings_save();
1173
1174 action_signalscreenchange();
1175 return false;
1176}
1177static const char *unit_strings[] =
1178{
1179 [UNIT_INT]
1180 = "",
1181 [UNIT_MS]
1182 = "ms",
1183 [UNIT_SEC]
1184 = "s",
1185 [UNIT_MIN]
1186 = "min",
1187 [UNIT_HOUR]
1188 = "hr",
1189 [UNIT_KHZ]
1190 = "KHz",
1191 [UNIT_DB]
1192 = "dB",
1193 [UNIT_PERCENT]
1194 = "%",
1195 [UNIT_MAH]
1196 = "mAh",
1197 [UNIT_PIXEL]
1198 = "px",
1199 [UNIT_PER_SEC]
1200 = "per sec",
1201 [UNIT_HERTZ]
1202 = "Hz",
1203 [UNIT_MB]
1204 = "MB",
1205 [UNIT_KBIT]
1206 = "kb/s",
1207};
1208bool set_int_ex(const unsigned char* string,
1209 const char* unit,
1210 int voice_unit,
1211 int* variable,
1212 void (*function)(int),
1213 int step,
1214 int min,
1215 int max,
1216 void (*formatter)(char*, int, int, const char*),
1217 long (*get_talk_id)(int))
1218{
1219 int count = (max-min)/step + 1;
1220#if CONFIG_KEYPAD != PLAYER_PAD
1221 struct value_setting_data data = {
1222 INT,max, step, voice_unit,unit,formatter,get_talk_id,NULL };
1223 if (voice_unit < UNIT_LAST)
1224 data.unit = unit_strings[voice_unit];
1225 else
1226 data.unit = str(voice_unit);
1227 return do_set_setting(string,variable,count,
1228 (max-*variable)/step, &data,function);
1229#else
1230 struct value_setting_data data = {
1231 INT,min, -step, voice_unit,unit,formatter,get_talk_id,NULL };
1232 if (voice_unit < UNIT_LAST)
1233 data.unit = unit_strings[voice_unit];
1234 else
1235 data.unit = str(voice_unit);
1236 return do_set_setting(string,variable,count,
1237 (*variable-min)/step, &data,function);
1238#endif
1239}
1240bool set_int(const unsigned char* string, 960bool set_int(const unsigned char* string,
1241 const char* unit, 961 const char* unit,
1242 int voice_unit, 962 int voice_unit,
@@ -1250,25 +970,7 @@ bool set_int(const unsigned char* string,
1250 return set_int_ex(string, unit, voice_unit, variable, function, 970 return set_int_ex(string, unit, voice_unit, variable, function,
1251 step, min, max, formatter, NULL); 971 step, min, max, formatter, NULL);
1252} 972}
1253/* NOTE: the 'type' parameter specifies the actual type of the variable 973
1254 that 'variable' points to. not the value within. Only variables with
1255 type 'bool' should use parameter BOOL.
1256
1257 The type separation is necessary since int and bool are fundamentally
1258 different and bit-incompatible types and can not share the same access
1259 code. */
1260bool set_option(const char* string, void* variable, enum optiontype type,
1261 const struct opt_items* options, int numoptions, void (*function)(int))
1262{
1263 struct value_setting_data data = {
1264 type,0, 0, 0,NULL,NULL,NULL,(struct opt_items*)options };
1265 int selected;
1266 if (type == BOOL)
1267 selected = *(bool*)variable ? 1 : 0;
1268 else selected = *(int*)variable;
1269 return do_set_setting(string,variable,numoptions,
1270 selected, &data,function);
1271}
1272 974
1273/** extra stuff which is probably misplaced **/ 975/** extra stuff which is probably misplaced **/
1274 976
@@ -1303,85 +1005,3 @@ void set_file(char* filename, char* setting, int maxlen)
1303 settings_save(); 1005 settings_save();
1304} 1006}
1305 1007
1306#ifdef HAVE_RECORDING
1307/* This array holds the record timer interval lengths, in seconds */
1308static const unsigned long rec_timer_seconds[] =
1309{
1310 0, /* 0 means OFF */
1311 5*60, /* 00:05 */
1312 10*60, /* 00:10 */
1313 15*60, /* 00:15 */
1314 30*60, /* 00:30 */
1315 60*60, /* 01:00 */
1316 74*60, /* 74:00 */
1317 80*60, /* 80:00 */
1318 2*60*60, /* 02:00 */
1319 4*60*60, /* 04:00 */
1320 6*60*60, /* 06:00 */
1321 8*60*60, /* 08:00 */
1322 10L*60*60, /* 10:00 */
1323 12L*60*60, /* 12:00 */
1324 18L*60*60, /* 18:00 */
1325 24L*60*60 /* 24:00 */
1326};
1327
1328unsigned int rec_timesplit_seconds(void)
1329{
1330 return rec_timer_seconds[global_settings.rec_timesplit];
1331}
1332
1333/* This array holds the record size interval lengths, in bytes */
1334static const unsigned long rec_size_bytes[] =
1335{
1336 0, /* 0 means OFF */
1337 5*1024*1024, /* 5MB */
1338 10*1024*1024, /* 10MB */
1339 15*1024*1024, /* 15MB */
1340 32*1024*1024, /* 32MB */
1341 64*1024*1024, /* 64MB */
1342 75*1024*1024, /* 75MB */
1343 100*1024*1024, /* 100MB */
1344 128*1024*1024, /* 128MB */
1345 256*1024*1024, /* 256MB */
1346 512*1024*1024, /* 512MB */
1347 650*1024*1024, /* 650MB */
1348 700*1024*1024, /* 700MB */
1349 1024*1024*1024, /* 1GB */
1350 1536*1024*1024, /* 1.5GB */
1351 1792*1024*1024, /* 1.75GB */
1352};
1353
1354unsigned long rec_sizesplit_bytes(void)
1355{
1356 return rec_size_bytes[global_settings.rec_sizesplit];
1357}
1358/*
1359 * Time strings used for the trigger durations.
1360 * Keep synchronous to trigger_times in settings_apply_trigger
1361 */
1362const char * const trig_durations[TRIG_DURATION_COUNT] =
1363{
1364 "0s", "1s", "2s", "5s",
1365 "10s", "15s", "20s", "25s", "30s",
1366 "1min", "2min", "5min", "10min"
1367};
1368
1369void settings_apply_trigger(void)
1370{
1371 /* Keep synchronous to trig_durations and trig_durations_conf*/
1372 static const long trigger_times[TRIG_DURATION_COUNT] = {
1373 0, HZ, 2*HZ, 5*HZ,
1374 10*HZ, 15*HZ, 20*HZ, 25*HZ, 30*HZ,
1375 60*HZ, 2*60*HZ, 5*60*HZ, 10*60*HZ
1376 };
1377
1378 peak_meter_define_trigger(
1379 global_settings.rec_start_thres,
1380 trigger_times[global_settings.rec_start_duration],
1381 MIN(trigger_times[global_settings.rec_start_duration] / 2, 2*HZ),
1382 global_settings.rec_stop_thres,
1383 trigger_times[global_settings.rec_stop_postrec],
1384 trigger_times[global_settings.rec_stop_gap]
1385 );
1386}
1387#endif