blob: 8d72e79a3d1676c57428939ff09f7ab2ed7a3b93 [file] [log] [blame]
Daniel Stenberg9963c452003-03-10 12:19:49 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Daniel Stenberg
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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 Stenberg9963c452003-03-10 12:19:49 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
Linus Nielsen Feltzing26440c92004-07-05 11:15:50 +000021#ifndef MISC_H
22#define MISC_H
Daniel Stenberg9963c452003-03-10 12:19:49 +000023
Michael Sevakis0f5cb942006-11-06 18:07:30 +000024#include <stdbool.h>
Jonathan Gordon61f5dd62008-06-07 09:35:57 +000025#include <inttypes.h>
Maurus Cuelenaere8751b942009-01-29 21:05:13 +000026#include "config.h"
Jonathan Gordon489962d2010-08-10 14:15:03 +000027#include "screen_access.h"
Dominik Riebeling02103a22008-08-02 20:39:03 +000028
Nils Wallménius79f19b92009-10-17 13:40:42 +000029extern const unsigned char * const byte_units[];
William Wilgus62a5ed42018-12-09 12:09:40 -060030extern const unsigned char * const * const kibyte_units;
William Wilgusa06d9c82018-12-17 22:27:55 -060031extern const unsigned char * const unit_strings_core[];
Jens Arnold2116bba2005-01-31 00:39:20 +000032/* 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 Wilgus62a5ed42018-12-09 12:09:40 -060037char *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 Feltzing75b41a82003-05-04 02:04:31 +000043
William Wilgusa06d9c82018-12-17 22:27:55 -060044
45/* format_time_auto */
46enum 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*/
66unsigned 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*/
85const char *format_time_auto(char *buffer, int buf_len, long value,
86 int unit_idx, bool supress_unit);
87
Magnus Holmgren14ba91e2007-02-17 13:36:44 +000088/* 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 */
94void format_time(char* buf, int buf_size, long t);
95
Nils Wallméniusdabcb812008-05-01 10:13:12 +000096/* Ask the user if they really want to erase the current dynamic playlist
97 * returns true if the playlist should be replaced */
98bool warn_on_pl_erase(void);
99
Linus Nielsen Feltzing75b41a82003-05-04 02:04:31 +0000100/* 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 */
106int read_line(int fd, char* buffer, int buffer_size);
Miika Pekkarinena1ac7432006-10-21 20:37:33 +0000107int fast_readline(int fd, char *buf, int buf_size, void *parameters,
Miika Pekkarinend0084ff2011-06-23 20:22:00 +0000108 int (*callback)(int n, char *buf, void *parameters));
Linus Nielsen Feltzinga8dab4c2004-06-30 13:31:14 +0000109
Linus Nielsen Feltzing26440c92004-07-05 11:15:50 +0000110bool settings_parseline(char* line, char** name, char** value);
Jean-Philippe Bernardyf64939e2005-02-07 22:56:37 +0000111long default_event_handler_ex(long event, void (*callback)(void *), void *parameter);
112long default_event_handler(long event);
Jens Arnold178c5652007-04-09 13:39:37 +0000113bool list_stop_handler(void);
Boris Gjenerofdc29d02011-12-19 20:12:52 +0000114void car_adapter_mode_init(void) INIT_ATTR;
Linus Nielsen Feltzing60895bc2005-09-02 05:39:09 +0000115extern int show_logo(void);
Linus Nielsen Feltzing26440c92004-07-05 11:15:50 +0000116
Nick Peskett1b781df2011-12-20 08:15:36 +0000117/* 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 Martitz8c655cf2012-07-18 23:26:21 +0200124int split_string(char *str, const char needle, char *vector[], int vector_length);
Dominik Riebeling02103a22008-08-02 20:39:03 +0000125int open_utf8(const char* pathname, int flags);
126
Peter D'Hoyed2b30552007-03-30 21:54:48 +0000127#ifdef BOOTFILE
Thomas Martitzcfda0972009-11-25 22:54:36 +0000128#if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF) \
129 || defined(HAVE_HOTSWAP_STORAGE_AS_MAIN)
Peter D'Hoyed2b30552007-03-30 21:54:48 +0000130void check_bootfile(bool do_rolo);
131#endif
Peter D'Hoyedc33e1e2007-03-30 23:36:10 +0000132#endif
Peter D'Hoyed2b30552007-03-30 21:54:48 +0000133
Nils Wallméniusf46657e2007-05-30 17:57:32 +0000134/* check range, set volume and save settings */
135void setvol(void);
136
Brandon Low74cbb0a2007-06-17 21:16:34 +0000137#ifdef HAVE_LCD_COLOR
Dave Chapmane92d2c52008-03-21 13:41:35 +0000138int hex_to_rgb(const char* hex, int* color);
Brandon Low74cbb0a2007-06-17 21:16:34 +0000139#endif
140
Nils Wallménius4acae4d2007-11-18 14:12:01 +0000141char* strrsplt(char* str, int c);
Nils Wallménius5a557722009-02-08 11:09:55 +0000142char* skip_whitespace(char* const str);
Robert Kuklad87b0372007-11-21 21:28:27 +0000143
Nicolas Pennequin536b5a02008-01-18 10:02:03 +0000144/*
145 * removes the extension of filename (if it doesn't start with a .)
146 * puts the result in buffer
147 */
Magnus Holmgren22350812008-02-06 19:51:19 +0000148char *strip_extension(char* buffer, int buffer_size, const char *filename);
Robert Kuklad87b0372007-11-21 21:28:27 +0000149
Tomer Shalev83d24f82009-10-23 13:29:19 +0000150#ifdef HAVE_LCD_BITMAP
Jonathan Gordon489962d2010-08-10 14:15:03 +0000151bool parse_color(enum screen_type screen, char *text, int *value);
Dave Chapmane92d2c52008-03-21 13:41:35 +0000152
Tomer Shalev83d24f82009-10-23 13:29:19 +0000153/* only used in USB HID and set_time screen */
154#if defined(USB_ENABLE_HID) || (CONFIG_RTC != 0)
155int clamp_value_wrap(int value, int max, int min);
156#endif
157#endif
158
Jonathan Gordonb58d3652011-06-01 14:41:49 +0000159enum 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 Gordon97a4c1e2011-07-20 14:11:15 +0000172 ACTIVITY_OPTIONSELECT,
Jonathan Gordon32dfc0c2011-08-04 13:40:24 +0000173 ACTIVITY_PLAYLISTBROWSER,
Jonathan Gordone918b7b2011-08-05 00:47:11 +0000174 ACTIVITY_PLUGIN,
Jonathan Gordon835683b2011-08-07 08:39:56 +0000175 ACTIVITY_CONTEXTMENU,
176 ACTIVITY_SYSTEMSCREEN,
177 ACTIVITY_TIMEDATESCREEN,
Jonathan Gordon101693f2011-11-15 13:22:02 +0000178 ACTIVITY_BOOKMARKSLIST,
Osborne Jacobsd5e676b2012-03-02 23:30:07 -0500179 ACTIVITY_SHORTCUTSMENU,
Thomas Martitza6483342014-01-16 00:26:45 +0100180 ACTIVITY_ID3SCREEN,
181 ACTIVITY_USBSCREEN
Jonathan Gordonb58d3652011-06-01 14:41:49 +0000182};
Michael Sevakis5663e1c2011-07-08 22:31:15 +0000183
184#if CONFIG_CODEC == SWCODEC
185void beep_play(unsigned int frequency, unsigned int duration,
186 unsigned int amplitude);
187
188enum system_sound
189{
190 SOUND_KEYCLICK = 0,
191 SOUND_TRACK_SKIP,
192 SOUND_TRACK_NO_MORE,
Solomon Peachy39b64f72018-12-15 19:15:28 -0500193 SOUND_LIST_EDGE_BEEP_WRAP,
194 SOUND_LIST_EDGE_BEEP_NOWRAP,
Michael Sevakis5663e1c2011-07-08 22:31:15 +0000195};
196
197/* Play a standard sound */
198void system_sound_play(enum system_sound sound);
199
Jonathan Gordoneb2ea7f2012-01-12 22:28:36 +1100200typedef bool (*keyclick_callback)(int action, void* data);
201void keyclick_set_callback(keyclick_callback cb, void* data);
Michael Sevakis5663e1c2011-07-08 22:31:15 +0000202/* Produce keyclick based upon button and global settings */
Michael Sevakisd05db0a2012-03-03 07:52:13 -0500203void keyclick_click(bool rawbutton, int action);
Michael Sevakis57a20d22012-04-30 16:27:01 -0400204
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 */
209struct mp3entry;
210int id3_get_replaygain_mode(const struct mp3entry *id3);
211void replaygain_update(void);
212#else
213static inline void replaygain_update(void) {}
Michael Sevakis5663e1c2011-07-08 22:31:15 +0000214#endif /* CONFIG_CODEC == SWCODEC */
215
Jonathan Gordonb58d3652011-06-01 14:41:49 +0000216void push_current_activity(enum current_activity screen);
217void pop_current_activity(void);
218enum current_activity get_current_activity(void);
219
Michael Sevakisaced6672017-09-18 06:00:05 -0400220/* format a sound value like: -1.05 dB */
221int format_sound_value(char *buf, size_t len, int snd, int val);
Jonathan Gordonb58d3652011-06-01 14:41:49 +0000222
Michael Sevakis0f5cb942006-11-06 18:07:30 +0000223#endif /* MISC_H */