Add files via upload

This commit is contained in:
Chris Boudacoff 2018-03-14 11:47:47 +02:00 committed by GitHub
parent e6db699dec
commit 8e96f3f837
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,9 @@
all:
$(CC) teres1-debug.c -o teres1-debug
clean:
$(RM) teres1-debug
install: all
install -m0755 teres1-debug /usr/local/sbin

View File

@ -0,0 +1,76 @@
/* teres1-debug.c - debug mode switch
Copyright (C) 2018 Chris Boudacoff
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <linux/input.h>
#define DEBUGEN 361
void export_gpio(int gpio)
{
int fd;
char buf[255];
fd = open("/sys/class/gpio/export", O_WRONLY);
sprintf(buf, "%d", gpio);
write(fd, buf, strlen(buf));
close(fd);
sprintf(buf, "/sys/class/gpio/gpio%d/direction", gpio);
fd = open(buf, O_WRONLY);
write(fd, "out", 3);
close(fd);
}
void set_gpio(int gpio, int value)
{
char buf[255];
sprintf(buf, "/sys/class/gpio/gpio%d/value", gpio);
int fd = open(buf, O_WRONLY);
sprintf(buf, "%d", value);
write(fd, buf, 1);
close(fd);
}
void usage(void)
{
extern char *program_invocation_short_name;
printf("USAGE:\n");
printf(" %s on|off\n", program_invocation_short_name);
printf("\n");
}
int main (int argc, char **argv)
{
int mode;
if (!argv[1])
{
usage();
exit(0);
}
if (strcmp(argv[1],"off")==0) mode = 1;
else if (strcmp(argv[1],"on")==0) mode = 0;
else { usage(); exit(0); }
//printf("Debug %d\r\n",mode);
export_gpio(DEBUGEN);
set_gpio(DEBUGEN, mode);
return 0;
}