asserts and error checking

This commit is contained in:
d3m1g0d
2019-07-19 21:50:58 +02:00
parent 0aa4491dc6
commit 4ce1316a00

View File

@@ -4,10 +4,14 @@
#include <assert.h> #include <assert.h>
#include "header/CyUSBSerial.h" #include "header/CyUSBSerial.h"
#include <stdio.h> #include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
typedef enum inErr { typedef enum inErr {
USAGE = 0, SUCCESS = 0,
INVALID USAGE,
INVALID,
NO_DEVICES
} inErr; } inErr;
void cyErrHandler(CY_RETURN_STATUS err); void cyErrHandler(CY_RETURN_STATUS err);
@@ -16,14 +20,18 @@ void inErrHandler(inErr err);
bool setPin(CY_HANDLE h, int pinNumber, bool value) { bool setPin(CY_HANDLE h, int pinNumber, bool value) {
assert(pinNumber <= 11); // sanity checks, should be sanitized in the parser assert(pinNumber <= 11); // sanity checks, should be sanitized in the parser
assert(pinNumber >=0); assert(pinNumber >=0);
CY_RETURN_STATUS err = CySetGpioValue(h, pinNumber, value); CY_RETURN_STATUS r = CySetGpioValue(h, pinNumber, value);
if (err) cyErrHandler(err); if (r != CY_SUCCESS) cyErrHandler(r);
return value; return value;
} }
bool getPin(CY_HANDLE h, int pinNumber){ bool getPin(CY_HANDLE h, int pinNumber){
assert(pinNumber <= 11); // sanity checks, should be sanitized in the parser assert(pinNumber <= 11); // sanity checks, should be sanitized in the parser
assert(pinNumber >=0); assert(pinNumber >=0);
uint8_t v;
CY_RETURN_STATUS r = CyGetGpioValue(h, pinNumber, &v);
if (r != CY_SUCCESS) cyErrHandler(r);
return (bool)v;
} }
bool flpPin(CY_HANDLE h, int pinNumber) { bool flpPin(CY_HANDLE h, int pinNumber) {
@@ -37,4 +45,14 @@ bool flpPin(CY_HANDLE h, int pinNumber) {
void parser(int argc, char **args); void parser(int argc, char **args);
int main(int argc, char **args);
inErr attachHandles() {
}
int main(int argc, char **args){
CY_RETURN_STATUS r = CyLibraryInit();
if (r != CY_SUCCESS) cyErrHandler(r);
}