Daniel Stenberg | 9963c45 | 2003-03-10 12:19:49 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2002 by Daniel Stenberg |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Daniel Stenberg | 9963c45 | 2003-03-10 12:19:49 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
Linus Nielsen Feltzing | 26440c9 | 2004-07-05 11:15:50 +0000 | [diff] [blame] | 21 | #ifndef MISC_H |
| 22 | #define MISC_H |
Daniel Stenberg | 9963c45 | 2003-03-10 12:19:49 +0000 | [diff] [blame] | 23 | |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 24 | #include <stdbool.h> |
Jonathan Gordon | 61f5dd6 | 2008-06-07 09:35:57 +0000 | [diff] [blame] | 25 | #include <inttypes.h> |
Maurus Cuelenaere | 8751b94 | 2009-01-29 21:05:13 +0000 | [diff] [blame] | 26 | #include "config.h" |
Jonathan Gordon | 489962d | 2010-08-10 14:15:03 +0000 | [diff] [blame] | 27 | #include "screen_access.h" |
Dominik Riebeling | 02103a2 | 2008-08-02 20:39:03 +0000 | [diff] [blame] | 28 | |
Nils Wallménius | 79f19b9 | 2009-10-17 13:40:42 +0000 | [diff] [blame] | 29 | extern const unsigned char * const byte_units[]; |
William Wilgus | 62a5ed4 | 2018-12-09 12:09:40 -0600 | [diff] [blame] | 30 | extern const unsigned char * const * const kibyte_units; |
William Wilgus | a06d9c8 | 2018-12-17 22:27:55 -0600 | [diff] [blame] | 31 | extern const unsigned char * const unit_strings_core[]; |
Jens Arnold | 2116bba | 2005-01-31 00:39:20 +0000 | [diff] [blame] | 32 | /* Format a large-range value for output, using the appropriate unit so that |
| 33 | * the displayed value is in the range 1 <= display < 1000 (1024 for "binary" |
| 34 | * units) if possible, and 3 significant digits are shown. If a buffer is |
| 35 | * given, the result is snprintf()'d into that buffer, otherwise the result is |
| 36 | * voiced.*/ |
William Wilgus | 62a5ed4 | 2018-12-09 12:09:40 -0600 | [diff] [blame] | 37 | char *output_dyn_value(char *buf, |
| 38 | int buf_size, |
| 39 | int value, |
| 40 | const unsigned char * const *units, |
| 41 | unsigned int unit_count, |
| 42 | bool binary_scale); |
Linus Nielsen Feltzing | 75b41a8 | 2003-05-04 02:04:31 +0000 | [diff] [blame] | 43 | |
William Wilgus | a06d9c8 | 2018-12-17 22:27:55 -0600 | [diff] [blame] | 44 | |
| 45 | /* format_time_auto */ |
| 46 | enum e_fmt_time_auto_idx |
| 47 | { |
| 48 | UNIT_IDX_HR = 0, |
| 49 | UNIT_IDX_MIN, |
| 50 | UNIT_IDX_SEC, |
| 51 | UNIT_IDX_MS, |
| 52 | UNIT_IDX_TIME_COUNT, |
| 53 | }; |
| 54 | #define UNIT_IDX_MASK 0x01FFU /*Return only Unit_IDX*/ |
| 55 | #define UNIT_TRIM_ZERO 0x0200U /*Don't show leading zero on max_idx*/ |
| 56 | #define UNIT_LOCK_HR 0x0400U /*Don't Auto Range below this field*/ |
| 57 | #define UNIT_LOCK_MIN 0x0800U /*Don't Auto Range below this field*/ |
| 58 | #define UNIT_LOCK_SEC 0x1000U /*Don't Auto Range below this field*/ |
| 59 | |
| 60 | /* time_split_units() |
| 61 | split time values depending on base unit |
| 62 | unit_idx: UNIT_HOUR, UNIT_MIN, UNIT_SEC, UNIT_MS |
| 63 | abs_value: absolute time value |
| 64 | units_in: array of unsigned ints with IDX_TIME_COUNT fields |
| 65 | */ |
| 66 | unsigned int time_split_units(int unit_idx, unsigned long abs_val, |
| 67 | unsigned long (*units_in)[UNIT_IDX_TIME_COUNT]); |
| 68 | |
| 69 | /* format_time_auto - return an auto ranged time string; |
| 70 | buffer: needs to be at least 25 characters for full range |
| 71 | |
| 72 | unit_idx: specifies lowest or base index of the value |
| 73 | add | UNIT_LOCK_ to keep place holder of units that would normally be |
| 74 | discarded.. For instance, UNIT_LOCK_HR would keep the hours place, ex: string |
| 75 | 00:10:10 (0 HRS 10 MINS 10 SECONDS) normally it would return as 10:10 |
| 76 | add | UNIT_TRIM_ZERO to supress leading zero on the largest unit |
| 77 | |
| 78 | value: should be passed in the same form as unit_idx |
| 79 | |
| 80 | supress_unit: may be set to true and in this case the |
| 81 | hr, min, sec, ms identifiers will be left off the resulting string but |
| 82 | since right to left languages are handled it is advisable to leave units |
| 83 | as an indication of the text direction |
| 84 | */ |
| 85 | const char *format_time_auto(char *buffer, int buf_len, long value, |
| 86 | int unit_idx, bool supress_unit); |
| 87 | |
Magnus Holmgren | 14ba91e | 2007-02-17 13:36:44 +0000 | [diff] [blame] | 88 | /* Format time into buf. |
| 89 | * |
| 90 | * buf - buffer to format to. |
| 91 | * buf_size - size of buffer. |
| 92 | * t - time to format, in milliseconds. |
| 93 | */ |
| 94 | void format_time(char* buf, int buf_size, long t); |
| 95 | |
Nils Wallménius | dabcb81 | 2008-05-01 10:13:12 +0000 | [diff] [blame] | 96 | /* Ask the user if they really want to erase the current dynamic playlist |
| 97 | * returns true if the playlist should be replaced */ |
| 98 | bool warn_on_pl_erase(void); |
| 99 | |
Linus Nielsen Feltzing | 75b41a8 | 2003-05-04 02:04:31 +0000 | [diff] [blame] | 100 | /* Read (up to) a line of text from fd into buffer and return number of bytes |
| 101 | * read (which may be larger than the number of bytes stored in buffer). If |
| 102 | * an error occurs, -1 is returned (and buffer contains whatever could be |
| 103 | * read). A line is terminated by a LF char. Neither LF nor CR chars are |
| 104 | * stored in buffer. |
| 105 | */ |
| 106 | int read_line(int fd, char* buffer, int buffer_size); |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 107 | int fast_readline(int fd, char *buf, int buf_size, void *parameters, |
Miika Pekkarinen | d0084ff | 2011-06-23 20:22:00 +0000 | [diff] [blame] | 108 | int (*callback)(int n, char *buf, void *parameters)); |
Linus Nielsen Feltzing | a8dab4c | 2004-06-30 13:31:14 +0000 | [diff] [blame] | 109 | |
Linus Nielsen Feltzing | 26440c9 | 2004-07-05 11:15:50 +0000 | [diff] [blame] | 110 | bool settings_parseline(char* line, char** name, char** value); |
Jean-Philippe Bernardy | f64939e | 2005-02-07 22:56:37 +0000 | [diff] [blame] | 111 | long default_event_handler_ex(long event, void (*callback)(void *), void *parameter); |
| 112 | long default_event_handler(long event); |
Jens Arnold | 178c565 | 2007-04-09 13:39:37 +0000 | [diff] [blame] | 113 | bool list_stop_handler(void); |
Boris Gjenero | fdc29d0 | 2011-12-19 20:12:52 +0000 | [diff] [blame] | 114 | void car_adapter_mode_init(void) INIT_ATTR; |
Linus Nielsen Feltzing | 60895bc | 2005-09-02 05:39:09 +0000 | [diff] [blame] | 115 | extern int show_logo(void); |
Linus Nielsen Feltzing | 26440c9 | 2004-07-05 11:15:50 +0000 | [diff] [blame] | 116 | |
Nick Peskett | 1b781df | 2011-12-20 08:15:36 +0000 | [diff] [blame] | 117 | /* Unicode byte order mark sequences and lengths */ |
| 118 | #define BOM_UTF_8 "\xef\xbb\xbf" |
| 119 | #define BOM_UTF_8_SIZE 3 |
| 120 | #define BOM_UTF_16_LE "\xff\xfe" |
| 121 | #define BOM_UTF_16_BE "\xfe\xff" |
| 122 | #define BOM_UTF_16_SIZE 2 |
| 123 | |
Thomas Martitz | 8c655cf | 2012-07-18 23:26:21 +0200 | [diff] [blame] | 124 | int split_string(char *str, const char needle, char *vector[], int vector_length); |
Dominik Riebeling | 02103a2 | 2008-08-02 20:39:03 +0000 | [diff] [blame] | 125 | int open_utf8(const char* pathname, int flags); |
| 126 | |
Peter D'Hoye | d2b3055 | 2007-03-30 21:54:48 +0000 | [diff] [blame] | 127 | #ifdef BOOTFILE |
Thomas Martitz | cfda097 | 2009-11-25 22:54:36 +0000 | [diff] [blame] | 128 | #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF) \ |
| 129 | || defined(HAVE_HOTSWAP_STORAGE_AS_MAIN) |
Peter D'Hoye | d2b3055 | 2007-03-30 21:54:48 +0000 | [diff] [blame] | 130 | void check_bootfile(bool do_rolo); |
| 131 | #endif |
Peter D'Hoye | dc33e1e | 2007-03-30 23:36:10 +0000 | [diff] [blame] | 132 | #endif |
Peter D'Hoye | d2b3055 | 2007-03-30 21:54:48 +0000 | [diff] [blame] | 133 | |
Nils Wallménius | f46657e | 2007-05-30 17:57:32 +0000 | [diff] [blame] | 134 | /* check range, set volume and save settings */ |
| 135 | void setvol(void); |
| 136 | |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 137 | #ifdef HAVE_LCD_COLOR |
Dave Chapman | e92d2c5 | 2008-03-21 13:41:35 +0000 | [diff] [blame] | 138 | int hex_to_rgb(const char* hex, int* color); |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 139 | #endif |
| 140 | |
Nils Wallménius | 4acae4d | 2007-11-18 14:12:01 +0000 | [diff] [blame] | 141 | char* strrsplt(char* str, int c); |
Nils Wallménius | 5a55772 | 2009-02-08 11:09:55 +0000 | [diff] [blame] | 142 | char* skip_whitespace(char* const str); |
Robert Kukla | d87b037 | 2007-11-21 21:28:27 +0000 | [diff] [blame] | 143 | |
Nicolas Pennequin | 536b5a0 | 2008-01-18 10:02:03 +0000 | [diff] [blame] | 144 | /* |
| 145 | * removes the extension of filename (if it doesn't start with a .) |
| 146 | * puts the result in buffer |
| 147 | */ |
Magnus Holmgren | 2235081 | 2008-02-06 19:51:19 +0000 | [diff] [blame] | 148 | char *strip_extension(char* buffer, int buffer_size, const char *filename); |
Robert Kukla | d87b037 | 2007-11-21 21:28:27 +0000 | [diff] [blame] | 149 | |
Tomer Shalev | 83d24f8 | 2009-10-23 13:29:19 +0000 | [diff] [blame] | 150 | #ifdef HAVE_LCD_BITMAP |
Jonathan Gordon | 489962d | 2010-08-10 14:15:03 +0000 | [diff] [blame] | 151 | bool parse_color(enum screen_type screen, char *text, int *value); |
Dave Chapman | e92d2c5 | 2008-03-21 13:41:35 +0000 | [diff] [blame] | 152 | |
Tomer Shalev | 83d24f8 | 2009-10-23 13:29:19 +0000 | [diff] [blame] | 153 | /* only used in USB HID and set_time screen */ |
| 154 | #if defined(USB_ENABLE_HID) || (CONFIG_RTC != 0) |
| 155 | int clamp_value_wrap(int value, int max, int min); |
| 156 | #endif |
| 157 | #endif |
| 158 | |
Jonathan Gordon | b58d365 | 2011-06-01 14:41:49 +0000 | [diff] [blame] | 159 | enum current_activity { |
| 160 | ACTIVITY_UNKNOWN = 0, |
| 161 | ACTIVITY_MAINMENU, |
| 162 | ACTIVITY_WPS, |
| 163 | ACTIVITY_RECORDING, |
| 164 | ACTIVITY_FM, |
| 165 | ACTIVITY_PLAYLISTVIEWER, |
| 166 | ACTIVITY_SETTINGS, |
| 167 | ACTIVITY_FILEBROWSER, |
| 168 | ACTIVITY_DATABASEBROWSER, |
| 169 | ACTIVITY_PLUGINBROWSER, |
| 170 | ACTIVITY_QUICKSCREEN, |
| 171 | ACTIVITY_PITCHSCREEN, |
Jonathan Gordon | 97a4c1e | 2011-07-20 14:11:15 +0000 | [diff] [blame] | 172 | ACTIVITY_OPTIONSELECT, |
Jonathan Gordon | 32dfc0c | 2011-08-04 13:40:24 +0000 | [diff] [blame] | 173 | ACTIVITY_PLAYLISTBROWSER, |
Jonathan Gordon | e918b7b | 2011-08-05 00:47:11 +0000 | [diff] [blame] | 174 | ACTIVITY_PLUGIN, |
Jonathan Gordon | 835683b | 2011-08-07 08:39:56 +0000 | [diff] [blame] | 175 | ACTIVITY_CONTEXTMENU, |
| 176 | ACTIVITY_SYSTEMSCREEN, |
| 177 | ACTIVITY_TIMEDATESCREEN, |
Jonathan Gordon | 101693f | 2011-11-15 13:22:02 +0000 | [diff] [blame] | 178 | ACTIVITY_BOOKMARKSLIST, |
Osborne Jacobs | d5e676b | 2012-03-02 23:30:07 -0500 | [diff] [blame] | 179 | ACTIVITY_SHORTCUTSMENU, |
Thomas Martitz | a648334 | 2014-01-16 00:26:45 +0100 | [diff] [blame] | 180 | ACTIVITY_ID3SCREEN, |
| 181 | ACTIVITY_USBSCREEN |
Jonathan Gordon | b58d365 | 2011-06-01 14:41:49 +0000 | [diff] [blame] | 182 | }; |
Michael Sevakis | 5663e1c | 2011-07-08 22:31:15 +0000 | [diff] [blame] | 183 | |
| 184 | #if CONFIG_CODEC == SWCODEC |
| 185 | void beep_play(unsigned int frequency, unsigned int duration, |
| 186 | unsigned int amplitude); |
| 187 | |
| 188 | enum system_sound |
| 189 | { |
| 190 | SOUND_KEYCLICK = 0, |
| 191 | SOUND_TRACK_SKIP, |
| 192 | SOUND_TRACK_NO_MORE, |
Solomon Peachy | 39b64f7 | 2018-12-15 19:15:28 -0500 | [diff] [blame] | 193 | SOUND_LIST_EDGE_BEEP_WRAP, |
| 194 | SOUND_LIST_EDGE_BEEP_NOWRAP, |
Michael Sevakis | 5663e1c | 2011-07-08 22:31:15 +0000 | [diff] [blame] | 195 | }; |
| 196 | |
| 197 | /* Play a standard sound */ |
| 198 | void system_sound_play(enum system_sound sound); |
| 199 | |
Jonathan Gordon | eb2ea7f | 2012-01-12 22:28:36 +1100 | [diff] [blame] | 200 | typedef bool (*keyclick_callback)(int action, void* data); |
| 201 | void keyclick_set_callback(keyclick_callback cb, void* data); |
Michael Sevakis | 5663e1c | 2011-07-08 22:31:15 +0000 | [diff] [blame] | 202 | /* Produce keyclick based upon button and global settings */ |
Michael Sevakis | d05db0a | 2012-03-03 07:52:13 -0500 | [diff] [blame] | 203 | void keyclick_click(bool rawbutton, int action); |
Michael Sevakis | 57a20d2 | 2012-04-30 16:27:01 -0400 | [diff] [blame] | 204 | |
| 205 | /* Return current ReplayGain mode a file should have (REPLAYGAIN_TRACK or |
| 206 | * REPLAYGAIN_ALBUM) if ReplayGain processing is enabled, or -1 if no |
| 207 | * information present. |
| 208 | */ |
| 209 | struct mp3entry; |
| 210 | int id3_get_replaygain_mode(const struct mp3entry *id3); |
| 211 | void replaygain_update(void); |
| 212 | #else |
| 213 | static inline void replaygain_update(void) {} |
Michael Sevakis | 5663e1c | 2011-07-08 22:31:15 +0000 | [diff] [blame] | 214 | #endif /* CONFIG_CODEC == SWCODEC */ |
| 215 | |
Jonathan Gordon | b58d365 | 2011-06-01 14:41:49 +0000 | [diff] [blame] | 216 | void push_current_activity(enum current_activity screen); |
| 217 | void pop_current_activity(void); |
| 218 | enum current_activity get_current_activity(void); |
| 219 | |
Michael Sevakis | aced667 | 2017-09-18 06:00:05 -0400 | [diff] [blame] | 220 | /* format a sound value like: -1.05 dB */ |
| 221 | int format_sound_value(char *buf, size_t len, int snd, int val); |
Jonathan Gordon | b58d365 | 2011-06-01 14:41:49 +0000 | [diff] [blame] | 222 | |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 223 | #endif /* MISC_H */ |