16 Commits
project ... V2

Author SHA1 Message Date
Siegfried Kienzle
2f29dc80ce rename loop.c to diff.c 2017-04-03 15:31:18 +02:00
Siegfried Kienzle
60a9c97758 finished 2017-04-03 15:28:34 +02:00
root
5974a3a1d5 start to write loop.c 2017-04-01 16:20:07 +02:00
Siegfried Kienzle
c265e4c1fb Merge pull request #2 from SWW13/v1-led5
V1: led5
2017-04-01 15:38:10 +02:00
Siegfried Kienzle
8b0c083d5d Merge pull request #1 from SWW13/v1-led-sh
V1: led.sh
2017-04-01 14:53:24 +02:00
Kienzle
8281c38db8 rename some functions and add some implementations 2017-03-29 11:10:15 +02:00
Siegfried Kienzle
fc25e2f506 remove logical bug 2017-03-28 06:34:23 +02:00
Siegfried Kienzle
71c04f77f3 add reserve, voltage and inOrOut 2017-03-27 20:58:02 +02:00
Siegfried Kienzle
bcad9de814 add function voltage and inOrOut 2017-03-24 17:51:26 +01:00
Siegfried Kienzle
a2baf654b6 remove bug with strings 2017-03-24 17:03:46 +01:00
Siegfried Kienzle
b15d09216e remove some bugs 2017-03-24 16:34:06 +01:00
Siegfried Kienzle
f230a08868 add some defines and the function inOut 2017-03-24 15:54:38 +01:00
Siegfried Kienzle
414c1a95ac add forgotten close in function reserve 2017-03-24 15:09:38 +01:00
Siegfried Kienzle
966611815f add function reserve 2017-03-24 15:06:31 +01:00
Siegfried Kienzle
398a259050 start to write switch.c 2017-03-24 14:02:04 +01:00
Siegfried Kienzle
92b78db992 modified README.md 2017-03-24 13:50:46 +01:00
3 changed files with 152 additions and 1 deletions

View File

@@ -1,2 +1,2 @@
# resy-ss17-template # resy-ss17-grp1
Template for grp repositories Template for grp repositories

120
V1/switch.c Normal file
View File

@@ -0,0 +1,120 @@
/*
* switch.c
* How to register an button and count this
* author: Simon Wörner, Manuel Vögele,
* Siegfried Kienzle
* 24-March-2017
*
* */
#define BUTTON "17"
#define IN "in\n"
#define OUT "out\n"
#define HIGH "1\n"
#define LOW "0\n"
#define MAXBYTES 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
int writeIntoFile(char* value, char* path)
{
int fd;
char buffer[3];
strcpy(buffer, value);
if((fd=open(path, O_RDWR | O_CREAT | O_TRUNC)) == -1) {
perror(NULL);
return EXIT_FAILURE;
}
if((write(fd, &buffer, sizeof(buffer))) == -1) {
perror("Cannot write into file");
return EXIT_FAILURE;
}
printf("Success");
close(fd);
return EXIT_SUCCESS;
}
int reserve(char* gpioPort)
{
char str[3];
strcpy(str, gpioPort);
strcat(str, "\n");
return writeIntoFile(str,"/sys/class/gpio/export");
}
int setDirection(char* gpioPort, char* inOut)
{
char *direc = "/direction";
char *gpioPath = "/sys/class/gpio/gpio";
char path[32];
strcpy(path, gpioPath);
strcat(path, gpioPort);
strcat(path, direc);
return writeIntoFile(inOut, path);
}
int setOutput(char* gpioPort, char* volt)
{
char *val = "/value";
char *gpioPath = "/sys/class/gpio/gpio";
char path[28];
strcpy(path, gpioPath);
strcat(path, gpioPort);
strcat(path, val);
return writeIntoFile(volt, path);
}
int mainLoop(char* gpioPort)
{
int fid, portValue, count, countButton;
char *val = "/value";
char *gpioPath = "/sys/class/gpio/gpio";
char path[28];
strcpy(path, gpioPath);
strcat(path, gpioPort);
strcat(path, val);
while(true)
{
if( (fid=open(path, O_RDONLY)) == -1)
perror("Fehler ");
if(readInput(fid) == 1)
{
countButton++;
printf("%d", countButton);
}
close(fid);
}
}
char[] readInput(int fid)
{
char buffer[MAXBYTES];
read(fid, &buffer, MAXBYTES);
return buffer;
}
int unexport(char* gpioport)
{
char str[3];
strcpy(str, gpioPort);
strcat(str, "\n");
return writeIntoFile(str,"/sys/class/gpio/unexport");
}
int main()
{
reserve(BUTTON);
setDirection(BUTTON, IN);
mainLoop(BUTTON);
unexport(BUTTON);
return 0;
}

31
V2/diff.c Normal file
View File

@@ -0,0 +1,31 @@
#include<stdio.h>
#include<time.h>
#include<pthread.h>
int main(int argc, char *argv[])
{
struct timespec time1, start, ende;
time1.tv_sec = 5;
time1.tv_nsec = 0;
clock_gettime(CLOCK_MONOTONIC, &start);
clock_nanosleep(CLOCK_MONOTONIC, 0, &time1, NULL);
clock_gettime(CLOCK_MONOTONIC, &ende);
int nsec_difference = (int) ((ende.tv_nsec - start.tv_nsec)/1000);
//microseconds
int sec_difference = (int) (ende.tv_sec - start.tv_sec)*1000*1000;
int real_time_slept = sec_difference + nsec_difference;
int difference_real_set = real_time_slept - time1.tv_sec * 1000 * 1000;
printf("Real time slept: %d\n", real_time_slept);
printf("Difference Real time slept and actually sleep time: %d usec\n", difference_real_set);
return 0;
}