Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
co2ampel
ampel-firmware
Commits
39fe4d11
Commit
39fe4d11
authored
Apr 17, 2021
by
Eric Duminil
Browse files
Don't read serial before enter is pressed
parent
9db226d7
Changes
3
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/ampel-firmware.ino
View file @
39fe4d11
...
...
@@ -147,9 +147,8 @@ void loop() {
// Short press for night mode, Long press for calibration.
checkFlashButton
();
if
(
Serial
.
available
()
>
0
)
{
commandString
=
Serial
.
readStringUntil
(
'\n'
);
sensor_commands
::
run
(
commandString
.
c_str
());
while
(
Serial
.
available
()
>
0
)
{
sensor_commands
::
processIncomingByte
(
Serial
.
read
());
}
if
(
sensor
::
processData
())
{
...
...
@@ -171,7 +170,7 @@ void loop() {
max_loop_duration
=
duration
;
Serial
.
print
(
F
(
"Debug - Max loop duration : "
));
Serial
.
print
(
max_loop_duration
);
Serial
.
println
(
" ms."
);
Serial
.
println
(
F
(
" ms."
)
)
;
}
}
...
...
ampel-firmware/sensor_commands.cpp
View file @
39fe4d11
...
...
@@ -77,6 +77,26 @@ namespace sensor_commands {
return
code
;
}
// http://www.gammon.com.au/serial
void
processIncomingByte
(
const
byte
input_byte
)
{
static
char
input_line
[
MAX_COMMAND_SIZE
];
static
unsigned
int
input_pos
=
0
;
switch
(
input_byte
)
{
case
'\n'
:
// end of text
input_line
[
input_pos
]
=
0
;
run
(
input_line
);
input_pos
=
0
;
break
;
case
'\r'
:
// discard carriage return
break
;
default:
// keep adding if not full ... allow for terminating null byte
if
(
input_pos
<
(
MAX_COMMAND_SIZE
-
1
))
input_line
[
input_pos
++
]
=
input_byte
;
break
;
}
}
void
listAvailableCallbacks
()
{
for
(
uint8_t
i
=
0
;
i
<
callbacks_count
;
i
++
)
{
Serial
.
print
(
" "
);
...
...
@@ -106,7 +126,7 @@ namespace sensor_commands {
Serial
.
println
(
")"
);
callbacks
[
i
].
intFunction
(
argument
);
}
else
{
Serial
.
println
();
Serial
.
println
(
"()"
);
callbacks
[
i
].
voidFunction
();
}
return
;
...
...
ampel-firmware/sensor_commands.h
View file @
39fe4d11
...
...
@@ -7,6 +7,7 @@
*/
namespace
sensor_commands
{
void
processIncomingByte
(
const
byte
in_byte
);
void
run
(
const
char
*
command
);
void
defineIntCallback
(
const
char
*
command
,
void
(
*
function
)(
int32_t
),
const
char
*
doc
);
void
defineCallback
(
const
char
*
command
,
void
(
*
function
)(
void
),
const
char
*
doc
);
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment