A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 Itai Shaked
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 **************************************************************************/
21#include "plugin.h"
22#include "lib/mylcd.h"
23#include "lib/pluginlib_actions.h"
24
25#define NUM_PARTICLES (LCD_WIDTH * LCD_HEIGHT / 72)
26#define SNOW_HEIGHT LCD_HEIGHT
27#define SNOW_WIDTH LCD_WIDTH
28
29static const struct button_mapping *plugin_contexts[] = { pla_main_ctx };
30
31/* PLA definitions */
32#define SNOW_QUIT PLA_EXIT
33
34#if (CONFIG_KEYPAD == IPOD_1G2G_PAD) \
35 || (CONFIG_KEYPAD == IPOD_3G_PAD) \
36 || (CONFIG_KEYPAD == IPOD_4G_PAD)
37#define SNOW_QUIT2 PLA_UP
38#else
39#define SNOW_QUIT2 PLA_CANCEL
40#endif
41static short particles[NUM_PARTICLES][2];
42
43#if LCD_WIDTH >= 160
44#define FLAKE_WIDTH 5
45static const unsigned char flake[] = {0x0a,0x04,0x1f,0x04,0x0a};
46#else
47#define FLAKE_WIDTH 3
48static const unsigned char flake[] = {0x02,0x07,0x02};
49#endif
50
51static bool particle_exists(int particle)
52{
53 if (particles[particle][0]>=0 && particles[particle][1]>=0 &&
54 particles[particle][0]<SNOW_WIDTH && particles[particle][1]<SNOW_HEIGHT)
55 return true;
56 else
57 return false;
58}
59
60static int create_particle(void)
61{
62 int i;
63
64 for (i=0; i<NUM_PARTICLES; i++) {
65 if (!particle_exists(i)) {
66 particles[i][0]=(rb->rand()%SNOW_WIDTH);
67 particles[i][1]=0;
68 return i;
69 }
70 }
71 return -1;
72}
73
74static void snow_move(void)
75{
76 int i;
77
78 if (!(rb->rand()%2))
79 create_particle();
80
81 for (i=0; i<NUM_PARTICLES; i++) {
82 if (particle_exists(i)) {
83 mylcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
84 rb->lcd_fillrect(particles[i][0],particles[i][1],
85 FLAKE_WIDTH,FLAKE_WIDTH);
86 mylcd_set_drawmode(DRMODE_SOLID);
87#ifdef HAVE_REMOTE_LCD
88 if (particles[i][0] <= LCD_REMOTE_WIDTH
89 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
90 rb->lcd_remote_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
91 rb->lcd_remote_fillrect(particles[i][0],particles[i][1],
92 FLAKE_WIDTH,FLAKE_WIDTH);
93 rb->lcd_remote_set_drawmode(DRMODE_SOLID);
94 }
95#endif
96 switch ((rb->rand()%7)) {
97 case 0:
98 particles[i][0]++;
99 break;
100
101 case 1:
102 particles[i][0]--;
103 break;
104
105 case 2:
106 break;
107
108 default:
109 particles[i][1]++;
110 break;
111 }
112 if (particle_exists(i))
113 rb->lcd_mono_bitmap(flake,particles[i][0],particles[i][1],
114 FLAKE_WIDTH,FLAKE_WIDTH);
115#ifdef HAVE_REMOTE_LCD
116 if (particles[i][0] <= LCD_REMOTE_WIDTH
117 && particles[i][1] <= LCD_REMOTE_HEIGHT) {
118 rb->lcd_remote_mono_bitmap(flake,particles[i][0],particles[i][1],
119 FLAKE_WIDTH,FLAKE_WIDTH);
120 }
121#endif
122 }
123 }
124}
125
126
127static void snow_init(void)
128{
129 int i;
130
131 for (i=0; i<NUM_PARTICLES; i++) {
132 particles[i][0]=-1;
133 particles[i][1]=-1;
134 }
135 mylcd_clear_display();
136#ifdef HAVE_REMOTE_LCD
137 rb->lcd_remote_clear_display();
138#endif
139}
140
141enum plugin_status plugin_start(const void* parameter)
142{
143 int button;
144 (void)(parameter);
145
146#ifdef HAVE_LCD_COLOR
147 rb->lcd_clear_display();
148 rb->lcd_set_foreground(LCD_WHITE);
149 rb->lcd_set_background(LCD_DEFAULT_BG);
150#endif
151 snow_init();
152 while (1) {
153 snow_move();
154 mylcd_update();
155#ifdef HAVE_REMOTE_LCD
156 rb->lcd_remote_update();
157#endif
158 rb->sleep(HZ/20);
159
160 /*We get button from PLA this way */
161 button = pluginlib_getaction(TIMEOUT_NOBLOCK, plugin_contexts,
162 ARRAYLEN(plugin_contexts));
163
164 if ((button == SNOW_QUIT) || (button == SNOW_QUIT2))
165 {
166 return PLUGIN_OK;
167 }
168 else
169 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
170 {
171 return PLUGIN_USB_CONNECTED;
172 }
173 }
174}
175