Control up to 4 DC Motors from a serial port

Dependencies:   mbed

Committer:
jm
Date:
Sat Feb 12 16:39:20 2011 +0000
Revision:
0:dedab08b24ea
jmMotor Command Line Interface Module

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jm 0:dedab08b24ea 1 /*************************************************************************
jm 0:dedab08b24ea 2 * @file main.cpp
jm 0:dedab08b24ea 3 *
jm 0:dedab08b24ea 4 * @version 1.0
jm 0:dedab08b24ea 5 * @date Feb 11, 2011
jm 0:dedab08b24ea 6 */
jm 0:dedab08b24ea 7
jm 0:dedab08b24ea 8 #include "mbed.h"
jm 0:dedab08b24ea 9
jm 0:dedab08b24ea 10 // Basic includes
jm 0:dedab08b24ea 11 #include "jmInterpreter.h"
jm 0:dedab08b24ea 12 #include "jmRingBuffer.h"
jm 0:dedab08b24ea 13 #include "jmCommands.h"
jm 0:dedab08b24ea 14 #include "jmMessages.h"
jm 0:dedab08b24ea 15 #include "LPC17xx.h"
jm 0:dedab08b24ea 16
jm 0:dedab08b24ea 17 LPC_GPIO_TypeDef *jmGPIO[5] ={LPC_GPIO0,LPC_GPIO1,LPC_GPIO2,LPC_GPIO3,LPC_GPIO4};
jm 0:dedab08b24ea 18
jm 0:dedab08b24ea 19 // CLIG-INCLUDE
jm 0:dedab08b24ea 20 #include "jmMotor.h"
jm 0:dedab08b24ea 21
jm 0:dedab08b24ea 22
jm 0:dedab08b24ea 23 // Initializations
jm 0:dedab08b24ea 24 void Inits(){
jm 0:dedab08b24ea 25 InitCommandLineRingBuffer();
jm 0:dedab08b24ea 26 InitMessages();
jm 0:dedab08b24ea 27 cli_version();
jm 0:dedab08b24ea 28
jm 0:dedab08b24ea 29 // CLIG-INIT
jm 0:dedab08b24ea 30 MotorInit();
jm 0:dedab08b24ea 31
jm 0:dedab08b24ea 32 }
jm 0:dedab08b24ea 33
jm 0:dedab08b24ea 34 // EggTimer tickers for modules
jm 0:dedab08b24ea 35 void eggTimers(){
jm 0:dedab08b24ea 36 int i;
jm 0:dedab08b24ea 37 // CLIG-TIMER
jm 0:dedab08b24ea 38 // Module jmMotor
jm 0:dedab08b24ea 39 for(i=0;i<motorQty;i++)if(sMotor[i].eggTimer>0)sMotor[i].eggTimer--;
jm 0:dedab08b24ea 40
jm 0:dedab08b24ea 41 }
jm 0:dedab08b24ea 42
jm 0:dedab08b24ea 43 int main() {
jm 0:dedab08b24ea 44 unsigned char c;
jm 0:dedab08b24ea 45 Serial pc(USBTX, USBRX); // communication medium
jm 0:dedab08b24ea 46 pc.baud(115200); // 115200 bauds, 8bits, 1 stop, no control flow
jm 0:dedab08b24ea 47 Ticker tick; // enable system ticks
jm 0:dedab08b24ea 48 tick.attach_us(&eggTimers,1000); // enable and select granularity for egg timers
jm 0:dedab08b24ea 49 Inits(); // initialization
jm 0:dedab08b24ea 50
jm 0:dedab08b24ea 51 while(true){
jm 0:dedab08b24ea 52 if( pc.readable()){ // something to read ?
jm 0:dedab08b24ea 53 c= pc.getc(); // read one char
jm 0:dedab08b24ea 54
jm 0:dedab08b24ea 55 if(Echo) printf("%c",c); // echo it ?
jm 0:dedab08b24ea 56
jm 0:dedab08b24ea 57 switch(c){ // process it
jm 0:dedab08b24ea 58
jm 0:dedab08b24ea 59 case 8 : DelChar(pLine); // remove last one
jm 0:dedab08b24ea 60 break;
jm 0:dedab08b24ea 61 case 10 : Insert(c,pLine); // end of line
jm 0:dedab08b24ea 62 Interpret();// process line
jm 0:dedab08b24ea 63 break;
jm 0:dedab08b24ea 64 default : Insert(c,pLine); // insert char in command line buffer
jm 0:dedab08b24ea 65 }
jm 0:dedab08b24ea 66 } // if
jm 0:dedab08b24ea 67
jm 0:dedab08b24ea 68 // CLIG-SM
jm 0:dedab08b24ea 69 MotorSM();
jm 0:dedab08b24ea 70
jm 0:dedab08b24ea 71
jm 0:dedab08b24ea 72 }// while
jm 0:dedab08b24ea 73 }// main
jm 0:dedab08b24ea 74
jm 0:dedab08b24ea 75
jm 0:dedab08b24ea 76