asserts and error checking
This commit is contained in:
@@ -4,10 +4,14 @@
|
||||
#include <assert.h>
|
||||
#include "header/CyUSBSerial.h"
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef enum inErr {
|
||||
USAGE = 0,
|
||||
INVALID
|
||||
SUCCESS = 0,
|
||||
USAGE,
|
||||
INVALID,
|
||||
NO_DEVICES
|
||||
} inErr;
|
||||
|
||||
void cyErrHandler(CY_RETURN_STATUS err);
|
||||
@@ -16,14 +20,18 @@ void inErrHandler(inErr err);
|
||||
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 err = CySetGpioValue(h, pinNumber, value);
|
||||
if (err) cyErrHandler(err);
|
||||
CY_RETURN_STATUS r = CySetGpioValue(h, pinNumber, value);
|
||||
if (r != CY_SUCCESS) cyErrHandler(r);
|
||||
return value;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
bool flpPin(CY_HANDLE h, int pinNumber) {
|
||||
@@ -37,4 +45,14 @@ bool flpPin(CY_HANDLE h, int pinNumber) {
|
||||
|
||||
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user