1
0
mirror of https://github.com/danog/fast-gpio.git synced 2024-11-30 04:19:09 +01:00

Start of pcm shiz

This commit is contained in:
Daniil Gentili 2017-08-11 00:10:03 +02:00
parent 29d7080aa8
commit 3e669257aa
4 changed files with 15 additions and 33 deletions

View File

@ -16,7 +16,7 @@
//Define DEVICE_TYPE Here for now.
// #define DEVICE_TYPE "omega2"
#define DEVICE_TYPE "omega2"
class FastGpio : public Module {
public:

View File

@ -65,6 +65,7 @@ struct gpioSetup {
// pulses options
char* pathPulsesFile;
int sampleFrequency;
int repeats;
// general options

View File

@ -13,8 +13,6 @@ SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
CXXFLAGS := -g # -Wall
#LIB := -pthread -lmongoclient -L lib -lboost_thread-mt -lboost_filesystem-mt -lboost_system-mt
DEVICE_TYPE := "UNKNOWN"
override CXXFLAGS += -D 'DEVICE_TYPE="$(DEVICE_TYPE)"'
INC := $(shell find $(INCDIR) -maxdepth 1 -type d -exec echo -I {} \;)

View File

@ -1,4 +1,5 @@
#include <main.h>
#include <climits>
void initGpioSetup (gpioSetup* obj)
{
@ -91,7 +92,7 @@ int parseArguments(const char* progName, int argc, char* argv[], gpioSetup *setu
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]);
setup->sampleFrequency = atoi(argv[3]);
}
else if (strncmp(argv[0], "pwm", strlen("pwm") ) == 0 ) {
@ -286,23 +287,23 @@ int pulseGpio(FastGpio *gpioObj,int pinNum, char* pathToFile, int repeats)
{
gpioObj->SetDirection(pinNum,1);
FILE * pFile;
pFile = fopen (pathToFile,"r");
// Max code size is 200
int* upTimes = new int[200];
int* downTimes = new int[200];
int* pUpTimes = upTimes;
int* pDownTimes = downTimes;
FILE * pFile = fopen (pathToFile,"r");
short *sdata;
bool data;
bool olddata = 0;
// Load data from the file
if (pFile != NULL)
{
int i = 0;
while ((fscanf(pFile, "%d,%d\n", pUpTimes,pDownTimes) != EOF) && (i++ < 200))
while (fread(sdata, sizeof(short), 1, pFile) == 1*sizeof(short))
{
pUpTimes++;
pDownTimes++;
data = abs(*sdata)/SHRT_MAX;
if (data != olddata) {
gpioObj->Set(pinNum, data);
}
olddata = data;
}
fclose (pFile);
}
@ -312,24 +313,6 @@ int pulseGpio(FastGpio *gpioObj,int pinNum, char* pathToFile, int repeats)
return 1;
}
// Play the code
while (repeats-- > 0)
{
pUpTimes = upTimes;
pDownTimes = downTimes;
while (*pUpTimes != 0)
{
// printf("Pulsing Up Time: %d, Down Time: %d\n",*pUpTimes,*pDownTimes);
pulse(gpioObj,pinNum,*pUpTimes,*pDownTimes);
pUpTimes++;
pDownTimes++;
}
}
delete[] upTimes;
delete[] downTimes;
}