1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Daniel Stenberg
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
29 #include "timefuncs.h"
32 #include "mp3_playback.h"
37 #include "backlight.h"
42 #define ONE_KILOBYTE 1024
43 #define ONE_MEGABYTE (1024*1024)
45 /* The point of this function would be to return a string of the input data,
46 but never longer than 5 columns. Add suffix k and M when suitable...
47 Make sure to have space for 6 bytes in the buffer. 5 letters plus the
48 terminating zero byte. */
49 char *num2max5(unsigned int bytes
, char *max5
)
52 snprintf(max5
, 6, "%5d", bytes
);
55 if(bytes
< (9999*ONE_KILOBYTE
)) {
56 snprintf(max5
, 6, "%4dk", bytes
/ONE_KILOBYTE
);
59 if(bytes
< (100*ONE_MEGABYTE
)) {
60 /* 'XX.XM' is good as long as we're less than 100 megs */
61 snprintf(max5
, 6, "%2d.%0dM",
63 (bytes
%ONE_MEGABYTE
)/(ONE_MEGABYTE
/10) );
66 snprintf(max5
, 6, "%4dM", bytes
/ONE_MEGABYTE
);
70 /* Read (up to) a line of text from fd into buffer and return number of bytes
71 * read (which may be larger than the number of bytes stored in buffer). If
72 * an error occurs, -1 is returned (and buffer contains whatever could be
73 * read). A line is terminated by a LF char. Neither LF nor CR chars are
76 int read_line(int fd
, char* buffer
, int buffer_size
)
83 while (count
< buffer_size
)
87 if (1 != read(fd
, &c
, 1))
101 buffer
[MIN(count
, buffer_size
- 1)] = 0;
103 return errno
? -1 : num_read
;
107 int main(int argc
, char **argv
)
113 num2max5(atoi(argv
[1]), buffer
));
120 #ifdef HAVE_LCD_BITMAP
121 extern unsigned char lcd_framebuffer
[LCD_HEIGHT
/8][LCD_WIDTH
];
122 static const unsigned char bmpheader
[] =
124 0x42, 0x4d, 0x3e, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00,
125 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x40, 0x00,
126 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
127 0x00, 0x00, 0xc4, 0x0e, 0x00, 0x00, 0xc4, 0x0e, 0x00, 0x00, 0x00, 0x00,
128 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0xee, 0x90, 0x00, 0x00, 0x00,
132 void screen_dump(void)
136 int src_byte
, src_mask
, dst_mask
;
137 char filename
[MAX_PATH
];
138 static unsigned char line_block
[8][16];
139 struct tm
*tm
= get_time();
141 snprintf(filename
, MAX_PATH
, "/dump %04d-%02d-%02d %02d-%02d-%02d.bmp",
142 tm
->tm_year
+1900, tm
->tm_mon
+1, tm
->tm_mday
,
143 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
145 fh
= creat(filename
, O_WRONLY
);
149 write(fh
, bmpheader
, sizeof(bmpheader
));
151 /* BMP image goes bottom up */
152 for (by
= LCD_HEIGHT
/8 - 1; by
>= 0; by
--)
154 memset(&line_block
[0][0], 0, 8*16);
156 for (bx
= 0; bx
< LCD_WIDTH
/8; bx
++)
159 for (ix
= 7; ix
>= 0; ix
--)
161 src_byte
= lcd_framebuffer
[by
][8*bx
+ix
];
163 for (iy
= 7; iy
>= 0; iy
--)
165 if (src_byte
& src_mask
)
166 line_block
[iy
][bx
] |= dst_mask
;
173 write(fh
, &line_block
[0][0], 8*16);
179 /* parse a line from a configuration file. the line format is:
183 Any whitespace before setting name or value (after ':') is ignored.
184 A # as first non-whitespace character discards the whole line.
185 Function sets pointers to null-terminated setting name and value.
186 Returns false if no valid config entry was found.
189 bool settings_parseline(char* line
, char** name
, char** value
)
193 while ( isspace(*line
) )
199 ptr
= strchr(line
, ':');
206 while (isspace(*ptr
))
212 bool clean_shutdown(void)
217 if(!charger_inserted())
220 splash(0, true, str(LANG_SHUTTINGDOWN
));
224 while(ata_disk_is_active())
228 #if CONFIG_KEYPAD == ONDIO_PAD
239 int default_event_handler_ex(int event
, void (*callback
)(void *), void *parameter
)
243 case SYS_USB_CONNECTED
:
244 if (callback
!= NULL
)
247 if (!mmc_detect() || (mmc_remove_request() == SYS_MMC_EXTRACTED
))
250 return SYS_USB_CONNECTED
;
252 if (callback
!= NULL
)
254 if (!clean_shutdown())
261 int default_event_handler(int event
)
263 return default_event_handler_ex(event
, NULL
, NULL
);