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[]; |
| 30 | extern const unsigned char * const * const kbyte_units; |
| 31 | |
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.*/ |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 37 | char *output_dyn_value(char *buf, int buf_size, int value, |
Nils Wallménius | 79f19b9 | 2009-10-17 13:40:42 +0000 | [diff] [blame] | 38 | const unsigned char * const *units, bool bin_scale); |
Linus Nielsen Feltzing | 75b41a8 | 2003-05-04 02:04:31 +0000 | [diff] [blame] | 39 | |
Magnus Holmgren | 14ba91e | 2007-02-17 13:36:44 +0000 | [diff] [blame] | 40 | /* Format time into buf. |
| 41 | * |
| 42 | * buf - buffer to format to. |
| 43 | * buf_size - size of buffer. |
| 44 | * t - time to format, in milliseconds. |
| 45 | */ |
| 46 | void format_time(char* buf, int buf_size, long t); |
| 47 | |
Nils Wallménius | dabcb81 | 2008-05-01 10:13:12 +0000 | [diff] [blame] | 48 | /* Ask the user if they really want to erase the current dynamic playlist |
| 49 | * returns true if the playlist should be replaced */ |
| 50 | bool warn_on_pl_erase(void); |
| 51 | |
Linus Nielsen Feltzing | 75b41a8 | 2003-05-04 02:04:31 +0000 | [diff] [blame] | 52 | /* Read (up to) a line of text from fd into buffer and return number of bytes |
| 53 | * read (which may be larger than the number of bytes stored in buffer). If |
| 54 | * an error occurs, -1 is returned (and buffer contains whatever could be |
| 55 | * read). A line is terminated by a LF char. Neither LF nor CR chars are |
| 56 | * stored in buffer. |
| 57 | */ |
| 58 | int read_line(int fd, char* buffer, int buffer_size); |
Miika Pekkarinen | a1ac743 | 2006-10-21 20:37:33 +0000 | [diff] [blame] | 59 | int fast_readline(int fd, char *buf, int buf_size, void *parameters, |
Miika Pekkarinen | d0084ff | 2011-06-23 20:22:00 +0000 | [diff] [blame] | 60 | int (*callback)(int n, char *buf, void *parameters)); |
Linus Nielsen Feltzing | a8dab4c | 2004-06-30 13:31:14 +0000 | [diff] [blame] | 61 | |
Linus Nielsen Feltzing | 26440c9 | 2004-07-05 11:15:50 +0000 | [diff] [blame] | 62 | bool settings_parseline(char* line, char** name, char** value); |
Jean-Philippe Bernardy | f64939e | 2005-02-07 22:56:37 +0000 | [diff] [blame] | 63 | long default_event_handler_ex(long event, void (*callback)(void *), void *parameter); |
| 64 | long default_event_handler(long event); |
Jens Arnold | 178c565 | 2007-04-09 13:39:37 +0000 | [diff] [blame] | 65 | bool list_stop_handler(void); |
Boris Gjenero | fdc29d0 | 2011-12-19 20:12:52 +0000 | [diff] [blame] | 66 | void car_adapter_mode_init(void) INIT_ATTR; |
Linus Nielsen Feltzing | 60895bc | 2005-09-02 05:39:09 +0000 | [diff] [blame] | 67 | extern int show_logo(void); |
Linus Nielsen Feltzing | 26440c9 | 2004-07-05 11:15:50 +0000 | [diff] [blame] | 68 | |
Nick Peskett | 1b781df | 2011-12-20 08:15:36 +0000 | [diff] [blame] | 69 | /* Unicode byte order mark sequences and lengths */ |
| 70 | #define BOM_UTF_8 "\xef\xbb\xbf" |
| 71 | #define BOM_UTF_8_SIZE 3 |
| 72 | #define BOM_UTF_16_LE "\xff\xfe" |
| 73 | #define BOM_UTF_16_BE "\xfe\xff" |
| 74 | #define BOM_UTF_16_SIZE 2 |
| 75 | |
Thomas Martitz | 8c655cf | 2012-07-18 23:26:21 +0200 | [diff] [blame] | 76 | 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] | 77 | int open_utf8(const char* pathname, int flags); |
| 78 | |
Peter D'Hoye | d2b3055 | 2007-03-30 21:54:48 +0000 | [diff] [blame] | 79 | #ifdef BOOTFILE |
Thomas Martitz | cfda097 | 2009-11-25 22:54:36 +0000 | [diff] [blame] | 80 | #if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF) \ |
| 81 | || defined(HAVE_HOTSWAP_STORAGE_AS_MAIN) |
Peter D'Hoye | d2b3055 | 2007-03-30 21:54:48 +0000 | [diff] [blame] | 82 | void check_bootfile(bool do_rolo); |
| 83 | #endif |
Peter D'Hoye | dc33e1e | 2007-03-30 23:36:10 +0000 | [diff] [blame] | 84 | #endif |
Peter D'Hoye | d2b3055 | 2007-03-30 21:54:48 +0000 | [diff] [blame] | 85 | |
Nils Wallménius | f46657e | 2007-05-30 17:57:32 +0000 | [diff] [blame] | 86 | /* check range, set volume and save settings */ |
| 87 | void setvol(void); |
| 88 | |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 89 | #ifdef HAVE_LCD_COLOR |
Dave Chapman | e92d2c5 | 2008-03-21 13:41:35 +0000 | [diff] [blame] | 90 | int hex_to_rgb(const char* hex, int* color); |
Brandon Low | 74cbb0a | 2007-06-17 21:16:34 +0000 | [diff] [blame] | 91 | #endif |
| 92 | |
Nils Wallménius | 4acae4d | 2007-11-18 14:12:01 +0000 | [diff] [blame] | 93 | char* strrsplt(char* str, int c); |
Nils Wallménius | 5a55772 | 2009-02-08 11:09:55 +0000 | [diff] [blame] | 94 | char* skip_whitespace(char* const str); |
Robert Kukla | d87b037 | 2007-11-21 21:28:27 +0000 | [diff] [blame] | 95 | |
Nicolas Pennequin | 536b5a0 | 2008-01-18 10:02:03 +0000 | [diff] [blame] | 96 | /* |
| 97 | * removes the extension of filename (if it doesn't start with a .) |
| 98 | * puts the result in buffer |
| 99 | */ |
Magnus Holmgren | 2235081 | 2008-02-06 19:51:19 +0000 | [diff] [blame] | 100 | char *strip_extension(char* buffer, int buffer_size, const char *filename); |
Robert Kukla | d87b037 | 2007-11-21 21:28:27 +0000 | [diff] [blame] | 101 | |
Tomer Shalev | 83d24f8 | 2009-10-23 13:29:19 +0000 | [diff] [blame] | 102 | #ifdef HAVE_LCD_BITMAP |
Jonathan Gordon | 489962d | 2010-08-10 14:15:03 +0000 | [diff] [blame] | 103 | bool parse_color(enum screen_type screen, char *text, int *value); |
Dave Chapman | e92d2c5 | 2008-03-21 13:41:35 +0000 | [diff] [blame] | 104 | |
Tomer Shalev | 83d24f8 | 2009-10-23 13:29:19 +0000 | [diff] [blame] | 105 | /* only used in USB HID and set_time screen */ |
| 106 | #if defined(USB_ENABLE_HID) || (CONFIG_RTC != 0) |
| 107 | int clamp_value_wrap(int value, int max, int min); |
| 108 | #endif |
| 109 | #endif |
| 110 | |
Jonathan Gordon | b58d365 | 2011-06-01 14:41:49 +0000 | [diff] [blame] | 111 | enum current_activity { |
| 112 | ACTIVITY_UNKNOWN = 0, |
| 113 | ACTIVITY_MAINMENU, |
| 114 | ACTIVITY_WPS, |
| 115 | ACTIVITY_RECORDING, |
| 116 | ACTIVITY_FM, |
| 117 | ACTIVITY_PLAYLISTVIEWER, |
| 118 | ACTIVITY_SETTINGS, |
| 119 | ACTIVITY_FILEBROWSER, |
| 120 | ACTIVITY_DATABASEBROWSER, |
| 121 | ACTIVITY_PLUGINBROWSER, |
| 122 | ACTIVITY_QUICKSCREEN, |
| 123 | ACTIVITY_PITCHSCREEN, |
Jonathan Gordon | 97a4c1e | 2011-07-20 14:11:15 +0000 | [diff] [blame] | 124 | ACTIVITY_OPTIONSELECT, |
Jonathan Gordon | 32dfc0c | 2011-08-04 13:40:24 +0000 | [diff] [blame] | 125 | ACTIVITY_PLAYLISTBROWSER, |
Jonathan Gordon | e918b7b | 2011-08-05 00:47:11 +0000 | [diff] [blame] | 126 | ACTIVITY_PLUGIN, |
Jonathan Gordon | 835683b | 2011-08-07 08:39:56 +0000 | [diff] [blame] | 127 | ACTIVITY_CONTEXTMENU, |
| 128 | ACTIVITY_SYSTEMSCREEN, |
| 129 | ACTIVITY_TIMEDATESCREEN, |
Jonathan Gordon | 101693f | 2011-11-15 13:22:02 +0000 | [diff] [blame] | 130 | ACTIVITY_BOOKMARKSLIST, |
Osborne Jacobs | d5e676b | 2012-03-02 23:30:07 -0500 | [diff] [blame] | 131 | ACTIVITY_SHORTCUTSMENU, |
Thomas Martitz | a648334 | 2014-01-16 00:26:45 +0100 | [diff] [blame] | 132 | ACTIVITY_ID3SCREEN, |
| 133 | ACTIVITY_USBSCREEN |
Jonathan Gordon | b58d365 | 2011-06-01 14:41:49 +0000 | [diff] [blame] | 134 | }; |
Michael Sevakis | 5663e1c | 2011-07-08 22:31:15 +0000 | [diff] [blame] | 135 | |
| 136 | #if CONFIG_CODEC == SWCODEC |
| 137 | void beep_play(unsigned int frequency, unsigned int duration, |
| 138 | unsigned int amplitude); |
| 139 | |
| 140 | enum system_sound |
| 141 | { |
| 142 | SOUND_KEYCLICK = 0, |
| 143 | SOUND_TRACK_SKIP, |
| 144 | SOUND_TRACK_NO_MORE, |
| 145 | }; |
| 146 | |
| 147 | /* Play a standard sound */ |
| 148 | void system_sound_play(enum system_sound sound); |
| 149 | |
Jonathan Gordon | eb2ea7f | 2012-01-12 22:28:36 +1100 | [diff] [blame] | 150 | typedef bool (*keyclick_callback)(int action, void* data); |
| 151 | void keyclick_set_callback(keyclick_callback cb, void* data); |
Michael Sevakis | 5663e1c | 2011-07-08 22:31:15 +0000 | [diff] [blame] | 152 | /* Produce keyclick based upon button and global settings */ |
Michael Sevakis | d05db0a | 2012-03-03 07:52:13 -0500 | [diff] [blame] | 153 | void keyclick_click(bool rawbutton, int action); |
Michael Sevakis | 57a20d2 | 2012-04-30 16:27:01 -0400 | [diff] [blame] | 154 | |
| 155 | /* Return current ReplayGain mode a file should have (REPLAYGAIN_TRACK or |
| 156 | * REPLAYGAIN_ALBUM) if ReplayGain processing is enabled, or -1 if no |
| 157 | * information present. |
| 158 | */ |
| 159 | struct mp3entry; |
| 160 | int id3_get_replaygain_mode(const struct mp3entry *id3); |
| 161 | void replaygain_update(void); |
| 162 | #else |
| 163 | static inline void replaygain_update(void) {} |
Michael Sevakis | 5663e1c | 2011-07-08 22:31:15 +0000 | [diff] [blame] | 164 | #endif /* CONFIG_CODEC == SWCODEC */ |
| 165 | |
Jonathan Gordon | b58d365 | 2011-06-01 14:41:49 +0000 | [diff] [blame] | 166 | void push_current_activity(enum current_activity screen); |
| 167 | void pop_current_activity(void); |
| 168 | enum current_activity get_current_activity(void); |
| 169 | |
| 170 | |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 171 | #endif /* MISC_H */ |