Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GPN_BadgeLasertag
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sebastian
GPN_BadgeLasertag
Commits
f328038d
Commit
f328038d
authored
7 years ago
by
OleL
Browse files
Options
Downloads
Patches
Plain Diff
implemented ir recv
parent
b29346ee
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
GPN_BadgeLasertag.ino
+32
-13
32 additions, 13 deletions
GPN_BadgeLasertag.ino
with
32 additions
and
13 deletions
GPN_BadgeLasertag.ino
+
32
−
13
View file @
f328038d
...
@@ -81,19 +81,36 @@ void hostGame() {
...
@@ -81,19 +81,36 @@ void hostGame() {
#endif
#endif
}
}
bool
isNumber
(
char
number
){
return
number
>=
0x30
&&
number
<=
0x39
;
}
bool
isValidIp
(
String
ip
){
bool
isValidIp
(
String
ip
){
unsigned
short
pos0
=
ip
.
indexOf
(
'.'
);
unsigned
short
pos0
=
ip
.
indexOf
(
'.'
);
unsigned
short
pos1
=
ip
.
indexOf
(
'.'
,
pos0
);
unsigned
short
pos1
=
ip
.
indexOf
(
'.'
,
pos0
+
1
);
unsigned
short
pos2
=
ip
.
indexOf
(
'.'
,
pos1
);
unsigned
short
pos2
=
ip
.
indexOf
(
'.'
,
pos1
+
1
);
unsigned
short
pos3
=
ip
.
indexOf
(
'.'
,
pos2
);
String
tuple0
=
ip
.
substring
(
0
,
pos0
);
String
tuple1
=
ip
.
substring
(
pos0
+
1
,
pos1
);
String
tuple2
=
ip
.
substring
(
pos1
+
1
,
pos2
);
String
tuple3
=
ip
.
substring
(
pos2
+
1
,
ip
.
length
()
-
1
);
String
part0
=
ip
.
substring
(
0
,
pos0
);
bool
isValid
=
true
;
String
part1
=
ip
.
substring
(
pos0
,
pos1
);
String
part2
=
ip
.
substring
(
pos1
,
pos2
);
String
part3
=
ip
.
substring
(
pos2
,
ip
.
length
());
Serial
.
printf
(
"Zerhackstuekelte IP: %s:%s:%s:%s"
,
part0
.
c_str
(),
part1
.
c_str
(),
part2
.
c_str
(),
part3
.
c_str
());
for
(
int
i
=
0
;
i
<
tuple0
.
length
();
i
++
){
Serial
.
printf
(
"tuple0: %d -> %c
\n
"
,
i
,
tuple0
[
i
]);
isValid
&=
isNumber
(
tuple0
[
i
]);
}
for
(
int
i
=
0
;
i
<
tuple1
.
length
();
i
++
){
Serial
.
printf
(
"tuple1: %d -> %c
\n
"
,
i
,
tuple1
[
i
]);
}
for
(
int
i
=
0
;
i
<
tuple2
.
length
();
i
++
){
Serial
.
printf
(
"tuple2: %d -> %c
\n
"
,
i
,
tuple2
[
i
]);
}
for
(
int
i
=
0
;
i
<
tuple3
.
length
();
i
++
){
Serial
.
printf
(
"tuple3: %d -> %c
\n
"
,
i
,
tuple3
[
i
]);
}
}
}
...
@@ -106,9 +123,9 @@ String recv_ir() {
...
@@ -106,9 +123,9 @@ String recv_ir() {
bool
dataVerified
=
false
;
bool
dataVerified
=
false
;
uint8_t
checksumRec
=
0
;
uint8_t
checksumRec
=
0
;
bool
done
=
false
;
//
bool done = false;
while
(
!
dataCompleted
&&
!
done
)
{
while
(
!
dataCompleted
)
{
int
on_time
=
0
;
int
on_time
=
0
;
decode_results
results
;
// Somewhere to store the results
decode_results
results
;
// Somewhere to store the results
if
(
irrecv
.
decode
(
&
results
))
{
if
(
irrecv
.
decode
(
&
results
))
{
...
@@ -116,18 +133,19 @@ String recv_ir() {
...
@@ -116,18 +133,19 @@ String recv_ir() {
Serial
.
println
(
"IR code too long. Edit IRremoteInt.h and increase RAWBUF"
);
Serial
.
println
(
"IR code too long. Edit IRremoteInt.h and increase RAWBUF"
);
return
"a12
\n
7.0
\n
.0.
\n
1b"
;
return
"a12
\n
7.0
\n
.0.
\n
1b"
;
}
}
char
*
buf
=
reinterpret_cast
<
char
*>
(
&
results
.
value
);
char
*
buf
=
reinterpret_cast
<
char
*>
(
&
results
.
value
);
if
(
millis
()
-
on_time
>
500
)
{
if
(
millis
()
-
on_time
>
500
)
{
pixels
.
setPixelColor
(
1
,
pixels
.
Color
(
0
,
0
,
0
));
pixels
.
setPixelColor
(
1
,
pixels
.
Color
(
0
,
0
,
0
));
pixels
.
show
();
pixels
.
show
();
}
}
uint8_t
checksum
=
'X'
;
if
(
stringCompleted
)
{
if
(
stringCompleted
)
{
uint8_t
checksum
=
buf
[
1
];
uint8_t
checksum
=
buf
[
1
];
dataCompleted
=
true
;
dataCompleted
=
true
;
Serial
.
printf
(
"checksum?? %c;%c
\n
"
,
checksumRec
<<
8
|
222
,
checksum
);
if
(
checksum
==
checksumRec
)
{
if
(
checksum
==
checksumRec
)
{
dataVerified
=
true
;
dataVerified
=
true
;
pixels
.
setPixelColor
(
1
,
pixels
.
Color
(
0
,
100
,
0
));
pixels
.
setPixelColor
(
1
,
pixels
.
Color
(
0
,
100
,
0
));
...
@@ -142,7 +160,8 @@ String recv_ir() {
...
@@ -142,7 +160,8 @@ String recv_ir() {
Serial
.
printf
(
"->:
\n\t
0: %c
\n\t
1: %c
\n\t
2: %c
\n\t
3: %c
\n
"
,
buf
[
0
],
buf
[
1
],
buf
[
2
],
buf
[
3
]);
Serial
.
printf
(
"->:
\n\t
0: %c
\n\t
1: %c
\n\t
2: %c
\n\t
3: %c
\n
"
,
buf
[
0
],
buf
[
1
],
buf
[
2
],
buf
[
3
]);
if
(
buf
[
0
]
==
'\n'
||
buf
[
1
]
==
'\n'
||
buf
[
2
]
==
'\n'
||
buf
[
3
]
==
'\n'
)
{
if
(
buf
[
0
]
==
'\n'
||
buf
[
1
]
==
'\n'
||
buf
[
2
]
==
'\n'
||
buf
[
3
]
==
'\n'
)
{
stringCompleted
=
true
;
stringCompleted
=
true
;
done
=
isValidIp
(
received
.
substring
(
1
,
received
.
length
()
-
2
));
Serial
.
printf
(
"string complete %s
\n
"
,
received
.
c_str
());
//done = true; //isValidIp(received.substring(1, received.length() - 2));
}
}
}
}
irrecv
.
resume
();
// Prepare for the next value
irrecv
.
resume
();
// Prepare for the next value
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment