-
Notifications
You must be signed in to change notification settings - Fork 6
/
ex-remote.c
77 lines (66 loc) · 1.56 KB
/
ex-remote.c
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
/* @DIR x3600-radio@/remote.c */
/* Copyright (c) 2020 J. M. Spivey */
#include "microbian.h"
#include "hardware.h"
#include "lib.h"
#define GROUP 17
static const image letter_A =
IMAGE(0,1,1,0,0,
1,0,0,1,0,
1,1,1,1,0,
1,0,0,1,0,
1,0,0,1,0);
static const image letter_B =
IMAGE(1,1,1,0,0,
1,0,0,1,0,
1,1,1,0,0,
1,0,0,1,0,
1,1,1,0,0);
void receiver_task(int dummy)
{
byte buf[RADIO_PACKET];
int n;
printf("Hello\n");
display_show(letter_A);
timer_delay(1000);
display_show(letter_B);
timer_delay(1000);
display_show(blank);
while (1) {
n = radio_receive(buf);
if (n == 1 && buf[0] == '1') {
printf("Button A\n");
display_show(letter_A);
} else if (n == 1 && buf[0] == '2') {
printf("Button B\n");
display_show(letter_B);
} else {
printf("Unknown packet, length %d: %d\n", n, buf[0]);
}
}
}
void sender_task(int dummy)
{
gpio_connect(BUTTON_A);
gpio_connect(BUTTON_B);
while (1) {
if (gpio_in(BUTTON_A) == 0) {
printf("Press A\n");
radio_send("1", 1);
} else if (gpio_in(BUTTON_B) == 0) {
printf("Press B\n");
radio_send("2", 1);
}
timer_delay(100);
}
}
void init(void)
{
serial_init();
radio_init();
radio_group(GROUP);
timer_init();
display_init();
start("Receiver", receiver_task, 0, STACK);
start("Sender", sender_task, 0, STACK);
}