raspi_lcd 0.0.2 → 0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/raspi_lcd/raspi_lcd.c +47 -2
- metadata +1 -1
data/ext/raspi_lcd/raspi_lcd.c
CHANGED
@@ -147,6 +147,51 @@ static VALUE r_SleepMs(VALUE self, VALUE ms)
|
|
147
147
|
return Qnil;
|
148
148
|
}
|
149
149
|
|
150
|
+
static VALUE r_Button(VALUE self, VALUE button)
|
151
|
+
{
|
152
|
+
int res;
|
153
|
+
int sym = SYM2ID(button);
|
154
|
+
if(sym==rb_intern("up"))
|
155
|
+
res = BUTTON_UP;
|
156
|
+
else if(sym==rb_intern("left"))
|
157
|
+
res = BUTTON_LEFT;
|
158
|
+
else if(sym==rb_intern("center"))
|
159
|
+
res = BUTTON_CENTER;
|
160
|
+
else if(sym==rb_intern("right"))
|
161
|
+
res = BUTTON_RIGHT;
|
162
|
+
else if(sym==rb_intern("down"))
|
163
|
+
res = BUTTON_DOWN;
|
164
|
+
else res = -1;
|
165
|
+
if(res==-1) {
|
166
|
+
rb_raise(rb_eStandardError,"only up, left, center, right and down are valid parameters");
|
167
|
+
return Qnil;
|
168
|
+
}
|
169
|
+
else
|
170
|
+
return res ? Qtrue : Qfalse;
|
171
|
+
}
|
172
|
+
|
173
|
+
static VALUE r_ButtonPressed(VALUE self, VALUE button)
|
174
|
+
{
|
175
|
+
int res;
|
176
|
+
int sym = SYM2ID(button);
|
177
|
+
if(sym==rb_intern("up"))
|
178
|
+
res = BUTTON_PRESSED_UP;
|
179
|
+
else if(sym==rb_intern("left"))
|
180
|
+
res = BUTTON_PRESSED_LEFT;
|
181
|
+
else if(sym==rb_intern("center"))
|
182
|
+
res = BUTTON_PRESSED_CENTER;
|
183
|
+
else if(sym==rb_intern("right"))
|
184
|
+
res = BUTTON_PRESSED_RIGHT;
|
185
|
+
else if(sym==rb_intern("down"))
|
186
|
+
res = BUTTON_PRESSED_DOWN;
|
187
|
+
else res = -1;
|
188
|
+
if(res==-1) {
|
189
|
+
rb_raise(rb_eStandardError,"only up, left, center, right and down are valid parameters");
|
190
|
+
return Qnil;
|
191
|
+
}
|
192
|
+
else
|
193
|
+
return res ? Qtrue : Qfalse;
|
194
|
+
}
|
150
195
|
|
151
196
|
|
152
197
|
|
@@ -178,7 +223,7 @@ void Init_raspi_lcd() {
|
|
178
223
|
rb_define_module_function(m,"spi_putc",r_SpiPutc, 1);
|
179
224
|
rb_define_module_function(m,"set_backlight",r_SetBacklight, 1);
|
180
225
|
rb_define_module_function(m,"sleep_ms",r_SleepMs, 1);
|
181
|
-
|
182
|
-
|
226
|
+
rb_define_module_function(m,"button",r_Button, 1);
|
227
|
+
rb_define_module_function(m,"button_pressed",r_ButtonPressed, 1);
|
183
228
|
}
|
184
229
|
|