Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
duck
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
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
jp7g21
duck
Commits
a0e84966
Commit
a0e84966
authored
3 years ago
by
jp7g21
Browse files
Options
Downloads
Plain Diff
Merge remote-tracking branch 'refs/remotes/origin/master'
parents
fffdfbd2
5e64af02
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
emb/command.c
+26
-3
26 additions, 3 deletions
emb/command.c
emb/command.h
+2
-0
2 additions, 0 deletions
emb/command.h
emb/state-controller.cpp
+21
-3
21 additions, 3 deletions
emb/state-controller.cpp
with
49 additions
and
6 deletions
emb/command.c
+
26
−
3
View file @
a0e84966
...
...
@@ -8,6 +8,9 @@
struct
command
command_buf
[
NUM_COMMANDS
];
uint16_t
comm_start
=
0
,
comm_end
=
0
;
char
comm_str
[
33
];
uint8_t
comm_str_ind
=
0
;
/* Add y to x, wrapping around limit */
static
inline
void
add_wrap
(
uint16_t
*
x
,
uint16_t
y
,
uint16_t
limit
)
{
...
...
@@ -17,7 +20,7 @@ static inline void add_wrap(uint16_t *x, uint16_t y, uint16_t limit)
}
enum
state
{
STATE_COMM
,
STATE_COMM_SPACE
,
STATE_ARG
STATE_COMM
,
STATE_COMM_SPACE
,
STATE_ARG
,
STATE_STRING
};
/* Return 1 if new command ready */
...
...
@@ -36,8 +39,16 @@ uint8_t uart_add_ch(char c)
break
;
case
STATE_COMM_SPACE
:
if
(
c
==
' '
)
{
state
=
STATE_ARG
;
}
else
{
if
(
curr
->
comm_ch
==
't'
)
{
comm_str_ind
=
0
;
state
=
STATE_STRING
;
}
else
{
state
=
STATE_ARG
;
}
}
else
{
state
=
STATE_COMM
;
add_wrap
(
&
comm_end
,
1
,
NUM_COMMANDS
);
}
...
...
@@ -58,6 +69,18 @@ uint8_t uart_add_ch(char c)
if
(
argbuf_ind
<
19
)
argbuf
[
argbuf_ind
++
]
=
c
;
}
break
;
case
STATE_STRING
:
if
(
comm_str_ind
==
sizeof
(
comm_str
)
-
1
||
c
==
'\n'
)
{
comm_str
[
comm_str_ind
]
=
'\0'
;
state
=
STATE_COMM
;
add_wrap
(
&
comm_end
,
1
,
NUM_COMMANDS
);
}
else
{
comm_str
[
comm_str_ind
++
]
=
c
;
}
break
;
}
return
state
==
STATE_COMM
;
}
...
...
This diff is collapsed.
Click to expand it.
emb/command.h
+
2
−
0
View file @
a0e84966
...
...
@@ -14,6 +14,8 @@ extern "C" {
int16_t
arg
[
NUM_ARGS
];
};
extern
char
comm_str
[
33
];
uint8_t
uart_add_ch
(
char
c
);
struct
command
*
get_command
(
void
);
...
...
This diff is collapsed.
Click to expand it.
emb/state-controller.cpp
+
21
−
3
View file @
a0e84966
#include
"servos.hpp"
#include
"command.h"
#include
"time.hpp"
#include
"display.hpp"
#include
<avr/interrupt.h>
#include
<string.h>
enum
State
{
...
...
@@ -17,13 +19,15 @@ static uint32_t velocitiesEndMillis[NUM_SERVOS];
static
int16_t
startAngles
[
NUM_SERVOS
];
static
uint32_t
startMillis
[
NUM_SERVOS
];
static
char
displayString
[
33
];
void
parseCommand
(
command
*
comm
)
{
uint32_t
currentMillis
=
getCurrentMillis
();
switch
(
comm
->
comm_ch
)
{
case
's'
:
case
's'
:
// set
if
(
0
<=
comm
->
arg
[
0
]
-
1
&&
comm
->
arg
[
0
]
-
1
<
NUM_SERVOS
)
{
setServoAngle
(
comm
->
arg
[
0
]
-
1
,
comm
->
arg
[
1
]
*
60
);
...
...
@@ -31,7 +35,7 @@ void parseCommand(command *comm)
servoVelocities
[
comm
->
arg
[
0
]
-
1
]
=
0
;
}
break
;
case
'v'
:
case
'v'
:
// velocity
if
(
0
<=
comm
->
arg
[
0
]
-
1
&&
comm
->
arg
[
0
]
-
1
<
NUM_SERVOS
)
{
servoVelocities
[
comm
->
arg
[
0
]
-
1
]
=
comm
->
arg
[
1
];
...
...
@@ -40,10 +44,23 @@ void parseCommand(command *comm)
startMillis
[
comm
->
arg
[
0
]
-
1
]
=
currentMillis
;
}
break
;
case
'd'
:
case
'd'
:
// delay
delayEnd
=
getCurrentMillis
()
+
comm
->
arg
[
0
];
state
=
STATE_DELAY
;
break
;
case
't'
:
// text
clearDisplay
();
setDisplayCursor
(
0
,
0
);
uint8_t
i
=
0
;
while
(
char
c
=
displayString
[
i
++
])
{
writeDisplay
(
c
);
if
(
i
==
16
)
setDisplayCursor
(
0
,
1
);
}
break
;
}
}
...
...
@@ -58,6 +75,7 @@ void updateState()
cli
();
command
*
tmp
=
get_command
();
command
comm
=
*
tmp
;
memcpy
(
displayString
,
comm_str
,
sizeof
(
displayString
));
sei
();
if
(
tmp
!=
nullptr
)
...
...
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