Control up to 4 steppers axis with limit switch logic from serial port

Dependencies:   mbed

Committer:
jm
Date:
Sat Feb 12 16:49:03 2011 +0000
Revision:
0:3e676fcd9c71
jmStepperAxis Command Line Interface Module

Who changed what in which revision?

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