~mil/sxmo-utils

ref: 4bf92406d0b7e8e7a4093d1e81d4e4ce4078faee sxmo-utils/programs/sxmo_setpineled.c -rw-r--r-- 836 bytes
4bf92406Stacy Harper Try to make bluetooth menu connection more reliable 9 months ago
                                                                                
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

void usage() {
	fprintf(stderr, "Usage: setpineled [red|green|blue|white] [0-255]\n");
}

int main(int argc, char *argv[]) {
	int brightness;
	char * color;
	char * command;
	char * type;

	if (argc < 2) {
		usage();
		return 1;
	}
	argc--;
	brightness = atoi(argv[argc--]);

	if (brightness < 0 || brightness > 255) {
		usage();
		return 1;
	}

	color = argv[argc--];
	if (
		strcmp(color, "red") &&
		strcmp(color, "blue") &&
		strcmp(color, "green") &&
		strcmp(color, "white")
	) {
		usage();
		return 1;
	}

	if (!strcmp(color, "white")) {
		type = "flash";
	} else {
		type = "indicator";
	}

	command = malloc(80);
	sprintf(
		command,
		"sh -c 'echo %d > /sys/class/leds/%s:%s/brightness'",
		brightness, color, type
	);
	return system(command);
}