Cleanup calling - mostly working; misc cleanup scripts; add vibrate program
This commit is contained in:
parent
fd286101d8
commit
22d974f22f
17 changed files with 366 additions and 176 deletions
|
@ -380,7 +380,7 @@ int main(int ac, char* av[])
|
|||
audio_setup.dai2_en = 1;
|
||||
break;
|
||||
default: /* '?' */
|
||||
fprintf(stderr, "Usage: %s [-s] [-m] [-h] [-e] [-2]\n", av[0]);
|
||||
fprintf(stderr, "Usage: %s [-s] [-m] [-h] [-e] [-2] [-z]\n", av[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
#include <gammu.h>
|
||||
#include <gammu-message.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
GSM_SMSMessage m;
|
||||
GSM_Error err;
|
||||
int i;
|
||||
char timestamp[50];
|
||||
char * hexstring;
|
||||
|
||||
hexstring = malloc(strlen(argv[1]) / 2);
|
||||
for (i = 0; i < strlen(argv[1]) / 2; i++) {
|
||||
sscanf(argv[1] + i*2, "%2hhx", &hexstring[i]);
|
||||
}
|
||||
err = GSM_DecodePDUFrame(NULL, &m, hexstring, strlen(argv[1]) / 2, NULL, 1);
|
||||
if (err != ERR_NONE) {
|
||||
fprintf(stderr, "Failure to parse string: %s\n", GSM_ErrorString(err));
|
||||
}
|
||||
GSM_DateTimeToTimestamp(&m.DateTime, timestamp);
|
||||
|
||||
printf("Date: %s\n", timestamp);
|
||||
printf("Number: %s\n", DecodeUnicodeConsole(m.Number));
|
||||
printf("Message:\n%s\n", DecodeUnicodeConsole(m.Text));
|
||||
}
|
|
@ -3,8 +3,18 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
char * pbpScreen = "/sys/class/backlight/edp-backlight/brightness";
|
||||
char * ppScreen = "/sys/devices/platform/backlight/backlight/backlight/brightness";
|
||||
|
||||
void usage() {
|
||||
fprintf(stderr, "Usage: setpinebacklight [0-10]\n");
|
||||
fprintf(stderr, "Usage: sxmo_setpinebacklight [number]\n");
|
||||
}
|
||||
|
||||
void writeFile(char *filepath, int brightness) {
|
||||
FILE *f;
|
||||
f = fopen(filepath, "w+");
|
||||
fprintf(f, "%d\n", brightness);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
@ -18,20 +28,18 @@ int main(int argc, char *argv[]) {
|
|||
argc--;
|
||||
brightness = atoi(argv[argc--]);
|
||||
|
||||
if (brightness < 0 || brightness > 10) {
|
||||
usage();
|
||||
if (setuid(0)) {
|
||||
fprintf(stderr, "setuid(0) failed\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
command = malloc(100);
|
||||
sprintf(
|
||||
command,
|
||||
"sh -c 'echo %d > /sys/devices/platform/backlight/backlight/backlight/brightness'",
|
||||
brightness
|
||||
);
|
||||
if (setuid(0)) {
|
||||
fprintf(stderr, "setuid(0) failed\n");
|
||||
if (access(pbpScreen, F_OK) != -1) {
|
||||
writeFile(pbpScreen, brightness);
|
||||
fprintf(stderr, "Set PBP brightness to %d\n", brightness);
|
||||
} else if (access(ppScreen, F_OK) != -1) {
|
||||
writeFile(ppScreen, brightness);
|
||||
fprintf(stderr, "Set PP brightness to %d\n", brightness);
|
||||
} else {
|
||||
return system(command);
|
||||
fprintf(stderr, "Neither PP or PBP Screen found!\n");
|
||||
}
|
||||
}
|
||||
|
|
110
programs/sxmo_vibratepine.c
Normal file
110
programs/sxmo_vibratepine.c
Normal file
|
@ -0,0 +1,110 @@
|
|||
/* Based on: https://xnux.eu/devices/feature/vibrator.html#toc-example-program-to-control-the-vibration-motor */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <poll.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/input.h>
|
||||
|
||||
|
||||
void syscall_error(int is_err, const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (!is_err)
|
||||
return;
|
||||
|
||||
printf("ERROR: ");
|
||||
va_start(ap, fmt);
|
||||
vprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
printf(": %s\n", strerror(errno));
|
||||
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int open_event_dev(const char* name_needle, int flags)
|
||||
{
|
||||
char path[256];
|
||||
char name[256];
|
||||
int fd, ret;
|
||||
|
||||
// find the right device and open it
|
||||
for (int i = 0; i < 10; i++) {
|
||||
snprintf(path, sizeof path, "/dev/input/event%d", i);
|
||||
fd = open(path, flags);
|
||||
if (fd < 0)
|
||||
continue;
|
||||
|
||||
ret = ioctl(fd, EVIOCGNAME(256), name);
|
||||
if (ret < 0)
|
||||
continue;
|
||||
|
||||
if (strstr(name, name_needle))
|
||||
return fd;
|
||||
|
||||
close(fd);
|
||||
}
|
||||
|
||||
errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void usage() {
|
||||
fprintf(stderr, "Usage: sxmo_vibratepine duration_ms\n");
|
||||
fprintf(stderr, " sxmo_vibratepine duration_ms strength_number\n");
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int fd, ret;
|
||||
struct pollfd pfds[1];
|
||||
int effects;
|
||||
|
||||
int durationMs, strength;
|
||||
|
||||
if (argc < 1) {
|
||||
usage();
|
||||
return 1;
|
||||
}
|
||||
argc--;
|
||||
|
||||
if (argc > 1) {
|
||||
strength = atoi(argv[argc--]);
|
||||
} else {
|
||||
strength = 4000;
|
||||
}
|
||||
|
||||
durationMs = atoi(argv[argc--]);
|
||||
|
||||
fd = open_event_dev("vibrator", O_RDWR | O_CLOEXEC);
|
||||
syscall_error(fd < 0, "Can't open vibrator event device");
|
||||
ret = ioctl(fd, EVIOCGEFFECTS, &effects);
|
||||
syscall_error(ret < 0, "EVIOCGEFFECTS failed");
|
||||
|
||||
struct ff_effect e = {
|
||||
.type = FF_RUMBLE,
|
||||
.id = -1,
|
||||
.u.rumble = { .strong_magnitude = strength },
|
||||
};
|
||||
|
||||
ret = ioctl(fd, EVIOCSFF, &e);
|
||||
syscall_error(ret < 0, "EVIOCSFF failed");
|
||||
|
||||
struct input_event play = { .type = EV_FF, .code = e.id, .value = 3 };
|
||||
ret = write(fd, &play, sizeof play);
|
||||
syscall_error(ret < 0, "write failed");
|
||||
|
||||
usleep(durationMs * 1000);
|
||||
|
||||
ret = ioctl(fd, EVIOCRMFF, e.id);
|
||||
syscall_error(ret < 0, "EVIOCRMFF failed");
|
||||
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue