Command all jmCLIG modules from serial port

Committer:
jm
Date:
Sat Feb 12 16:50:25 2011 +0000
Revision:
0:9112e09912db
jmAll Command Line Interface Module

Who changed what in which revision?

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