-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmds-mood.c
141 lines (107 loc) · 2.59 KB
/
cmds-mood.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include <stdio.h>
#include <string.h>
#include <libmicro/can.h>
#include <libmicro/debug.h>
#include <libmicro/lap.h>
#include "cmds.h"
#include "cmds-mood.h"
void cmd_mood_set(int argc, char *argv[]);
void cmd_mood_cycle(int argc, char *argv[]);
cmd_t mood_cmds[] = {
{ &cmd_mood_set, "set", "mood set <addr> <module> <r> <g> <b> <aux>", "Set RGB (0=on - 255=off), module is always 0. turn off cycle first!" },
{ &cmd_mood_cycle, "cycle", "mood cycle <addr> <on|off>", "control automatic color cycle" }
};
void cmd_mood_cycle(int argc, char *argv[])
{
pdo_message *msg;
int i;
if (argc != 3) goto argerror;
msg = (pdo_message *)can_buffer_get();
msg->addr_src = 0x00;
msg->addr_dst = 0x00;
msg->port_src = PORT_MOOD;
msg->port_dst = PORT_MOOD;
msg->dlc = 2;
msg->cmd = FKT_MOOD_ONOFF;
msg->data[0] = 0;
// dst
if (sscanf(argv[1], "%x", &i) != 1)
goto argerror;
msg->addr_dst = i;
// on/off
if (strcmp(argv[2], "on") == 0)
msg->data[0] = 1;
else if (strcmp(argv[2], "off") == 0)
msg->data[0] = 0;
else
goto argerror;
can_transmit((can_message*)msg);
return;
argerror:
debug(0, "%s", mood_cmds[0].sig);
}
void cmd_mood_set(int argc, char *argv[])
{
pdo_message *msg;
int i;
if (argc != 7) goto argerror;
msg = (pdo_message *)can_buffer_get();
msg->addr_src = 0x00;
msg->addr_dst = 0x00;
msg->port_src = PORT_MOOD;
msg->port_dst = PORT_MOOD;
msg->dlc = 6;
msg->cmd = FKT_MOOD_SET;
msg->data[0] = 0;
msg->data[1] = 0;
msg->data[2] = 0;
msg->data[3] = 0;
msg->data[4] = 0;
// dst
if (sscanf(argv[1], "%x", &i) != 1)
goto argerror;
msg->addr_dst = i;
// module
if (sscanf(argv[2], "%i", &i) == 1)
msg->data[0] = i;
// red
if (sscanf(argv[3], "%i", &i) == 1)
msg->data[1] = i;
// green
if (sscanf(argv[4], "%i", &i) == 1)
msg->data[2] = i;
// blue
if (sscanf(argv[5], "%i", &i) == 1)
msg->data[3] = i;
// aux
if (sscanf(argv[6], "%i", &i) == 1)
msg->data[4] = i;
can_transmit((can_message*)msg);
return;
argerror:
debug(0, "%s", mood_cmds[0].sig);
}
void cmd_mood(int argc, char **argv)
{
char *arg = argv[1];
cmd_t *cmd;
cmd = mood_cmds;
while(argc > 1 && cmd->fkt) {
if (strcmp(arg, cmd->cmd) == 0) {
(*(cmd->fkt))(argc-1, &(argv[1]));
goto done;
}
cmd++;
}
/* show help */
printf( "\nUsage: lapcontrol [OPTIONS] mood <SUBCOMMAND>\n\n" );
printf( "Available Subcommands:\n\n" );
cmd = mood_cmds;
while(cmd->fkt) {
printf( " %-30s %s\n", cmd->sig, cmd->desc );
cmd++;
}
printf( "\n" );
done:
return;
}