Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
#define UART1_TX_BUFFER_SIZE 10#define UART1_RX_BUFFER_SIZE 60unsigned char command;char rxBufferUsed = 0;int const checkByte = 33;char const confirmationGood = 101;char const confirmationBad = 99;int i;#include "hardware.h"// Initialise the hardwarevoid appInitHardware(void) { initHardware();}// Initialise the softwareTICK_COUNT appInitSoftware(TICK_COUNT loopStart){//start uart comm uartSetBaudRate(uart1, (BAUD_RATE)115200); rprintfInit(&uart1SendByte); rprintfChar('A'); uartFlushReceiveBuffer(UART1); return 30;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {//Check if there's new dataif (uartReceiveBufferIsEmpty(UART1) && rxBufferUsed == 0){ //if theres nothing in the buffer and there never wasi++; //tack one up on the run counterif (i==16000){rprintfChar('x'); //let me know nothing was received every few seconds to make surei=0; //everything's still running, then reset the counter} }else{ //if something is in the buffer or has beenrprintfChar('d'); //tell me! rxBufferUsed=1; //if (uartGetByte(UART1) == checkByte){ //check if its the right stuff just to keep commands in ordercommand = uartGetByte(UART1); // if it is, print the command recieved // on the segled // -------- Start Marquee-------Writer old = rprintfInit(marqueeGetWriter(&marquee)); marqueeSetEndDelay(&marquee,0); if(marqueeIsActive(&marquee)==FALSE){ rprintf("Action %s\n",command); //let me know what command was received } rprintfInit(old); // -------- End Marquee------- rprintfChar(confirmationGood); //then tell the computer it got the command successfully i=0; //reset counter}else{ //if the received first byte was not the correct verification byterprintfChar(confirmationBad);i=0; }} return 30;}
#define UART1_RX_BUFFER_SIZE 80#define UART1_TX_BUFFER_SIZE 80#include "hardware.h"char rxYes = 0;char rxChar;void appInitHardware(void) { initHardware();}TICK_COUNT appInitSoftware(TICK_COUNT loopStart){uartInit(UART1, 9600); return 0;}TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {Writer old = rprintfInit(marqueeGetWriter(&marquee));marqueeSetEndDelay(&marquee,0); if(!uartReceiveBufferIsEmpty(UART1)){ rxYes=1; rxChar = uart1GetByte(); uartFlushReceiveBuffer(UART1); txChar = rxChar + 1; uart1SendByte(txChar); } if(marqueeIsActive(&marquee)==FALSE){ if(rxYes == 1){ rprintf("%c\n", rxChar); rxYes = 0; } } rprintfInit(old); return 0;}