worked on the old monolythic design
This commit is contained in:
@@ -1,2 +1,4 @@
|
|||||||
tinio:
|
dynamic:
|
||||||
g++ -lcyusbserial -lusb-1.0 main.cpp
|
g++ -lcyusbserial -lusb-1.0 main.cpp
|
||||||
|
monolyth:
|
||||||
|
g++ -lcyusbserial -lusb-1.0 old.cpp
|
||||||
|
|||||||
@@ -1,28 +1,26 @@
|
|||||||
// Tinio - the Tiny I/O tool
|
// Tinio - the Tiny I/O tool
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <CyUSBCommon.h>
|
#include <CyUSBCommon.h>
|
||||||
#include <libusb.h>
|
#include <libusb.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
// those vars are to be used with locateDevice function
|
// those vars are to be used with locateDevice function
|
||||||
const UINT8 devInfoListLen = 200;
|
const uint8_t devInfoListLen = 200;
|
||||||
const CY_VID_PID deviceVidPid{UINT16(0x04b4), UINT16(0x0002)};
|
const CY_VID_PID deviceVidPid{UINT16(0x04b4), UINT16(0x0002)};
|
||||||
UINT8 deviceNumList[devInfoListLen];
|
uint8_t deviceNumList[devInfoListLen];
|
||||||
UINT8 deviceCount;
|
uint8_t deviceCount;
|
||||||
CY_DEVICE_INFO deviceInfoList[devInfoListLen];
|
CY_DEVICE_INFO deviceInfoList[devInfoListLen];
|
||||||
|
|
||||||
// vars for deviceOpen function
|
// vars for deviceOpen function
|
||||||
CY_HANDLE deviceHandle;
|
CY_HANDLE deviceHandle;
|
||||||
UINT8 intNum;
|
uint8_t defaultInterfaceNum = 0;
|
||||||
UINT8 devNum;
|
|
||||||
|
|
||||||
|
|
||||||
//----ACTUAL CODE BELOW
|
//----ACTUAL CODE BELOW
|
||||||
int verifyArgNum(const int num) // verifies the number of arguments. minimum is 2
|
int verifyArgNum(
|
||||||
{
|
const int num) // verifies the number of arguments. minimum is 2
|
||||||
if (num < 2)
|
|
||||||
{
|
{
|
||||||
|
if (num < 2) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
@@ -35,7 +33,8 @@ int initLib() //initializes the cypress library
|
|||||||
{
|
{
|
||||||
puts("The library init failed.");
|
puts("The library init failed.");
|
||||||
puts("Restarting...");
|
puts("Restarting...");
|
||||||
if (CyLibraryExit() != CY_SUCCESS) //try to close the possibly running library
|
if (CyLibraryExit() !=
|
||||||
|
CY_SUCCESS) // try to close the possibly running library
|
||||||
{
|
{
|
||||||
return 1; // if even that fails, abort.
|
return 1; // if even that fails, abort.
|
||||||
}
|
}
|
||||||
@@ -44,11 +43,10 @@ int initLib() //initializes the cypress library
|
|||||||
// try to reinitialize
|
// try to reinitialize
|
||||||
}
|
}
|
||||||
puts("OK");
|
puts("OK");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usage()
|
void usage() {
|
||||||
{
|
|
||||||
puts("Tinio test build 1");
|
puts("Tinio test build 1");
|
||||||
puts("Usage:");
|
puts("Usage:");
|
||||||
//----TODO----//
|
//----TODO----//
|
||||||
@@ -56,8 +54,7 @@ void usage()
|
|||||||
// usage summary.
|
// usage summary.
|
||||||
}
|
}
|
||||||
|
|
||||||
int evalErrors(const CY_RETURN_STATUS error)
|
int evalErrors(const CY_RETURN_STATUS error) {
|
||||||
{
|
|
||||||
int errCast = int(error);
|
int errCast = int(error);
|
||||||
switch (errCast) { // evaluates the return status of a function
|
switch (errCast) { // evaluates the return status of a function
|
||||||
case 0: // everything goes OK
|
case 0: // everything goes OK
|
||||||
@@ -69,7 +66,8 @@ int evalErrors(const CY_RETURN_STATUS error)
|
|||||||
return 1;
|
return 1;
|
||||||
break;
|
break;
|
||||||
case 2: // driver init failed. library's fault probably
|
case 2: // driver init failed. library's fault probably
|
||||||
puts("Library failure. Try to rerun the tinio utility or reinstall the library");
|
puts("Library failure. Try to rerun the tinio utility or reinstall the "
|
||||||
|
"library");
|
||||||
return 2;
|
return 2;
|
||||||
break;
|
break;
|
||||||
case 3: // CY_DEVICE_INFO_FETCH_FAILED error
|
case 3: // CY_DEVICE_INFO_FETCH_FAILED error
|
||||||
@@ -88,7 +86,8 @@ int evalErrors(const CY_RETURN_STATUS error)
|
|||||||
puts("Please send me a bug report to: kristjan.komlosi@gmail.com");
|
puts("Please send me a bug report to: kristjan.komlosi@gmail.com");
|
||||||
return 5;
|
return 5;
|
||||||
break;
|
break;
|
||||||
case 6: //library request failed. The cypress or libusb lib may be uninitialized
|
case 6: // library request failed. The cypress or libusb lib may be
|
||||||
|
// uninitialized
|
||||||
puts("Request failed. Is library installed?");
|
puts("Request failed. Is library installed?");
|
||||||
return 6;
|
return 6;
|
||||||
break;
|
break;
|
||||||
@@ -100,62 +99,50 @@ int evalErrors(const CY_RETURN_STATUS error)
|
|||||||
printf("Error no. %i!\n", errCast);
|
printf("Error no. %i!\n", errCast);
|
||||||
puts("This should not happen.");
|
puts("This should not happen.");
|
||||||
puts("Please send me a bug report to: kristjan.komlosi@gmail.com");
|
puts("Please send me a bug report to: kristjan.komlosi@gmail.com");
|
||||||
|
return errCast;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int locateDevice() // locate the device and verify it's the right one
|
int locateDevice() // locate the device and verify it's the right one
|
||||||
{
|
{
|
||||||
printf("Locating devices...");
|
printf("Locating devices...");
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
CY_RETURN_STATUS retVal;
|
CY_RETURN_STATUS retVal;
|
||||||
retVal = CyGetDeviceInfoVidPid(deviceVidPid, deviceNumList, deviceInfoList, &deviceCount, devInfoListLen);
|
retVal = CyGetDeviceInfoVidPid(deviceVidPid, deviceNumList, deviceInfoList,
|
||||||
|
&deviceCount, devInfoListLen);
|
||||||
throw retVal;
|
throw retVal;
|
||||||
}
|
} catch (CY_RETURN_STATUS errVal) {
|
||||||
catch(CY_RETURN_STATUS errVal)
|
|
||||||
{
|
|
||||||
int r = evalErrors(errVal);
|
int r = evalErrors(errVal);
|
||||||
if( r != 0 )
|
if (r != 0) {
|
||||||
{
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
if (deviceCount > 1)
|
if (deviceCount > 1) {
|
||||||
{
|
puts("More than one device found. The first one will be used unless told "
|
||||||
puts("More than one device found. The first one will be used unless told otherwise.");
|
"otherwise.");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int selectDevice(const UINT8 whichDev = 1)
|
int selectDevice(const uint8_t whichDev = 0) {
|
||||||
{
|
if (deviceCount == 0) {
|
||||||
if (deviceCount == 0)
|
|
||||||
{
|
|
||||||
puts("No devices found!");
|
puts("No devices found!");
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
if (whichDev > deviceCount)
|
if (whichDev > deviceCount) {
|
||||||
{
|
|
||||||
puts("The requested device doesn't exist.");
|
puts("The requested device doesn't exist.");
|
||||||
return 5;
|
return 5;
|
||||||
}
|
}
|
||||||
int errval = CyOpen(13, 0, &deviceHandle);
|
CY_RETURN_STATUS retval =
|
||||||
printf("errrval: %i, device %i\n", errval, deviceNumList[whichDev]);
|
CyOpen(deviceNumList[whichDev], defaultInterfaceNum, &deviceHandle);
|
||||||
|
if (!evalErrors(retval)) {
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int main(int argc, char const *argv[]) {
|
||||||
|
|
||||||
int main(int argc, char const *argv[])
|
|
||||||
{
|
|
||||||
initLib();
|
initLib();
|
||||||
locateDevice();
|
locateDevice();
|
||||||
for (size_t i = 0; i < 16; i++) {
|
|
||||||
selectDevice(i); /* code */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user