Subversion Repositories freemyipod

Rev

Rev 843 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
828 theseven 1
//
2
//
3
//    Copyright 2011 TheSeven
4
//
5
//
6
//    This file is part of emCORE.
7
//
8
//    emCORE is free software: you can redistribute it and/or
9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
13
//    emCORE is distributed in the hope that it will be useful,
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//
22
 
23
 
24
#include "emcoreapp.h"
25
#include "util.h"
26
#include "main.h"
27
 
28
 
879 theseven 29
static struct rtc_datetime datetime;
30
static unsigned int batt_level;
31
static long next_refresh = 0;
32
 
33
 
828 theseven 34
struct emcorelib_header* loadlib(uint32_t identifier, uint32_t version, char* filename)
35
{
36
    struct emcorelib_header* lib = get_library(identifier, version, LIBSOURCE_BOOTFLASH, filename);
37
    if (!lib) panicf(PANIC_KILLTHREAD, "Could not load %s", filename);
38
    return lib;
39
}
40
 
41
void* loadpng(struct libpng_api* libpng, const char* buf, const uint32_t size,
42
              void* (*decoder)(struct png_info* handle))
43
{
44
    if (size == 0) panicf(PANIC_KILLTHREAD, "Could not load PNG at 0x%08X", buf);
45
    struct png_info* handle = libpng->png_open(buf, size);
46
    if (!handle) panicf(PANIC_KILLTHREAD, "Could not parse PNG at 0x%08X", buf);
47
    void* out = decoder(handle);
48
    if (!out) panicf(PANIC_KILLTHREAD, "Could not decode PNG at 0x%08X", buf);
49
    libpng->png_destroy(handle);
50
    return out;
51
}
52
 
53
bool update_display(struct chooser_data* data)
54
{
55
    char buf[6];
879 theseven 56
    if (!next_refresh || TIMEOUT_EXPIRED(next_refresh, 10000000))
57
    {
58
        rtc_read_datetime(&datetime);
59
        batt_level = 22 * read_battery_mwh_current(0) / read_battery_mwh_full(0);
60
        next_refresh = USEC_TIMER;
61
    }
62
    snprintf(buf, sizeof(buf), "%02d:%02d", datetime.hour, datetime.minute);
828 theseven 63
    // clock
838 theseven 64
    rendertext(framebuf, 143, 4, 176, 0xff3f0000, 0x3fffffff, buf);
828 theseven 65
    // draw the battery meter box
66
    // top line
838 theseven 67
    ui->blendcolor(24, 1, 0xcf7f0000, framebuf, 4, 4, 176, framebuf, 4, 4, 176);
828 theseven 68
    // bottom line
838 theseven 69
    ui->blendcolor(24, 1, 0xcf7f0000, framebuf, 4, 11, 176, framebuf, 4, 11, 176);
828 theseven 70
    // left line
838 theseven 71
    ui->blendcolor(1, 6, 0xcf7f0000, framebuf, 4, 5, 176, framebuf, 4, 5, 176);
828 theseven 72
    // right line
838 theseven 73
    ui->blendcolor(1, 6, 0xcf7f0000, framebuf, 27, 5, 176, framebuf, 27, 5, 176);
74
    // top - right
75
    ui->blendcolor(1, 4, 0xcf7f0000, framebuf, 28, 6, 176, framebuf, 28, 6, 176);
828 theseven 76
    // remaining battery level
838 theseven 77
    ui->blendcolor(batt_level, 6, 0x7fff7f7f, framebuf, 5, 5, 176, framebuf, 5, 5, 176);
828 theseven 78
    // background of the rest space
838 theseven 79
    ui->blendcolor(22 - batt_level, 6, 0x7f7f0000, framebuf, 5 + batt_level,
828 theseven 80
                   5, 176, framebuf, 5 + batt_level, 5, 176);
838 theseven 81
    render_snow();
828 theseven 82
    return false;
83
}
84
 
85
void message(int x, const char* line1, const char* line2)
86
{
87
    rendertext(framebuf, x, 73, 176, 0xff3333ff, 0xa0000000, line1);
88
    rendertext(framebuf, x, 81, 176, 0xff3333ff, 0xa0000000, line2);
89
    displaylcd(0, 0, 176, 132, framebuf, 0, 0, 176);
90
    sleep(5000000);
91
}