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 ****************************************************************************/
27 #include "timefuncs.h"
29 #define ONE_KILOBYTE 1024
30 #define ONE_MEGABYTE (1024*1024)
32 /* The point of this function would be to return a string of the input data,
33 but never longer than 5 columns. Add suffix k and M when suitable...
34 Make sure to have space for 6 bytes in the buffer. 5 letters plus the
35 terminating zero byte. */
36 char *num2max5(unsigned int bytes
, char *max5
)
39 snprintf(max5
, 6, "%5d", bytes
);
42 if(bytes
< (9999*ONE_KILOBYTE
)) {
43 snprintf(max5
, 6, "%4dk", bytes
/ONE_KILOBYTE
);
46 if(bytes
< (100*ONE_MEGABYTE
)) {
47 /* 'XX.XM' is good as long as we're less than 100 megs */
48 snprintf(max5
, 6, "%2d.%0dM",
50 (bytes
%ONE_MEGABYTE
)/(ONE_MEGABYTE
/10) );
53 snprintf(max5
, 6, "%4dM", bytes
/ONE_MEGABYTE
);
57 /* Read (up to) a line of text from fd into buffer and return number of bytes
58 * read (which may be larger than the number of bytes stored in buffer). If
59 * an error occurs, -1 is returned (and buffer contains whatever could be
60 * read). A line is terminated by a LF char. Neither LF nor CR chars are
63 int read_line(int fd
, char* buffer
, int buffer_size
)
70 while (count
< buffer_size
)
74 if (1 != read(fd
, &c
, 1))
88 buffer
[MIN(count
, buffer_size
- 1)] = 0;
90 return errno
? -1 : num_read
;
94 int main(int argc
, char **argv
)
100 num2max5(atoi(argv
[1]), buffer
));
107 #ifdef HAVE_LCD_BITMAP
108 extern unsigned char lcd_framebuffer
[LCD_HEIGHT
/8][LCD_WIDTH
];
109 static unsigned char bmpheader
[] =
111 0x42, 0x4d, 0x3e, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x00,
112 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x40, 0x00,
113 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
114 0x00, 0x00, 0xc4, 0x0e, 0x00, 0x00, 0xc4, 0x0e, 0x00, 0x00, 0x00, 0x00,
115 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0xee, 0x90, 0x00, 0x00, 0x00,
119 static unsigned char buf
[112*8];
120 static unsigned char buf2
[112*8];
121 static char dummy
[2] = {0, 0};
123 void screen_dump(void)
128 char filename
[MAX_PATH
];
129 struct tm
*tm
= get_time();
132 for(y
= 0;y
< LCD_HEIGHT
/8;y
++)
134 for(x
= 0;x
< LCD_WIDTH
;x
++)
136 buf
[i
++] = lcd_framebuffer
[y
][x
];
140 memset(buf2
, 0, sizeof(buf2
));
142 for(y
= 0;y
< 64;y
++)
146 for(x
= 0;x
< 112/8;x
++)
150 buf2
[y
*112/8+x
] |= ((buf
[y
/8*112+x
*8+i
] >> shift
)
156 snprintf(filename
, MAX_PATH
, "/dump %04d-%02d-%02d %02d-%02d-%02d.bmp",
157 tm
->tm_year
+1900, tm
->tm_mon
+1, tm
->tm_mday
,
158 tm
->tm_hour
, tm
->tm_min
, tm
->tm_sec
);
159 f
= creat(filename
, O_WRONLY
);
162 write(f
, bmpheader
, sizeof(bmpheader
));
164 for(i
= 63;i
>= 0;i
--)
166 write(f
, &buf2
[i
*14], 14);
175 /* parse a line from a configuration file. the line format is:
179 Any whitespace before setting name or value (after ':') is ignored.
180 A # as first non-whitespace character discards the whole line.
181 Function sets pointers to null-terminated setting name and value.
182 Returns false if no valid config entry was found.
185 bool settings_parseline(char* line
, char** name
, char** value
)
189 while ( isspace(*line
) )
195 ptr
= strchr(line
, ':');
202 while (isspace(*ptr
))