Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
UCC
BlinkenLights
Commits
618ae246
Commit
618ae246
authored
Mar 07, 2014
by
Mitchell Pomery
Browse files
webGetArray
Returns ALL the lights!
parent
17252c38
Changes
1
Hide whitespace changes
Inline
Side-by-side
BlinkenLights.ino
View file @
618ae246
...
...
@@ -64,15 +64,13 @@ NEO_GRB + NEO_KHZ800);
// Set up our webserver
WebServer
webserver
(
PREFIX
,
80
);
// =========================== char-hex conversions ===========================
char
*
charToHex
(
char
c
)
{
char
base_digits
[
16
]
=
{
{
'0'
,
'1'
,
'2'
,
'3'
,
'4'
,
'5'
,
'6'
,
'7'
,
'8'
,
'9'
,
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
};
'8'
,
'9'
,
'A'
,
'B'
,
'C'
,
'D'
,
'E'
,
'F'
};
int
converted_number
[
64
];
int
base
=
16
;
...
...
@@ -86,25 +84,39 @@ char* charToHex(char c) {
number_to_convert
=
number_to_convert
/
base
;
index
++
;
}
Serial
.
println
(
index
);
//
Serial.println(index);
/* now print the result in reverse order */
index
--
;
/* back up to last entry in the array */
index
--
;
/* back up to last entry in the array */
char
ret
[
3
];
//ret[0] = '';
//ret[1] = '';
int
i
=
0
;
if
(
index
<
0
)
{
Serial
.
print
(
base_digits
[
0
]);
ret
[
i
]
=
base_digits
[
0
];
i
++
;
}
if
(
index
<
1
)
{
Serial
.
print
(
base_digits
[
0
]);
ret
[
i
]
=
base_digits
[
0
];
i
++
;
}
for
(;
index
>=
0
;
index
--
)
/
*
go backward through array
*/
for
(;
index
>=
0
&&
i
<
2
;
index
--
)
/
/
go backward through array
{
Serial
.
print
(
base_digits
[
converted_number
[
index
]]);
ret
[
i
]
=
base_digits
[
converted_number
[
index
]];
i
++
;
}
return
(
char
)
0
;
ret
[
2
]
=
'\0'
;
Serial
.
print
(
ret
);
// NEVER REMOVE THIS LINE. OR DIE
// WITHOUT IT WE GET GARBLED OUTPUT HERE
// YOU HAVE BEEN WARNED
return
ret
;
}
// ============================ LIGHT MANIPULATION ============================
/**
...
...
@@ -178,7 +190,13 @@ void setLED(int xpos, int ypos, int red, int green, int blue) {
* @return colour of LED at pos
*/
struct
led
getLED
(
int
pos
)
{
return
ledArray
[
pos
];
uint32_t
light
=
strip
.
getPixelColor
(
pos
);
//Serial.print(light);
led
ret
;
ret
.
red
=
light
>>
16
;
ret
.
green
=
light
>>
8
;
ret
.
blue
=
light
;
return
ret
;
}
/**
...
...
@@ -189,7 +207,7 @@ struct led getLED(int pos) {
*/
struct
led
getLED
(
int
xpos
,
int
ypos
)
{
int
pos
=
coordToPos
(
xpos
,
ypos
);
return
ledArray
[
pos
]
;
return
getLED
(
pos
)
;
}
// ================================ WEB PAGES ================================
...
...
@@ -234,6 +252,39 @@ char *url_tail, bool tail_complete) {
}
}
void
webGetArray
(
WebServer
&
server
,
WebServer
::
ConnectionType
type
,
char
*
url_tail
,
bool
tail_complete
)
{
URLPARAM_RESULT
rc
;
char
name
[
NAMELEN
];
char
value
[
VALUELEN
];
server
.
httpSuccess
();
// Kill the connection before doing anything if all they want is head
if
(
type
==
WebServer
::
HEAD
)
{
return
;
}
else
if
(
type
==
WebServer
::
GET
)
{
for
(
int
i
=
0
;
i
<
WIDTH
;
i
++
)
{
for
(
int
j
=
0
;
j
<
HEIGHT
;
j
++
)
{
led
light
=
getLED
(
i
,
j
);
//Serial.print(i);
//Serial.print(", ");
//Serial.println(j);
server
.
print
(
charToHex
(
light
.
red
));
//Serial.print(light.red);
server
.
print
(
charToHex
(
light
.
green
));
//Serial.print(light.green);
server
.
print
(
charToHex
(
light
.
blue
));
//Serial.println(light.blue);
}
}
//server.print(array);
}
else
{
server
.
print
(
"Unknown Request"
);
}
}
/**
* Set a specific LED to a specific colour
* @param server
...
...
@@ -463,6 +514,7 @@ void setup() {
webserver
.
addCommand
(
"custom"
,
&
webSetSequence
);
//webserver.addCommand("individual", &webSetLED);
webserver
.
addCommand
(
"brightness"
,
&
webSetBrightness
);
webserver
.
addCommand
(
"get"
,
&
webGetArray
);
// Start Webserver
webserver
.
begin
();
// Turn our lights on
...
...
@@ -472,14 +524,14 @@ void setup() {
ledArray
[
i
].
blue
=
(
char
)
128
;
}
for
(
int
i
=
-
128
;
i
<
128
;
i
++
)
{
Serial
.
print
(
i
);
Serial
.
print
(
" "
);
//Serial.print((char) i);
Serial
.
print
(
" "
);
charToHex
((
char
)
i
);
Serial
.
println
(
""
);
}
/*
for (int i = -128; i < 128; i++) {
Serial.print(i);
Serial.print(" ");
//Serial.print((char) i);
Serial.print(" ");
charToHex((char) i);
Serial.println("");
}*/
// Start Lights
strip
.
begin
();
...
...
@@ -530,3 +582,4 @@ void loop()
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment