This repository has been archived by the owner on Nov 10, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnakeno.c
195 lines (183 loc) · 3.6 KB
/
snakeno.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
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
/* CCC MSN 0.1b @ CCC 2011 Germany
* Developers:
* - Simpson
* - 0xCC
*
* Base Codes:
* - sign.c (For Mesh Communication)
* - blink.c (For Led Notification)
*
* */
#include <sysinit.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "basic/basic.h"
#include "basic/config.h"
#include "funk/nrf24l01p.h"
#include "funk/rftransfer.h"
#include "lcd/render.h"
#include "lcd/print.h"
#include "usetable.h"
/*Global Communication Config*/
uint8_t mac[5] = {1,2,3,5,5};
struct NRF_CFG config =
{
.channel= 81,
.txmac= "\x1\x2\x3\x5\x5",
.nrmacs=1,
.mac0= "\x1\x2\x3\x5\x5",
.maclen ="\x20",
};
/*Possible Messages*/
char msgs[5][20]={" Hi There!"," At Kourou"," At Baikonur","Party Hard!","Like a Boss!"};
void initDisplay(void);
void initMesh(void);
void waitMsg(void);
void blink(void);
/*Main Loop*/
void ram(void)
{
initDisplay();
uint8_t key;
do
{
key = getInput();
if(key == BTN_DOWN)
waitMsg();
else if (key == BTN_UP)
initMesh();
} while(key != BTN_ENTER);
}
/*Message Receiver*/
void waitMsg()
{
uint8_t key;
unsigned char buf[32];
char sender_nick[10];
int n,i;
int index=0;
int rcv =0;
int try=0;
do
{
key = getInput();
if(1)
{
nrf_config_set(&config);
n = nrf_rcv_pkt_time(100,32,buf);
getInputWaitTimeout(100);
if(n == 32)
{
index=buf[0];
for(i=0;i<10;i++)
sender_nick[i]=buf[i+1];
lcdClear();
lcdPrintln("");
lcdPrintln("CCC MSN 0.1b");
lcdPrintln("---------------");
lcdPrintln(msgs[index]);
lcdPrintln("");
lcdPrintln("Received");
lcdPrintln("");
lcdPrintln("_______________");
lcdPrintln(sender_nick);
lcdRefresh();
blink();
rcv=1;
try=0;
} else if(rcv)
{
lcdClear();
lcdPrintln("");
lcdPrintln("CCC MSN 0.1b");
lcdPrintln("-----------------");
lcdPrintln("Waiting...");
lcdPrint("Try ");
lcdPrintln(IntToStr(try,5,0));
lcdPrintln("");
lcdPrintln(msgs[index]);
lcdPrintln("_______________");
lcdPrintln(sender_nick);
lcdRefresh();
}
try++;
}
if(!rcv)
{
lcdClear();
lcdPrintln("");
lcdPrintln("CCC MSN 0.1b");
lcdPrintln("-----------------");
lcdPrintln("Waiting...");
lcdPrintln("");
lcdPrint("Try ");
lcdPrintln(IntToStr(try,5,0));
lcdPrintln("");
lcdPrintln("_______________");
lcdPrintln("W8 Users Auto");
lcdRefresh();
}
}while(key != BTN_ENTER);
initDisplay();
}
/*Starter*/
void initDisplay(void)
{
lcdClear();
lcdPrintln("");
lcdPrintln("CCC MSN 0.1b");
lcdNl();
lcdPrintln("Commands:");
lcdPrintln("UP/Down");
lcdPrintln("Press to Exit!");
lcdPrintln("");
lcdPrintln("_______________");
lcdPrintln(GLOBAL(nickname));
lcdRefresh();
}
/*Start to Talk*/
void initMesh(void)
{
char buf[32];
uint8_t key;
int index=0;
int trys=0;
int i;
do
{
key = getInput();
if(key != BTN_NONE)
{ // TODO: send often
memset(buf,0,32);
buf[0]=key;
for(i=0;i<11;i++)
buf[i+1]=GLOBAL(nickname)[i];
nrf_config_set(&config);
nrf_snd_pkt_crc(32,(uint8_t *)buf);
trys=trys+1;
}
lcdClear();
lcdPrintln("");
lcdPrintln("CCC MSN 0.1b");
lcdPrintln("-----------------");
lcdPrintln(msgs[index]);
lcdPrintln("");
lcdPrint("Try ");
lcdPrintln(IntToStr(trys,5,0));
lcdPrintln("");
lcdPrintln("_______________");
lcdPrintln("UP To Send Msg");
lcdRefresh();
} while(key != BTN_ENTER);
initDisplay();
}
/*Led Blink*/
void blink(void)
{
for (int x=0;x<20;x++)
{
gpioSetValue (RB_LED1, x%2);
delayms(50);
}
}