error cleaning, attach

This commit is contained in:
Kristjan Komlosi
2019-07-22 16:40:17 +02:00
parent 1758671962
commit 439f1beede
3 changed files with 50 additions and 16 deletions

View File

@@ -1,8 +1,9 @@
// TinI/O code rewrite of 2019 - fixing a kid's mistakes
// This code is licensed under the ISC license
// This code is licensed under the ISC license, by permission of myself
#include <stdbool.h>
#include <assert.h>
#include "header/CyUSBSerial.h"
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
@@ -14,14 +15,21 @@ typedef enum inErr {
NO_DEVICES
} inErr;
void cyErrHandler(CY_RETURN_STATUS err);
void inErrHandler(inErr err);
void cyErrHandler(CY_RETURN_STATUS err) {
if (err == CY_SUCCESS) {
return;
}
}
void inErrHandler(inErr err) {
if (err == SUCCESS) {
return;
}
}
bool setPin(CY_HANDLE h, int pinNumber, bool value) {
assert(pinNumber <= 11); // sanity checks, should be sanitized in the parser
assert(pinNumber >=0);
CY_RETURN_STATUS r = CySetGpioValue(h, pinNumber, value);
if (r != CY_SUCCESS) cyErrHandler(r);
cyErrHandler(CySetGpioValue(h, pinNumber, value));
return value;
}
@@ -29,8 +37,7 @@ bool getPin(CY_HANDLE h, int pinNumber){
assert(pinNumber <= 11); // sanity checks, should be sanitized in the parser
assert(pinNumber >=0);
uint8_t v;
CY_RETURN_STATUS r = CyGetGpioValue(h, pinNumber, &v);
if (r != CY_SUCCESS) cyErrHandler(r);
cyErrHandler(CyGetGpioValue(h, pinNumber, &v));
return (bool) v;
}
@@ -43,16 +50,35 @@ bool flpPin(CY_HANDLE h, int pinNumber) {
return val;
}
void parser(int argc, char **args);
inErr attachHandles() {
void attachHandles(CY_HANDLE *h) {
uint8_t num = 0;
cyErrHandler(CyGetListofDevices(&num));
assert(num > 0); /* sanity check, no devices should trigger a
CY_ERROR_DEVICE_NOT_FOUND error in cyErrHandler*/
CY_DEVICE_INFO deviceInfo[num];
for(uint8_t i = num; i >= 0; i--) { // iterate through the device info array
/* Pointer arithmetics: same as &deviceInfo[num] but without an
unnecessary reference-to-dereference narrative. Keep it simple, stupid!
*/
cyErrHandler(CyGetDeviceInfo(num, deviceInfo+i)); // fill deviceInfo
}
/* at this point, every element of deviceInfo should have a CY_DEVICE_INFO
struct inside. */
// TODO: assert dis.
for (uint8_t i = 0; i < num; i++) {
if (strcmp((deviceInfo+i) -> manufacturerName, "tinio")) {
cyErrHandler(CyOpen(i, 0, h));
}
}
/* This abominable trainwreck of a hack needs an explanation. i iterates
through the deviceInfo array, until it hits a device with the manufacturer
string set to "tinio". It then calls CyOpen on the device. This WILL fail
miserably if the device is set to CDC mode, but custom and PHDC work fine.
*/
// TODO: mek dis betr
}
int main(int argc, char **args){
CY_RETURN_STATUS r = CyLibraryInit();
if (r != CY_SUCCESS) cyErrHandler(r);
}

BIN
try Executable file

Binary file not shown.

8
try.c Normal file
View File

@@ -0,0 +1,8 @@
#include <stdio.h>
int main () {
unsigned a = 10;
for (a -= 1; a; a--) {
printf("%d", a);
}
}