Repository navigation
Expand file tree
/
Copy pathmain.c
More file actions
60 lines (54 loc) · 1.65 KB
/
Copy pathmain.c
File metadata and controls
60 lines (54 loc) · 1.65 KB
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
#include <stdio.h>
#include <getopt.h>
#include "opencodeV3/opencodeV3.h"
int main(int argc, char *argv[]) {
int c;
unsigned int addr = 0;
uint8_t outbuf[32];
while (1) {
int option_index = 0;
static struct option long_options[] = {
{"Address", required_argument, 0, 'a' },
{"Dimming", required_argument, 0, 'd' },
{"DimmingNight", no_argument, 0, 'n' },
{"Binding", required_argument, 0, 'b' },
{"LampOnOff", required_argument, 0, 'o' },
{0, 0, 0, 0 }
};
c = getopt_long(argc, argv, "a:d:nb:o:",
long_options, &option_index);
if (c == -1)
break;
switch (c) {
case 'a':
sscanf(optarg, "%i", &addr);
break;
case 'd':
int orange, white;
sscanf(optarg, "%i,%i", &orange, &white);
opencodeV3_Dimming(outbuf, 256, addr, 0, orange, white);
break;
case 'n':
opencodeV3_DimmingNight(outbuf, 256, addr, 0);
break;
case 'b':
int bind = 0;
sscanf(optarg, "%i", &bind);
opencodeV3_Binding(outbuf, 256, addr, 0, bind);
break;
case 'o':
int onoff = 0;
sscanf(optarg, "%i", &onoff);
opencodeV3_LampOnOff(outbuf, 256, addr, 0, onoff);
break;
case '?':
break;
default:
}
}
for (int i=5; i<31; i++) {
if(i%2)
printf("-u %02x%02x ", outbuf[i+1], outbuf[i]);
}
return 0;
}