Skip to content
Snippets Groups Projects
Commit e8e21420 authored by jp7g21's avatar jp7g21
Browse files

Wrote duck cli

parent bb0a39ec
No related branches found
No related tags found
No related merge requests found
duck: duck.c ../libduck/libduck.so
cc duck.c -o duck -L ../libduck -l duck
.PHONY: clean install
clean:
rm -f duck
install: duck
install -T -D -m 555 duck /usr/lib/duck/duck && \
install -T udev-rule /etc/udev/rules.d/80-duck.rules && \
udevadm control -R
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <err.h>
#include <stdlib.h>
#include "../libduck/libduck.h"
#define SHAKE_ANGLE 45
#define SHAKE_T 300
void shake(int motor, int number)
{
for (int j=0; j < number; j++) {
duck_set_position(motor, -SHAKE_ANGLE);
duck_delay(SHAKE_T);
duck_set_position(motor, SHAKE_ANGLE);
duck_delay(2 * SHAKE_T);
duck_set_position(motor, 0);
duck_delay(SHAKE_T);
}
}
int main(int argc, char **argv)
{
int option;
const char *fname = DEFAULT_DUCK_FNAME;
char buf[100];
while ((option=getopt(argc, argv, "t:")) != -1) {
switch (option) {
case 't':
strncpy(buf, optarg, 100);
fname = buf;
break;
default:
printf("Usage: duck [-t TTYNAME] command\n");
exit(EXIT_FAILURE);
break;
}
}
open_duck(fname);
configure_duck();
for (int i=optind; argv[i]; i++) {
if (strcmp(argv[i], "set") == 0) {
if (argv[i+1] && argv[i+2]) {
int motor = atoi(argv[i+1]);
int angle = atoi(argv[i+2]);
duck_set_position(motor, angle);
i += 2;
}
} else if (strcmp(argv[i], "vel") == 0) {
if (argv[i+1] && argv[i+2]) {
int motor = atoi(argv[i+1]);
int deg_per_sec = atoi(argv[i+2]);
duck_set_velocity(motor, deg_per_sec);
i += 2;
}
} else if (strcmp(argv[i], "headshake") == 0) {
if (argv[i+1]) {
int numshakes = atoi(argv[i+1]);
shake(MOTOR_1, numshakes);
i++;
}
} else if (strcmp(argv[i], "nod") == 0) {
if (argv[i+1]) {
int numnods = atoi(argv[i+1]);
shake(MOTOR_2, numnods);
i++;
}
}
}
return 0;
}
ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", MODE="666"
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment