forked from ErikAndren/delcom-904000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelcom_on_off.c
76 lines (66 loc) · 1.73 KB
/
delcom_on_off.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
// Flashes red color
// Copyright Erik Zachrisson: [email protected]
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <stdbool.h>
#include "delcom_freebsd.h"
static HIDPacketStruct my_packet;
int write_hid(hid_device *hnd, uint8_t data) {
// Write 8 byte command
my_packet.tx.major_cmd = WRITE_PORT_CMD;
// Write to port 1 command
my_packet.tx.minor_cmd = 2;
// Data to write to port1
my_packet.tx.data_lsb = data;
// Send it
return hid_send_feature_report(hnd, my_packet.data, 8);
}
void usage() {
printf("Usage:\n");
printf("Turn off light\n");
printf("./delcom_on_off off\n");
printf("Turn on red light\n");
printf("./delcom_on_off red\n");
printf("Turn on green light\n");
printf("./delcom_on_off green\n");
printf("Turn on yellow light\n");
printf("./delcom_on_off yellow\n");
return;
}
int main(int argc, char* argv[]) {
hid_device *handle;
uint32_t colour;
if (argc != 2){
usage();
return errno;
}
if (strcmp(argv[1],"red") == 0){
printf("red\n");
colour = RED_COLOR;
} else if (strcmp(argv[1],"green") == 0){
printf("green\n");
colour = GREEN_COLOR;
} else if (strcmp(argv[1],"yellow") == 0){
printf("yello\n");
colour = YELLOW_COLOR;
} else if (strcmp(argv[1],"off") == 0){
printf("off\n");
colour = NO_COLOR;
} else {
printf("unknown colour: %s\n", argv[1]);
usage();
return errno;
}
// Open the device using the VID, PID,
handle = hid_open(DELCOM_HID_VID, DELCOM_HID_PID, NULL);
if (!handle) {
printf("Error: Unable to open device. (%d:%s)\n", errno, strerror(errno));
return errno;
}
write_hid(handle, colour);
return 0;
}