Auxiliaries I use for CreaBot

Committer:
sepp_nepp
Date:
Wed Oct 31 14:22:26 2018 +0000
Revision:
0:32b17da1ddae
First Commit of Creabot Auxiliary functions

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sepp_nepp 0:32b17da1ddae 1
sepp_nepp 0:32b17da1ddae 2 #ifndef BOT_AUXILIARIES_H
sepp_nepp 0:32b17da1ddae 3 #define BOT_AUXILIARIES_H
sepp_nepp 0:32b17da1ddae 4
sepp_nepp 0:32b17da1ddae 5 #include "mbed.h"
sepp_nepp 0:32b17da1ddae 6 #include "LED_WS2812.h"
sepp_nepp 0:32b17da1ddae 7
sepp_nepp 0:32b17da1ddae 8
sepp_nepp 0:32b17da1ddae 9 // Put the LED names in the order they are chained up
sepp_nepp 0:32b17da1ddae 10 enum LED_Nr{ ledAvG, ledAvD, ledArD, ledArG, NumLEDs };
sepp_nepp 0:32b17da1ddae 11
sepp_nepp 0:32b17da1ddae 12
sepp_nepp 0:32b17da1ddae 13 // *****************************************************************
sepp_nepp 0:32b17da1ddae 14 // Handle all the LEDs with some general function wrappers functions
sepp_nepp 0:32b17da1ddae 15 // *****************************************************************
sepp_nepp 0:32b17da1ddae 16
sepp_nepp 0:32b17da1ddae 17 /** Control 4 LEDs around the Car: front / rear, left / right
sepp_nepp 0:32b17da1ddae 18 *
sepp_nepp 0:32b17da1ddae 19 * Example:
sepp_nepp 0:32b17da1ddae 20 * @code
sepp_nepp 0:32b17da1ddae 21 * // --- Define the PIN where the LED band is connected -----
sepp_nepp 0:32b17da1ddae 22 * LED_CAR ledBand(PB_5,4);
sepp_nepp 0:32b17da1ddae 23 * Setup rainbow colors for the ledBand
sepp_nepp 0:32b17da1ddae 24 * ledBand.LEDsRainbow();
sepp_nepp 0:32b17da1ddae 25 * Rotate the colors for the ledBand
sepp_nepp 0:32b17da1ddae 26 * ledBand.StartRotation(0.6) ;
sepp_nepp 0:32b17da1ddae 27 * Turn off the LEDs:
sepp_nepp 0:32b17da1ddae 28 * ledBand.LEDsOff();
sepp_nepp 0:32b17da1ddae 29 * @endcode
sepp_nepp 0:32b17da1ddae 30 */
sepp_nepp 0:32b17da1ddae 31
sepp_nepp 0:32b17da1ddae 32
sepp_nepp 0:32b17da1ddae 33 class LED_CAR: public LED_WS2812
sepp_nepp 0:32b17da1ddae 34 {
sepp_nepp 0:32b17da1ddae 35 public:
sepp_nepp 0:32b17da1ddae 36 /** Create a Car-LED object to control the four LEDs around the car
sepp_nepp 0:32b17da1ddae 37 *
sepp_nepp 0:32b17da1ddae 38 * @param PinName Pin Name through wich the LEDs are controlled
sepp_nepp 0:32b17da1ddae 39 * @param _nbLeds Number of LEDs actually implemented, defaults to 4
sepp_nepp 0:32b17da1ddae 40 */
sepp_nepp 0:32b17da1ddae 41 LED_CAR(PinName _PinOut, int _nbLeds):LED_WS2812(_PinOut, _nbLeds) { };
sepp_nepp 0:32b17da1ddae 42
sepp_nepp 0:32b17da1ddae 43 void LEDsOff( void );
sepp_nepp 0:32b17da1ddae 44 void LEDsRainbow( void );
sepp_nepp 0:32b17da1ddae 45 void LEDNrCol(LED_Nr aNr, int parameter) ;
sepp_nepp 0:32b17da1ddae 46 void LEDsRainbowMove( double speed );
sepp_nepp 0:32b17da1ddae 47 void LEDClignote(LED_Nr aNr, int OnOff);
sepp_nepp 0:32b17da1ddae 48 int ColNr2Color( char ColNr);
sepp_nepp 0:32b17da1ddae 49
sepp_nepp 0:32b17da1ddae 50 // *****************************************************************
sepp_nepp 0:32b17da1ddae 51 // Handle all the LEDs specifically with the LED Position definitions
sepp_nepp 0:32b17da1ddae 52 // *****************************************************************
sepp_nepp 0:32b17da1ddae 53
sepp_nepp 0:32b17da1ddae 54 void LEDFront(int ColNr) ;
sepp_nepp 0:32b17da1ddae 55 void LEDRear(int ColNr) ;
sepp_nepp 0:32b17da1ddae 56 void LEDCligR(int speed);
sepp_nepp 0:32b17da1ddae 57 void LEDCligL(int speed);
sepp_nepp 0:32b17da1ddae 58 void LEDAnim(int speed);
sepp_nepp 0:32b17da1ddae 59 }; // class LED_CAR
sepp_nepp 0:32b17da1ddae 60
sepp_nepp 0:32b17da1ddae 61 const int BuffLen = 512;
sepp_nepp 0:32b17da1ddae 62
sepp_nepp 0:32b17da1ddae 63 // Define States of the interpreter
sepp_nepp 0:32b17da1ddae 64 enum InterpretState { isStartNew, isLineFilling, isOverflow, isWaitNewLine};
sepp_nepp 0:32b17da1ddae 65
sepp_nepp 0:32b17da1ddae 66 typedef struct RD_CMD_TYPE {
sepp_nepp 0:32b17da1ddae 67 char Command; // Holds the next read command character
sepp_nepp 0:32b17da1ddae 68 int Parameter ; // Holds one int Parameter
sepp_nepp 0:32b17da1ddae 69 int NumParam ; // Indicates how many parameters where found
sepp_nepp 0:32b17da1ddae 70 } RD_CMD_TYPE;
sepp_nepp 0:32b17da1ddae 71
sepp_nepp 0:32b17da1ddae 72
sepp_nepp 0:32b17da1ddae 73 // Uses a Ring buffer to buffer incomiing characters
sepp_nepp 0:32b17da1ddae 74 // Uses a parsing function to extract lines containing a command each
sepp_nepp 0:32b17da1ddae 75 class Interpreter{
sepp_nepp 0:32b17da1ddae 76 public:
sepp_nepp 0:32b17da1ddae 77 // Interpreter Class Creation
sepp_nepp 0:32b17da1ddae 78 Interpreter();
sepp_nepp 0:32b17da1ddae 79 void Reinit( void );
sepp_nepp 0:32b17da1ddae 80
sepp_nepp 0:32b17da1ddae 81 public: // the writing mechanics
sepp_nepp 0:32b17da1ddae 82 void AddChar ( char aChar ); // Barebone function, assumes that checks havee been performed by writeBuf!
sepp_nepp 0:32b17da1ddae 83 void writeBuf( char c) ; // High level method to add a Char to the buffer,
sepp_nepp 0:32b17da1ddae 84 char RingBuf[BuffLen];
sepp_nepp 0:32b17da1ddae 85 InterpretState MyState;// Indicates if buffer overflow, line ended etc.
sepp_nepp 0:32b17da1ddae 86 int WriteIndex ; // points to next index to write to
sepp_nepp 0:32b17da1ddae 87 int BufAvail ; // indicates how much of the buffer is still available
sepp_nepp 0:32b17da1ddae 88 int LinesComplete; // Indicates how many complete lines are available
sepp_nepp 0:32b17da1ddae 89
sepp_nepp 0:32b17da1ddae 90 public: // the reading mechanics
sepp_nepp 0:32b17da1ddae 91 RD_CMD_TYPE ParseCommand( void ) ;
sepp_nepp 0:32b17da1ddae 92 int ScanIndex; // points to next index to read from to
sepp_nepp 0:32b17da1ddae 93 char actC ; // holds the actual character
sepp_nepp 0:32b17da1ddae 94 private:
sepp_nepp 0:32b17da1ddae 95 char GetAChar ( void );
sepp_nepp 0:32b17da1ddae 96 void SkipBlanks( void );
sepp_nepp 0:32b17da1ddae 97 int ReadAnInt ( void );
sepp_nepp 0:32b17da1ddae 98 char actPP ( void );
sepp_nepp 0:32b17da1ddae 99 }; // class Interpreter
sepp_nepp 0:32b17da1ddae 100
sepp_nepp 0:32b17da1ddae 101 #endif