Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mantis_comms-2 mantis_stepper mbed
commands.cpp
00001 /* 00002 * These commands aren't just for serial comms, the ones without serialSend can be called by the interface module as well 00003 */ 00004 #include "mantis_stepper.h" 00005 #include "mbed.h" 00006 #include "commands.h" 00007 #include "mantis_comms.h" 00008 #include <math.h> 00009 #include <string.h> 00010 #include <stdio.h> 00011 00012 #define COMMAND if(!strcmp( 00013 #define ACTION ,s)) 00014 #define convert (1.024/32767) 00015 #define coefa ((float)0.1)//0.5 00016 #define coefb ((float)0.05) 00017 00018 PRIVATE char buffer[64]; 00019 00020 PRIVATE char* dtos(double var) { 00021 sprintf(buffer, "%g", var); 00022 return buffer; // returns a pointer to buffer. 00023 } 00024 00025 void SetPosition(long index,long pos); 00026 void StepperTest(long index); 00027 void SetSpeedMode(long index,long dir); 00028 void SetPosMode(long index); 00029 00030 00031 00032 PRIVATE MantisComms *TitaniumLink; // keeping a reference to the comms interfaces here, allows them to inter-communicate 00033 00034 00035 00036 void TitaniumSend(const char *s) 00037 { 00038 TitaniumLink->serialSend(s,1); 00039 } 00040 00041 00042 /*This is the function that is "called back" from the manti_comms code. It's address is passed to the constructor: 00043 MantisComms::MantisComms(void (*CallBack)(const char *, double,const char *sPram,MantisComms *),PinName Tx,PinName Rx) */ 00044 PUBLIC void runTitaniumCommand(const char *s, double p,const char *sParam,MantisComms *TitaniumComms) { 00045 /* 00046 s points to a string that contains any chars after the "=", or else \0 00047 p contains any numeric parameter after the "=" interpreted as a double 00048 sParam points to a string that contains any params after the "=" 00049 */ 00050 00051 COMMAND "D?" ACTION {TitaniumComms->serialSend("123456",1);return;} else //Return serial number 00052 COMMAND "FW?" ACTION {TitaniumComms->serialSend("1.0",1);return;} else //Return firmware version 00053 COMMAND "HW?" ACTION {TitaniumComms->serialSend("1.0",1);return;} else //Return hardware version 00054 COMMAND "ver?" ACTION {TitaniumComms->serialSend("1.1", 1);return;} 00055 COMMAND "POS=" ACTION {SetPosition(0,p);return;} 00056 COMMAND "SPEEDMODE=" ACTION {SetSpeedMode(0,p);return;} 00057 COMMAND "POSMODE?" ACTION {SetPosMode(0);return;} 00058 COMMAND "TEST?" ACTION {StepperTest(0);return;} 00059 00060 00061 00062 } 00063 00064 00065 00066 00067 00068
Generated on Wed Aug 3 2022 00:43:41 by
