summaryrefslogtreecommitdiff
path: root/apps/plugins/remote_control.c
blob: a5ad4423a1a156ac04cf0494db7bf18586d5a4ae (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
/***************************************************************************
*             __________               __   ___.
*   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
*   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
*   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
*   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
*                     \/            \/     \/    \/            \/
* $Id$
*
* Copyright (C) 2009 Tomer Shalev
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/

#include "plugin.h"

#include "lib/pluginlib_actions.h"



#define PLUGIN_CONTINUE 10

static inline void remote_control_setcolors(void);

/*****************************************************************************
* remote_control_setcolors() set the foreground and background colors.
******************************************************************************/
static inline void remote_control_setcolors(void)
{
#ifdef HAVE_LCD_COLOR
    rb->lcd_set_background(LCD_RGBPACK(181, 181, 222));
    rb->lcd_set_foreground(LCD_BLACK);
#endif
}

static int menu_desktop(void)
{
    int selection = 0;

    MENUITEM_STRINGLIST(menu, "Desktop", NULL, "Escape", "Windows", "F10",
            "Page Up", "Page Down");
    while(1)
    {
        int id = HID_GENERIC_DESKTOP_UNDEFINED;

        switch (rb->do_menu(&menu, &selection, NULL, false))
        {
            case 0: /* Escape */
                id = HID_KEYBOARD_ESCAPE;
                break;
            case 1: /* Windows */
                /* Not sure whether this is the right key */
                id = HID_KEYBOARD_LEFT_GUI;
                break;
            case 2: /* F10 */
                id = HID_KEYBOARD_F10;
                break;
            case 3: /* Page Up */
                id = HID_KEYBOARD_PAGE_UP;
                break;
            case 4: /* Page Down */
                id = HID_KEYBOARD_PAGE_DOWN;
                break;
            case MENU_ATTACHED_USB:
                return PLUGIN_USB_CONNECTED;
            case GO_TO_PREVIOUS:
                return PLUGIN_CONTINUE;
            default:
                break;
        }

        if (id != HID_GENERIC_DESKTOP_UNDEFINED)
            rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, id);
    }
}

static int menu_presentation(void)
{
    int selection = 0;

    MENUITEM_STRINGLIST(menu, "Presentation", NULL, "Next Slide", "Prev Slide",
            "Start Slideshow", "Leave Slideshow", "Black Screen",
            "White Screen");
    while(1)
    {
        int id = HID_GENERIC_DESKTOP_UNDEFINED;

        switch (rb->do_menu(&menu, &selection, NULL, false))
        {
            case 0: /* Next Slide */
                id = HID_KEYBOARD_N;
                break;
            case 1: /* Prev Slide */
                id = HID_KEYBOARD_P;
                break;
            case 2: /* Start Slideshow */
                id = HID_KEYBOARD_F5;
                break;
            case 3: /* Leave Slideshow */
                id = HID_KEYBOARD_ESCAPE;
                break;
            case 4: /* Black Screen */
                id = HID_KEYBOARD_DOT;
                break;
            case 5: /* White Screen */
                id = HID_KEYBOARD_COMMA;
                break;
            case MENU_ATTACHED_USB:
                return PLUGIN_USB_CONNECTED;
            case GO_TO_PREVIOUS:
                return PLUGIN_CONTINUE;
            default:
                break;
        }

        if (id != HID_GENERIC_DESKTOP_UNDEFINED)
            rb->usb_hid_send(HID_USAGE_PAGE_KEYBOARD_KEYPAD, id);
    }
}

static int menu_media_player(void)
{
    int selection = 0;

    MENUITEM_STRINGLIST(menu, "Media Player", NULL, "Play", "Stop", "Next",
            "Previous", "Volume Up", "Volume Down", "Mute");
    while(1)
    {
        int id = HID_CONSUMER_USAGE_UNASSIGNED;

        switch (rb->do_menu(&menu, &selection, NULL, false))
        {
            case 0: /* Play */
                id = HID_CONSUMER_USAGE_PLAY_PAUSE;
                break;
            case 1: /* Stop */
                id = HID_CONSUMER_USAGE_STOP;
                break;
            case 2: /* Next */
                id = HID_CONSUMER_USAGE_SCAN_NEXT_TRACK;
                break;
            case 3: /* Previous */
                id = HID_CONSUMER_USAGE_SCAN_PREVIOUS_TRACK;
                break;
            case 4: /* Volume Up */
                id = HID_CONSUMER_USAGE_VOLUME_INCREMENT;
                break;
            case 5: /* Volume Down */
                id = HID_CONSUMER_USAGE_VOLUME_DECREMENT;
                break;
            case 6: /* Mute */
                id = HID_CONSUMER_USAGE_MUTE;
                break;
            case MENU_ATTACHED_USB:
                return PLUGIN_USB_CONNECTED;
            case GO_TO_PREVIOUS:
                return PLUGIN_CONTINUE;
            default:
                break;
        }

        if (id != HID_CONSUMER_USAGE_UNASSIGNED)
            rb->usb_hid_send(HID_USAGE_PAGE_CONSUMER, id);
    }
}

/*****************************************************************************
* plugin entry point.
******************************************************************************/
enum plugin_status plugin_start(const void* parameter)
{
    enum plugin_status rc = PLUGIN_CONTINUE;
    int selection = 0;

    (void)parameter;

    rb->lcd_clear_display();

#if LCD_DEPTH > 1
    rb->lcd_set_backdrop(NULL);
#endif
    rb->lcd_setfont(FONT_SYSFIXED);

    remote_control_setcolors();

    MENUITEM_STRINGLIST(menu, "Remote Control", NULL, "Desktop", "Presentation",
            "Media Player", "Quit");
    while(rc == PLUGIN_CONTINUE)
    {
        switch (rb->do_menu(&menu, &selection, NULL, false))
        {
            case 0: /* Desktop */
                rc = menu_desktop();
                break;
            case 1: /* Presentation */
                rc = menu_presentation();
                break;
            case 2: /* Media Player */
                rc = menu_media_player();
                break;
            case 3: /* Quit */
            case GO_TO_PREVIOUS:
                rc = PLUGIN_OK;
                break;
            case MENU_ATTACHED_USB:
                rc = PLUGIN_USB_CONNECTED;
                break;
            default:
                break;
        }
    }
    rb->lcd_setfont(FONT_UI);

    return rc;
}