Subversion Repositories freemyipod

Rev

Rev 838 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
808 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
 
29
struct emcorelib_header* loadlib(uint32_t identifier, uint32_t version, char* filename)
30
{
31
    struct emcorelib_header* lib = get_library(identifier, version, LIBSOURCE_BOOTFLASH, filename);
32
    if (!lib) panicf(PANIC_KILLTHREAD, "Could not load %s", filename);
33
    return lib;
34
}
35
 
36
void* loadpng(struct libpng_api* libpng, const char* buf, const uint32_t size,
37
              void* (*decoder)(struct png_info* handle))
38
{
39
    if (size == 0) panicf(PANIC_KILLTHREAD, "Could not load PNG at 0x%08X", buf);
40
    struct png_info* handle = libpng->png_open(buf, size);
41
    if (!handle) panicf(PANIC_KILLTHREAD, "Could not parse PNG at 0x%08X", buf);
42
    void* out = decoder(handle);
43
    if (!out) panicf(PANIC_KILLTHREAD, "Could not decode PNG at 0x%08X", buf);
44
    libpng->png_destroy(handle);
45
    return out;
46
}
47
 
48
bool update_display(struct chooser_data* data)
49
{
50
    char buf[6];
51
    struct rtc_datetime dt;
52
    rtc_read_datetime(&dt);
53
    snprintf(buf, sizeof(buf), "%02d:%02d", dt.hour, dt.minute);
54
    // clock
843 theseven 55
    rendertext(framebuf, 287, 4, 320, 0xffffcccc, 0, buf);
808 theseven 56
    // draw the battery meter box
57
    // top line
843 theseven 58
    ui->blendcolor(24, 1, 0xffffcccc, framebuf, 4, 4, 320, framebuf, 4, 4, 320);
808 theseven 59
    // bottom line
843 theseven 60
    ui->blendcolor(24, 1, 0xffffcccc, framebuf, 4, 11, 320, framebuf, 4, 11, 320);
808 theseven 61
    // left line
843 theseven 62
    ui->blendcolor(1, 6, 0xffffcccc, framebuf, 4, 5, 320, framebuf, 4, 5, 320);
808 theseven 63
    // right line
843 theseven 64
    ui->blendcolor(1, 6, 0xffffcccc, framebuf, 27, 5, 320, framebuf, 27, 5, 320);
838 theseven 65
    // top - right
843 theseven 66
    ui->blendcolor(1, 4, 0xffffcccc, framebuf, 28, 6, 320, framebuf, 28, 6, 320);
808 theseven 67
    unsigned int batt_level = 22 * read_battery_mwh_current(0) / read_battery_mwh_full(0);
68
    // remaining battery level
843 theseven 69
    ui->blendcolor(batt_level, 6, 0xc0ffcccc, framebuf, 5, 5, 320, framebuf, 5, 5, 320);
808 theseven 70
    // background of the rest space
843 theseven 71
    ui->blendcolor(22 - batt_level, 6, 0x40000000, framebuf, 5 + batt_level,
823 theseven 72
                   5, 320, framebuf, 5 + batt_level, 5, 320);
808 theseven 73
    return false;
74
}
75
 
76
void message(int x, const char* line1, const char* line2)
77
{
78
    rendertext(framebuf, x, 140, 320, 0xff3333ff, 0xa0000000, line1);
79
    rendertext(framebuf, x, 148, 320, 0xff3333ff, 0xa0000000, line2);
80
    displaylcd(0, 0, 320, 240, framebuf, 0, 0, 320);
81
    sleep(5000000);
82
}