blob: 0d4cba6cd3641caf9a9fa156d79fc8560620e658 [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[];
30extern const unsigned char * const * const kbyte_units;
31
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.*/
Michael Sevakis0f5cb942006-11-06 18:07:30 +000037char *output_dyn_value(char *buf, int buf_size, int value,
Nils Wallménius79f19b92009-10-17 13:40:42 +000038 const unsigned char * const *units, bool bin_scale);
Linus Nielsen Feltzing75b41a82003-05-04 02:04:31 +000039
Magnus Holmgren14ba91e2007-02-17 13:36:44 +000040/* 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 */
46void format_time(char* buf, int buf_size, long t);
47
Nils Wallméniusdabcb812008-05-01 10:13:12 +000048/* Ask the user if they really want to erase the current dynamic playlist
49 * returns true if the playlist should be replaced */
50bool warn_on_pl_erase(void);
51
Linus Nielsen Feltzing75b41a82003-05-04 02:04:31 +000052/* 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 */
58int read_line(int fd, char* buffer, int buffer_size);
Miika Pekkarinena1ac7432006-10-21 20:37:33 +000059int fast_readline(int fd, char *buf, int buf_size, void *parameters,
Miika Pekkarinend0084ff2011-06-23 20:22:00 +000060 int (*callback)(int n, char *buf, void *parameters));
Linus Nielsen Feltzinga8dab4c2004-06-30 13:31:14 +000061
Linus Nielsen Feltzing26440c92004-07-05 11:15:50 +000062bool settings_parseline(char* line, char** name, char** value);
Jean-Philippe Bernardyf64939e2005-02-07 22:56:37 +000063long default_event_handler_ex(long event, void (*callback)(void *), void *parameter);
64long default_event_handler(long event);
Jens Arnold178c5652007-04-09 13:39:37 +000065bool list_stop_handler(void);
Boris Gjenerofdc29d02011-12-19 20:12:52 +000066void car_adapter_mode_init(void) INIT_ATTR;
Linus Nielsen Feltzing60895bc2005-09-02 05:39:09 +000067extern int show_logo(void);
Linus Nielsen Feltzing26440c92004-07-05 11:15:50 +000068
Nick Peskett1b781df2011-12-20 08:15:36 +000069/* 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 Martitz8c655cf2012-07-18 23:26:21 +020076int split_string(char *str, const char needle, char *vector[], int vector_length);
Dominik Riebeling02103a22008-08-02 20:39:03 +000077int open_utf8(const char* pathname, int flags);
78
Peter D'Hoyed2b30552007-03-30 21:54:48 +000079#ifdef BOOTFILE
Thomas Martitzcfda0972009-11-25 22:54:36 +000080#if !defined(USB_NONE) && !defined(USB_HANDLED_BY_OF) \
81 || defined(HAVE_HOTSWAP_STORAGE_AS_MAIN)
Peter D'Hoyed2b30552007-03-30 21:54:48 +000082void check_bootfile(bool do_rolo);
83#endif
Peter D'Hoyedc33e1e2007-03-30 23:36:10 +000084#endif
Peter D'Hoyed2b30552007-03-30 21:54:48 +000085
Nils Wallméniusf46657e2007-05-30 17:57:32 +000086/* check range, set volume and save settings */
87void setvol(void);
88
Brandon Low74cbb0a2007-06-17 21:16:34 +000089#ifdef HAVE_LCD_COLOR
Dave Chapmane92d2c52008-03-21 13:41:35 +000090int hex_to_rgb(const char* hex, int* color);
Brandon Low74cbb0a2007-06-17 21:16:34 +000091#endif
92
Nils Wallménius4acae4d2007-11-18 14:12:01 +000093char* strrsplt(char* str, int c);
Nils Wallménius5a557722009-02-08 11:09:55 +000094char* skip_whitespace(char* const str);
Robert Kuklad87b0372007-11-21 21:28:27 +000095
Nicolas Pennequin536b5a02008-01-18 10:02:03 +000096/*
97 * removes the extension of filename (if it doesn't start with a .)
98 * puts the result in buffer
99 */
Magnus Holmgren22350812008-02-06 19:51:19 +0000100char *strip_extension(char* buffer, int buffer_size, const char *filename);
Robert Kuklad87b0372007-11-21 21:28:27 +0000101
Tomer Shalev83d24f82009-10-23 13:29:19 +0000102#ifdef HAVE_LCD_BITMAP
Jonathan Gordon489962d2010-08-10 14:15:03 +0000103bool parse_color(enum screen_type screen, char *text, int *value);
Dave Chapmane92d2c52008-03-21 13:41:35 +0000104
Tomer Shalev83d24f82009-10-23 13:29:19 +0000105/* only used in USB HID and set_time screen */
106#if defined(USB_ENABLE_HID) || (CONFIG_RTC != 0)
107int clamp_value_wrap(int value, int max, int min);
108#endif
109#endif
110
Jonathan Gordonb58d3652011-06-01 14:41:49 +0000111enum 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 Gordon97a4c1e2011-07-20 14:11:15 +0000124 ACTIVITY_OPTIONSELECT,
Jonathan Gordon32dfc0c2011-08-04 13:40:24 +0000125 ACTIVITY_PLAYLISTBROWSER,
Jonathan Gordone918b7b2011-08-05 00:47:11 +0000126 ACTIVITY_PLUGIN,
Jonathan Gordon835683b2011-08-07 08:39:56 +0000127 ACTIVITY_CONTEXTMENU,
128 ACTIVITY_SYSTEMSCREEN,
129 ACTIVITY_TIMEDATESCREEN,
Jonathan Gordon101693f2011-11-15 13:22:02 +0000130 ACTIVITY_BOOKMARKSLIST,
Osborne Jacobsd5e676b2012-03-02 23:30:07 -0500131 ACTIVITY_SHORTCUTSMENU,
Thomas Martitza6483342014-01-16 00:26:45 +0100132 ACTIVITY_ID3SCREEN,
133 ACTIVITY_USBSCREEN
Jonathan Gordonb58d3652011-06-01 14:41:49 +0000134};
Michael Sevakis5663e1c2011-07-08 22:31:15 +0000135
136#if CONFIG_CODEC == SWCODEC
137void beep_play(unsigned int frequency, unsigned int duration,
138 unsigned int amplitude);
139
140enum system_sound
141{
142 SOUND_KEYCLICK = 0,
143 SOUND_TRACK_SKIP,
144 SOUND_TRACK_NO_MORE,
145};
146
147/* Play a standard sound */
148void system_sound_play(enum system_sound sound);
149
Jonathan Gordoneb2ea7f2012-01-12 22:28:36 +1100150typedef bool (*keyclick_callback)(int action, void* data);
151void keyclick_set_callback(keyclick_callback cb, void* data);
Michael Sevakis5663e1c2011-07-08 22:31:15 +0000152/* Produce keyclick based upon button and global settings */
Michael Sevakisd05db0a2012-03-03 07:52:13 -0500153void keyclick_click(bool rawbutton, int action);
Michael Sevakis57a20d22012-04-30 16:27:01 -0400154
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 */
159struct mp3entry;
160int id3_get_replaygain_mode(const struct mp3entry *id3);
161void replaygain_update(void);
162#else
163static inline void replaygain_update(void) {}
Michael Sevakis5663e1c2011-07-08 22:31:15 +0000164#endif /* CONFIG_CODEC == SWCODEC */
165
Jonathan Gordonb58d3652011-06-01 14:41:49 +0000166void push_current_activity(enum current_activity screen);
167void pop_current_activity(void);
168enum current_activity get_current_activity(void);
169
170
Michael Sevakis0f5cb942006-11-06 18:07:30 +0000171#endif /* MISC_H */