Modernize

This commit is contained in:
Jens True 2021-11-30 10:01:28 +00:00
parent e16c7a34fd
commit 65f0450f8d
4 changed files with 96 additions and 59 deletions

@ -7,13 +7,30 @@ steps:
- apt-get -y update - apt-get -y update
- apt-get -y install libusb-1.0 - apt-get -y install libusb-1.0
- make - make
- name: release - name: docs
image: plugins/gitea-release image: corentinaltepe/doxygen
settings: commands:
api_key: - doxygen
from_secret: DRONE_ACCESS_TOKEN - name: release-dev
base_url: https://code.jcktrue.dk image: alpine
files: volumes:
- ledcontroller - name: output
when: path: /output
event: tag commands:
- mkdir -p /output/dev/
- cp -r docs/html/* /output/dev/docs/
- name: release-tag
image: alpine
volumes:
- name: output
path: /output
commands:
- cp -r /output/dev/ /output/${DRONE_SEMVER}/
when:
event:
- tag
volumes:
- name: output
host:
path: /home/jct/apps/http/share.jcktrue.dk/${DRONE_REPO_NAME}/

1
.gitignore vendored

@ -1,3 +1,4 @@
*~ *~
*.swp *.swp
ledcontroller ledcontroller
docs/

7
Doxyfile Normal file

@ -0,0 +1,7 @@
PROJECT_NAME = "ledcontroller-3bit"
OUTPUT_DIRECTORY = "docs/"
INPUT = "README.md" "main.c"
RECURSIVE = YES
WARNINGS = YES
GENERATE_LATEX = NO
USE_MDFILE_AS_MAINPAGE = README.md

110
main.c

@ -1,4 +1,4 @@
/* /**
ledcontroller-3bit ledcontroller-3bit
This file is a fork of the LedController code. You will find This file is a fork of the LedController code. You will find
@ -39,7 +39,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdio.h> #include <stdio.h>
#include <libusb.h> #include <libusb.h>
#include <errno.h> #include <errno.h>
@ -48,22 +47,8 @@
#define VID 0x1294 #define VID 0x1294
#define PID 0x1320 #define PID 0x1320
static struct libusb_device_handle *devh = NULL; static struct libusb_device_handle *devh = NULL;
/**
int main(int argc, char **argv)
{
int ret;
unsigned char code = 0;
if (argc != 2) {
printf
("Syntax: %s blue | red | green | aqua | purple | yellow | white | off\n",
argv[0]);
return -1;
}
/*
The device has a RGB LED, which has two states for each "sub-LED", The device has a RGB LED, which has two states for each "sub-LED",
on and off. on and off.
The "sub-LEDs" are red, green and blue. The "sub-LEDs" are red, green and blue.
@ -82,39 +67,66 @@ int main(int argc, char **argv)
1 1 0 yellow 0x6 (more of a mustard - green color) 1 1 0 yellow 0x6 (more of a mustard - green color)
1 1 1 white 0x7 (a very blue-ish white) 1 1 1 white 0x7 (a very blue-ish white)
*/ */
if (strcmp(argv[1], "blue") == 0) { int main(int argc, char **argv) {
code = 1; int ret;
} else if (strcmp(argv[1], "red") == 0) { unsigned char code = 0;
code = 2; if (argc != 2)
} else if (strcmp(argv[1], "green") == 0) { {
code = 3; printf("Syntax: %s blue | red | green | aqua | purple | yellow | white | off\n", argv[0]);
} else if (strcmp(argv[1], "aqua") == 0) { return -1;
code = 4; }
} else if (strcmp(argv[1], "purple") == 0) {
code = 5; if (strcmp(argv[1], "blue") == 0)
} else if (strcmp(argv[1], "yellow") == 0) { {
code = 6; code = 1;
} else if (strcmp(argv[1], "white") == 0) { }
code = 7; else if (strcmp(argv[1], "red") == 0)
} else { {
puts("Invalid color"); code = 2;
return -1; }
else if (strcmp(argv[1], "green") == 0)
{
code = 3;
}
else if (strcmp(argv[1], "aqua") == 0)
{
code = 4;
}
else if (strcmp(argv[1], "purple") == 0)
{
code = 5;
}
else if (strcmp(argv[1], "yellow") == 0)
{
code = 6;
}
else if (strcmp(argv[1], "white") == 0)
{
code = 7;
}
else
{
puts("Invalid color");
return -1;
} }
libusb_init(NULL); libusb_init(NULL);
devh = libusb_open_device_with_vid_pid(NULL, VID, PID); devh = libusb_open_device_with_vid_pid(NULL, VID, PID);
if (devh == NULL) { if (devh == NULL)
puts("Device not found"); {
return -1; puts("Device not found");
return -1;
} }
if (libusb_kernel_driver_active(devh, 0)) { if (libusb_kernel_driver_active(devh, 0))
puts("Detach driver from kernel"); {
ret = libusb_detach_kernel_driver(devh, 0); puts("Detach driver from kernel");
if (ret < 0) { ret = libusb_detach_kernel_driver(devh, 0);
puts("Could not detach driver"); if (ret < 0)
return -1; {
} puts("Could not detach driver");
return -1;
}
} }
char data[5]; char data[5];
@ -127,11 +139,11 @@ int main(int argc, char **argv)
int dummy; int dummy;
libusb_claim_interface(devh, 0); libusb_claim_interface(devh, 0);
ret = libusb_interrupt_transfer(devh, 0x2, data, 5, &dummy, 0); ret = libusb_interrupt_transfer(devh, 0x2, data, 5, &dummy, 0);
if (ret < 0) { if (ret < 0)
perror("libusb error"); {
return -1; perror("libusb error");
return -1;
} }
return 0; return 0;
} }