1
0
mirror of https://github.com/danog/fast-gpio.git synced 2024-11-26 20:04:37 +01:00

Pulses function now uses external code file

This commit is contained in:
Gilad Fride 2016-05-27 23:32:50 +03:00
parent ad89e07e4b
commit 7523a0f7a1
3 changed files with 98 additions and 65 deletions

View File

@ -61,6 +61,10 @@ struct gpioSetup {
int pwmFreq;
int pwmDuty;
// pulses options
char* pathPulsesFile;
int repeats;
// general options
int verbose;
int debug;
@ -80,7 +84,7 @@ int noteChildPid (int pinNum, int pid);
int killOldProcess (int pinNum);
int checkOldProcess (gpioSetup *setup);
int pulseGpio (FastGpio *gpioObj,int pinNum);
int pulseGpio(FastGpio *gpioObj,int pinNum, char* pathToFile, int repeats);

53
pulses_example.csv Normal file
View File

@ -0,0 +1,53 @@
2616,808
472,812
468,816
468,808
476,808
476,808
468,816
468,812
468,388
900,812
472,812
472,384
900,812
472,808
472,384
900,812
472,808
476,380
900,384
900,816
472,808
468,812
472,384
904,812
464,388
900,812
472,380
904,812
472,388
896,812
468,812
476,808
476,808
472,812
472,808
472,812
472,816
468,384
900,812
468,388
900,384
904,812
472,808
472,384
904,380
900,388
900,812
468,388
900,812
468,816
464,816
468,388
900,8004
1 2616 808
2 472 812
3 468 816
4 468 808
5 476 808
6 476 808
7 468 816
8 468 812
9 468 388
10 900 812
11 472 812
12 472 384
13 900 812
14 472 808
15 472 384
16 900 812
17 472 808
18 476 380
19 900 384
20 900 816
21 472 808
22 468 812
23 472 384
24 904 812
25 464 388
26 900 812
27 472 380
28 904 812
29 472 388
30 896 812
31 468 812
32 476 808
33 476 808
34 472 812
35 472 808
36 472 812
37 472 816
38 468 384
39 900 812
40 468 388
41 900 384
42 904 812
43 472 808
44 472 384
45 904 380
46 900 388
47 900 812
48 468 388
49 900 812
50 468 816
51 464 816
52 468 388
53 900 8004

View File

@ -1,6 +1,5 @@
#include <main.h>
void initGpioSetup (gpioSetup* obj)
{
obj->pinNumber = -1;
@ -25,7 +24,7 @@ void usage(const char* progName) {
printf("\t%s read <gpio>\n", progName);
printf("\t%s set <gpio> <value: 0 or 1>\n", progName);
printf("\t%s pwm <gpio> <freq in Hz> <duty cycle percentage>\n", progName);
printf("\t%s pulses <gpio>\n",progName);
printf("\t%s pulses <gpio> <path_pulses_file> <repeats>\n",progName);
printf("\n");
}
@ -90,6 +89,9 @@ int parseArguments(const char* progName, int argc, char* argv[], gpioSetup *setu
else if (strncmp(argv[0], "pulses", strlen("pulses") ) == 0 ) {
setup->cmd = GPIO_CMD_PULSES;
strcpy(setup->cmdString, FASTGPIO_CMD_STRING_PULSES);
// get the path to the pulses file and repeat number
setup->pathPulsesFile = argv[2];
setup->repeats = atoi(argv[3]);
}
else if (strncmp(argv[0], "pwm", strlen("pwm") ) == 0 ) {
@ -151,7 +153,7 @@ int gpioRun(gpioSetup* setup)
strcpy(valString, (setup->pinDir == 1 ? "output" : "input") );
break;
case GPIO_CMD_PULSES:
pulseGpio(&gpioObj,setup->pinNumber);
pulseGpio(&gpioObj,setup->pinNumber,setup->pathPulsesFile,setup->repeats);
break;
default:
@ -273,75 +275,49 @@ void pulse(FastGpio *gpioObj,int pinNum,int highMicros, int lowMicros)
usleep(lowMicros);
}
void SendCodeGate(FastGpio *gpioObj,int pinNum)
{
pulse(gpioObj,pinNum, 2616,808);
pulse(gpioObj,pinNum, 472,812);
pulse(gpioObj,pinNum, 468,816);
pulse(gpioObj,pinNum, 468,808);
pulse(gpioObj,pinNum, 476,808);
pulse(gpioObj,pinNum, 476,808);
pulse(gpioObj,pinNum, 468,816);
pulse(gpioObj,pinNum, 468,812);
pulse(gpioObj,pinNum, 468,388);
pulse(gpioObj,pinNum, 900,812);
pulse(gpioObj,pinNum, 472,812);
pulse(gpioObj,pinNum, 472,384);
pulse(gpioObj,pinNum, 900,812);
pulse(gpioObj,pinNum, 472,808);
pulse(gpioObj,pinNum, 472,384);
pulse(gpioObj,pinNum, 900,812);
pulse(gpioObj,pinNum, 472,808);
pulse(gpioObj,pinNum, 476,380);
pulse(gpioObj,pinNum, 900,384);
pulse(gpioObj,pinNum, 900,816);
pulse(gpioObj,pinNum, 472,808);
pulse(gpioObj,pinNum, 468,812);
pulse(gpioObj,pinNum, 472,384);
pulse(gpioObj,pinNum, 904,812);
pulse(gpioObj,pinNum, 464,388);
pulse(gpioObj,pinNum, 900,812);
pulse(gpioObj,pinNum, 472,380);
pulse(gpioObj,pinNum, 904,812);
pulse(gpioObj,pinNum, 472,388);
pulse(gpioObj,pinNum, 896,812);
pulse(gpioObj,pinNum, 468,812);
pulse(gpioObj,pinNum, 476,808);
pulse(gpioObj,pinNum, 476,808);
pulse(gpioObj,pinNum, 472,812);
pulse(gpioObj,pinNum, 472,808);
pulse(gpioObj,pinNum, 472,812);
pulse(gpioObj,pinNum, 472,816);
pulse(gpioObj,pinNum, 468,384);
pulse(gpioObj,pinNum, 900,812);
pulse(gpioObj,pinNum, 468,388);
pulse(gpioObj,pinNum, 900,384);
pulse(gpioObj,pinNum, 904,812);
pulse(gpioObj,pinNum, 472,808);
pulse(gpioObj,pinNum, 472,384);
pulse(gpioObj,pinNum, 904,380);
pulse(gpioObj,pinNum, 900,388);
pulse(gpioObj,pinNum, 900,812);
pulse(gpioObj,pinNum, 468,388);
pulse(gpioObj,pinNum, 900,812);
pulse(gpioObj,pinNum, 468,816);
pulse(gpioObj,pinNum, 464,816);
pulse(gpioObj,pinNum, 468,388);
pulse(gpioObj,pinNum, 900,8004);
}
int pulseGpio(FastGpio *gpioObj,int pinNum)
int pulseGpio(FastGpio *gpioObj,int pinNum, char* pathToFile, int repeats)
{
gpioObj->SetDirection(pinNum,1);
for (int i = 0; i < 20; i++)
FILE * pFile;
pFile = fopen (pathToFile,"r");
// Max pulses is 100
int* upTimes = new int[200];
int* downTimes = new int[200];
int* pUpTimes = upTimes;
int* pDownTimes = downTimes;
// Load data from the file
if (pFile != NULL)
{
SendCodeGate(gpioObj,pinNum);
while (fscanf(pFile, "%d,%d\n", pUpTimes,pDownTimes) != EOF)
{
pUpTimes++;
pDownTimes++;
}
fclose (pFile);
}
int i = 0;
while (repeats-- > 0)
{
// Play the code
pUpTimes = upTimes;
pDownTimes = downTimes;
i = 0;
while ((*pUpTimes != 0) && (i++ < 200))
{
// printf("Pulsing Up Time: %d, Down Time: %d\n",*pUpTimes,*pDownTimes);
pulse(gpioObj,pinNum,*pUpTimes,*pDownTimes);
pUpTimes++;
pDownTimes++;
}
}
delete[] upTimes;
delete[] downTimes;
}