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:
parent
29d7080aa8
commit
3e669257aa
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
//Define DEVICE_TYPE Here for now.
|
//Define DEVICE_TYPE Here for now.
|
||||||
|
|
||||||
// #define DEVICE_TYPE "omega2"
|
#define DEVICE_TYPE "omega2"
|
||||||
|
|
||||||
class FastGpio : public Module {
|
class FastGpio : public Module {
|
||||||
public:
|
public:
|
||||||
|
@ -65,6 +65,7 @@ struct gpioSetup {
|
|||||||
|
|
||||||
// pulses options
|
// pulses options
|
||||||
char* pathPulsesFile;
|
char* pathPulsesFile;
|
||||||
|
int sampleFrequency;
|
||||||
int repeats;
|
int repeats;
|
||||||
|
|
||||||
// general options
|
// general options
|
||||||
|
2
makefile
2
makefile
@ -13,8 +13,6 @@ SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
|
|||||||
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
|
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
|
||||||
CXXFLAGS := -g # -Wall
|
CXXFLAGS := -g # -Wall
|
||||||
#LIB := -pthread -lmongoclient -L lib -lboost_thread-mt -lboost_filesystem-mt -lboost_system-mt
|
#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 {} \;)
|
INC := $(shell find $(INCDIR) -maxdepth 1 -type d -exec echo -I {} \;)
|
||||||
|
|
||||||
|
43
src/main.cpp
43
src/main.cpp
@ -1,4 +1,5 @@
|
|||||||
#include <main.h>
|
#include <main.h>
|
||||||
|
#include <climits>
|
||||||
|
|
||||||
void initGpioSetup (gpioSetup* obj)
|
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);
|
strcpy(setup->cmdString, FASTGPIO_CMD_STRING_PULSES);
|
||||||
// get the path to the pulses file and repeat number
|
// get the path to the pulses file and repeat number
|
||||||
setup->pathPulsesFile = argv[2];
|
setup->pathPulsesFile = argv[2];
|
||||||
setup->repeats = atoi(argv[3]);
|
setup->sampleFrequency = atoi(argv[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (strncmp(argv[0], "pwm", strlen("pwm") ) == 0 ) {
|
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);
|
gpioObj->SetDirection(pinNum,1);
|
||||||
|
|
||||||
FILE * pFile;
|
FILE * pFile = fopen (pathToFile,"r");
|
||||||
pFile = fopen (pathToFile,"r");
|
short *sdata;
|
||||||
// Max code size is 200
|
bool data;
|
||||||
int* upTimes = new int[200];
|
bool olddata = 0;
|
||||||
int* downTimes = new int[200];
|
|
||||||
int* pUpTimes = upTimes;
|
|
||||||
int* pDownTimes = downTimes;
|
|
||||||
|
|
||||||
// Load data from the file
|
// Load data from the file
|
||||||
if (pFile != NULL)
|
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++;
|
data = abs(*sdata)/SHRT_MAX;
|
||||||
pDownTimes++;
|
if (data != olddata) {
|
||||||
|
gpioObj->Set(pinNum, data);
|
||||||
|
}
|
||||||
|
olddata = data;
|
||||||
|
|
||||||
}
|
}
|
||||||
fclose (pFile);
|
fclose (pFile);
|
||||||
}
|
}
|
||||||
@ -312,24 +313,6 @@ int pulseGpio(FastGpio *gpioObj,int pinNum, char* pathToFile, int repeats)
|
|||||||
return 1;
|
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;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user