a commit...

This commit is contained in:
[ Kristjan Komloši HomePC ]
2017-02-01 19:57:42 +01:00
parent e0a6c665e9
commit cf86a1d310
+26 -32
View File
@@ -1,14 +1,15 @@
// Tinio - the Tiny I/O tool // Tinio - the Tiny I/O tool
#include <CyUSBCommon.h> #include <CyUSBCommon.h>
#include <ctype.h>
#include <libusb.h> #include <libusb.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <ctype.h>
// those vars are to be used with locateDevice function // those vars are to be used with locateDevice function
const uint8_t maxDevs = 16; // 16 connected devices should be enough... const uint8_t maxDevs = 16; // 16 connected devices should be enough...
const CY_VID_PID deviceVidPid{UINT16(0x04b4), UINT16(0x0004)}; // the id for the chip const CY_VID_PID deviceVidPid{UINT16(0x04b4),
UINT16(0x0004)}; // the id for the chip
uint8_t deviceNumList[maxDevs]; uint8_t deviceNumList[maxDevs];
uint8_t deviceCount; uint8_t deviceCount;
CY_DEVICE_INFO deviceInfoList[maxDevs]; CY_DEVICE_INFO deviceInfoList[maxDevs];
@@ -132,31 +133,29 @@ int locateDevice() // locate the device and verify it's the right one
} }
} }
int selectDevice() { int attachDevices() {
for (int i = 0; i < deviceCount; i++) {
if (whichDev > deviceCount) { int rs = evalErrors(
puts("The requested device doesn't exist."); CyOpen(deviceNumList[i], interfaceNum, &deviceHandleList[i]));
return 5; if (rs != 0) {
}
for(int i = 0; i < deviceCount; i++){
int rs = evalErrors(CyOpen(deviceNumList[i], interfaceNum, &deviceHandleList[i]));
if (rs != 0)
{
return rs; return rs;
} }
} }
return 0; return 0;
} }
int setGPIO(int targetPin, uint8_t value) {
int retval = evalErrors(CySetGpioValue(deviceHandleList[whichDev-1], targetPin, value));
return retval;
}
int isstrdigit(const char *str) { int isstrdigit(const char *str) {
for(; *str != '\0'; str++){ for (; *str != '\0'; str++) {
if ( !(isdigit(*str)) ) { if (!(isdigit(*str))) {
return 0; return 0;
} }
} }
return 1; return 1;
} }
void test() { void test() {
@@ -165,13 +164,12 @@ void test() {
CySetGpioValue(deviceHandleList[0], 8, 0); CySetGpioValue(deviceHandleList[0], 8, 0);
} }
int parseCmdLine(int acount, char * const* arglist) { int parseCmdLine(int acount, char *const *arglist) {
int opt; int opt;
while( (opt = getopt(acount, arglist, "d:s:r:v:i:") != -1 ) ) { while ((opt = getopt(acount, arglist, "d:s:r:v:i:") != -1)) {
switch(opt) { switch (opt) {
case 'd': case 'd':
if ( !(isstrdigit(optarg)) ) if (!(isstrdigit(optarg))) {
{
puts("Unknown argument for switch -d"); puts("Unknown argument for switch -d");
puts("Arguments MUST be integer numbers!"); puts("Arguments MUST be integer numbers!");
return -1; return -1;
@@ -179,24 +177,20 @@ int parseCmdLine(int acount, char * const* arglist) {
whichDev = atoi(optarg); whichDev = atoi(optarg);
break; break;
case 's': case 's':
if ( !(isstrdigit(optarg)) ) if (!(isstrdigit(optarg))) {
{
puts("Unknown argument for switch -s"); puts("Unknown argument for switch -s");
puts("Arguments MUST be integer numbers!"); puts("Arguments MUST be integer numbers!");
return -1; return -1;
} }
//TODO complete when set and read GPIO are done // TODO complete when set and read GPIO are done
break; break;
} }
}
}
} }
int main(int argc, char const *argv[]) { int main(int argc, char const *argv[]) {
initLib(); initLib();
locateDevice(); locateDevice();
selectDevice(); attachDevices();
// test(); // test();
} }