From 31912e28d5311a0e8585dc36e2c01cdd0e3315ca Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 30 Nov 2015 16:01:54 -0500 Subject: libZEPHYR began --- src/zephyr.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 src/zephyr.c (limited to 'src/zephyr.c') diff --git a/src/zephyr.c b/src/zephyr.c new file mode 100644 index 0000000..847f95a --- /dev/null +++ b/src/zephyr.c @@ -0,0 +1,192 @@ +#include +#include + +#include + +#ifdef LCD_PORT + +static void (*_lcdUpdateFunc)(void *); +static char lcdBuffer[2][16]; + +void zLCDHandler(void *unused_param){ + while(1){ + lcdSetText(LCD_PORT,1,lcdBuffer[0]); + lcdSetText(LCD_PORT,2,lcdBuffer[1]); + + if(_lcdUpdateFunc) + _lcdUpdateFunc(unused_param); + + delay(LCD_RATE); + } +} + +void zLCDInit(void){ + lcdInit(LCD_PORT); + lcdClear(LCD_PORT); + lcdSetBacklight(LCD_PORT,true); +} + +void zLCDStart(void){ + taskCreate(zLCDHandler, + TASK_DEFAULT_STACK_SIZE, + NULL, + TASK_PRIORITY_DEFAULT + ); + + memset(&lcdBuffer,0,32); + strcpy(lcdBuffer[0]," libZEPHYR v1.0 "); +} + +void zLCDWrite(unsigned char line,const char *text,...){ + va_list args; + char buf[16]; + va_start(args,text); + sprintf(buf,text,args); + va_end(args); + strcpy(lcdBuffer[line-1],buf); +} + +void zLCDSetUpdateFunc(void (*func)(void *)){ + _lcdUpdateFunc = func; +} + +void zLCDClearUpdateFunc(void){ + _lcdUpdateFunc = 0; +} + +#endif // LCD_PORT + +#ifdef GYRO_PORT + +static Gyro gyro; +static bool gyroEnabled = false; + +void zGyroInit(void){ + if((gyro=gyroInit(2,0))){ + gyroEnabled = true; + } +} + +#endif // GYRO_PORT + +/* + * A map of what's plugged into the motor ports. + * Expected declarations: + * + * DRIVEL - Left drive port + * DRIVER - Right drive port + * +*/ + +#define MOTOR_PORT_COUNT 10 + +#ifdef IME_ENABLE +#define MOTOR_IME_COUNT 5 +#endif // IME_ENABLE + +const char *MOTOR_PORT_MAP[MOTOR_PORT_COUNT] = { + "UNUSED1", + "UNUSED2", + "UNUSED3", + "UNUSED4", + "INTAKE", + "DRIVER", + "DRIVEL", + "LIFT1", + "LIFT2", + "ROTATER" +}; + +#ifdef IME_ENABLE + +const char *MOTOR_IME_MAP[MOTOR_IME_COUNT] = { + "DRIVER", + "DRIVEL", + "ROTATER", + "LIFT1", + "LIFT2" +}; + +static unsigned int imeCount = 0; + +void zIMEInit(void){ + imeCount = imeInitializeAll(); +} + +#endif // IME_ENABLE + +void zMotorSet(const char *motor,char speed){ + for(unsigned char i=0;i