summaryrefslogtreecommitdiffstats
path: root/utils/wpseditor/libwps/src/api.c
blob: 485efa8e00319c51da4748d3d6b9049f8f539c45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#include <stdio.h>
#include <stdlib.h>
#include "sound.h"
#include "api.h"
#include "proxy.h"
#include "dummies.h"
#include "scroll_engine.h"
#include "wpsstate.h"
#include <string.h>

struct proxy_api *xapi;

void get_current_vp(struct viewport_api *avp);
/*************************************************************

*************************************************************/
#ifdef HAVE_LCD_BITMAP
void screen_clear_area(struct screen * display, int xstart, int ystart,
                       int width, int height) {
    display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
    display->fillrect(xstart, ystart, width, height);
    display->set_drawmode(DRMODE_SOLID);
}
#endif

bool load_wps_backdrop(char* filename) {
    return xapi->load_wps_backdrop(filename);
}

bool load_remote_wps_backdrop(char* filename) {
    return xapi->load_remote_wps_backdrop(filename);
}

int read_bmp_file(const char* filename,struct bitmap *bm, int maxsize,int format) {
    if (!xapi->read_bmp_file)
    {
        DEBUGF1("can't read bmp file! NULL api!\n");
        return -1;
    }
    bm->format = 3;//FORMAT_ANY?
    bm->data = (unsigned char*)malloc(255);
    memset(bm->data,0,255);
    strcpy((char*)bm->data,filename);
    //bm->data[strlen(filename)] = '\0';
    xapi->read_bmp_file(filename,&bm->width, &bm->height);
    return 1;
}

bool load_wps_backdrop2(char* filename) {
    DEBUGF1("load_wps_backdrop(char* filename='%s')",filename);
    return true;
}

bool load_remote_wps_backdrop2(char* filename) {
    DEBUGF1("load_remote_wps_backdrop2(char* filename='%s')",filename);
    return true;
}

void stop_scroll() {
    DEBUGF3("stop_scroll\n");
    return;
}

void puts_scroll(int x, int y, const unsigned char *string) {
    DEBUGF2("puts_scroll(int x=%d, int y=%d, const unsigned char *string='%s'\n",x,y,string);
}

void putsxy(int x, int y, const unsigned char *str) {
    DEBUGF2("putsxy(int =%d, int y=%d, const unsigned char *str='%s')\n",x,y,str);
}

void lcd_update() {
    DEBUGF3("update\n");
}

void clear_viewport(int x, int y, int w, int h, int color) {
    DEBUGF3("clear_viewport(int x=%d, int y=%d, int w=%d, int h=%d, int color=%d)\n", x, y, w, h, color);
};

int getstringsize(const unsigned char *str, int *w, int *h) {
    //DEBUGF1("getstringsize(const unsigned char *str=\"%s\", int *w=%d, int *h=%d \n",str,*w,*h);
    *w=strlen((char*)str)*sysfont.maxwidth;
    *h=sysfont.height;
    return 1;
}

void set_wpsstate(struct wpsstate state){
    sysfont.height = state.fontheight;
    sysfont.maxwidth = state.fontwidth;
    global_settings.volume = state.volume;
    battery_percent = state.battery_level;
    _audio_status = state.audio_status;
}

void set_trackstate(struct trackstate state){
    gui_wps[0].state->id3->title = state.title;
    gui_wps[0].state->id3->artist = state.artist;
    gui_wps[0].state->id3->album = state.album;
    gui_wps[0].state->id3->elapsed = state.elapsed;
    gui_wps[0].state->id3->length = state.length;
}

void set_next_trackstate(struct trackstate state)
{
    gui_wps[0].state->nid3->title = state.title;
    gui_wps[0].state->nid3->artist = state.artist;
    gui_wps[0].state->nid3->album = state.album;
    gui_wps[0].state->nid3->elapsed = state.elapsed;
    gui_wps[0].state->nid3->length = state.length;
}

enum api_playmode playmodes[PLAYMODES_NUM] = {
    API_STATUS_PLAY,
    API_STATUS_STOP,
    API_STATUS_PAUSE,
    API_STATUS_FASTFORWARD,
    API_STATUS_FASTBACKWARD
};

const char *playmodeNames[] = {
    "Play", "Stop", "Pause", "FastForward", "FastBackward"
};


void set_audio_status(int status){
    DEBUGF1("%s",playmodeNames[status]);
    switch(status){
        case API_STATUS_PLAY:
            _audio_status = AUDIO_STATUS_PLAY;
            status_set_ffmode(STATUS_PLAY);
            break;
        case API_STATUS_STOP:
            _audio_status = 0;
            status_set_ffmode(STATUS_STOP);
            break;
        case API_STATUS_PAUSE:
            _audio_status = AUDIO_STATUS_PAUSE;
            status_set_ffmode(STATUS_PLAY);
            break;
        case API_STATUS_FASTFORWARD:
            status_set_ffmode(STATUS_FASTFORWARD);
            break;
        case API_STATUS_FASTBACKWARD:
            status_set_ffmode(STATUS_FASTBACKWARD);
            break;
        default:
            DEBUGF1("ERR: Unknown status");
    }
}

void test_api(struct proxy_api *api) {
    if (!api->stop_scroll)
        api->stop_scroll=stop_scroll;
    if (!api->set_viewport)
        api->set_viewport=lcd_set_viewport;
    if (!api->clear_viewport)
        api->clear_viewport=clear_viewport;
    if (!api->getstringsize)
        api->getstringsize=getstringsize;
    if (!api->getwidth)
        api->getwidth=lcd_getwidth;
    if (!api->getheight)
        api->getheight=lcd_getheight;
    if (!api->set_drawmode)
        api->set_drawmode=lcd_set_drawmode;
    if (!api->puts_scroll)
        api->puts_scroll=puts_scroll;
    if (!api->update)
        api->update=lcd_update;
    if (!api->clear_display)
        api->clear_display=lcd_clear_display;
    if (!api->getfont)
        api->getfont=lcd_getfont;
    if (!api->putsxy)
        api->putsxy=putsxy;

#if LCD_DEPTH > 1
    if (!api->get_foreground)
        api->get_foreground=lcd_get_foreground;
    if (!api->get_background)
        api->get_background=lcd_get_background;
#endif
    if (!api->load_remote_wps_backdrop)
        api->load_remote_wps_backdrop = load_remote_wps_backdrop2;
    if (!api->load_wps_backdrop)
        api->load_wps_backdrop = load_wps_backdrop2;
    //dbgf = printf;
}

/**************************************************************

**************************************************************/

int set_api(struct proxy_api* api) {
    if (api->debugf)
        dbgf = api->debugf;
    screens[0].screen_type=SCREEN_MAIN;
    screens[0].lcdwidth=LCD_WIDTH;
    screens[0].lcdheight=LCD_HEIGHT;
    screens[0].depth=LCD_DEPTH;
#ifdef HAVE_LCD_COLOR
    screens[0].is_color=true;
#else
    screens[0].is_color=false;
#endif
    if (api->getwidth)
        screens[0].getwidth = api->getwidth;
    if (api->stop_scroll)
        screens[0].stop_scroll=api->stop_scroll;
    screens[0].scroll_stop = lcd_scroll_stop;
    if (api->set_viewport)
        screens[0].set_viewport=api->set_viewport;
    if (api->clear_viewport)
        screens[0].clear_viewport=lcd_clear_viewport;
    if (api->getstringsize)
        screens[0].getstringsize=api->getstringsize;
    if (api->getwidth)
        screens[0].getwidth=api->getwidth;
    if (api->getheight)
        screens[0].getheight=api->getheight;
    if (api->set_drawmode)
        screens[0].set_drawmode=api->set_drawmode;
    if (api->fillrect)
        screens[0].fillrect=api->fillrect;
    if (api->puts_scroll)
        screens[0].puts_scroll=api->puts_scroll;
    if (api->transparent_bitmap_part)
        screens[0].transparent_bitmap_part=api->transparent_bitmap_part;
    if (api->update)
        screens[0].update=api->update;
    if (api->clear_display)
        screens[0].clear_display=api->clear_display;
    if (api->getfont)
        screens[0].getfont=api->getfont;
    if (api->hline)
        screens[0].hline=api->hline;
    if (api->vline)
        screens[0].vline=api->vline;
    if (api->drawpixel)
        screens[0].drawpixel=api->drawpixel;
    if (api->putsxy)
        screens[0].putsxy=api->putsxy;
#if LCD_DEPTH > 1
    if (api->get_foreground)
        screens[0].get_foreground=api->get_foreground;
    if (api->get_background)
        screens[0].get_background=api->get_background;
#endif

    screens[0].bitmap_part = api->bitmap_part;
    /**************************
    *          OUT            *
    **************************/
    api->get_model_name = get_model_name;
    api->get_current_vp = get_current_vp;
    api->set_wpsstate = set_wpsstate;
    api->set_trackstate = set_trackstate;
    api->set_next_trackstate= set_next_trackstate;
    api->set_audio_status= set_audio_status;
    xapi = api;
    return 0;
}