From 439f1beede82a17d2a16a1015ce83560dd3bbb65 Mon Sep 17 00:00:00 2001 From: Kristjan Komlosi Date: Mon, 22 Jul 2019 16:40:17 +0200 Subject: [PATCH] error cleaning, attach --- tinio/tinio.c | 58 ++++++++++++++++++++++++++++++++++++-------------- try | Bin 0 -> 16544 bytes try.c | 8 +++++++ 3 files changed, 50 insertions(+), 16 deletions(-) create mode 100755 try create mode 100644 try.c diff --git a/tinio/tinio.c b/tinio/tinio.c index d60e43f..be80829 100644 --- a/tinio/tinio.c +++ b/tinio/tinio.c @@ -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 #include #include "header/CyUSBSerial.h" +#include #include #include #include @@ -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,30 +37,48 @@ 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); - return (bool)v; + cyErrHandler(CyGetGpioValue(h, pinNumber, &v)); + return (bool) v; } bool flpPin(CY_HANDLE h, int pinNumber) { assert(pinNumber <= 11); // sanity checks, should be sanitized in the parser - assert(pinNumber >=0); + assert(pinNumber >= 0); bool val = getPin(h, pinNumber); val = !val; setPin(h, pinNumber, val); 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); - - } diff --git a/try b/try new file mode 100755 index 0000000000000000000000000000000000000000..9f6285e55f462d8dbdfcbf2752bdb5927106fb5a GIT binary patch literal 16544 zcmeHOZ)_CD6@PbU>`Q?2VM1ddDVr7))5hlm5@VVW_H3WMZq1(>2#H!)&c3sK?fK5S z+iUGeZK+I9PZY|BsEYcb%11s#DwV2=FG-9{L6!0WJ~dTSiAJPy+E5&cAS()7-N|map+L3PGyx+Xvo0&JWyR)}DKS>Vu1p@()6olu2G(D;-$UXvSyOhdU7pw#w zz6_5;BO(p>(^UycJ125HXcveKvt0-!@y>Jk`Jj#(={gB`OdXe`w2&n6mXgj{TOQ{^ zkr1_uiMN8XtONH?Q^GjS&n;*d+VN`ytf8*oDTjo34fAfdUZ|z<^{$%6tekt=&cv3G?T#0b`xe7i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lp@MRqz{tx-@BA4cl)GzCO+24GF z+b?mHdSx8{hFmfczC0H!bRdXH>}+jm{)(T!V}X+ox^A1sZK2tsb`+k-+gRe{%eqfv z{)6flho4}Ed`bId9TjK3)Fbv(mot5e3Sn$sD-!;s4khVMd2Rd!-k5UmAdQ@EF*5|M9vI!v%!K1>z0Z1bAr~m)} literal 0 HcmV?d00001 diff --git a/try.c b/try.c new file mode 100644 index 0000000..36fbb79 --- /dev/null +++ b/try.c @@ -0,0 +1,8 @@ +#include + +int main () { + unsigned a = 10; + for (a -= 1; a; a--) { + printf("%d", a); + } +}