Auxiliaries I use for CreaBot

Bot_Auxiliaries.h

Committer:
sepp_nepp
Date:
2018-10-31
Revision:
0:32b17da1ddae

File content as of revision 0:32b17da1ddae:


#ifndef BOT_AUXILIARIES_H
#define BOT_AUXILIARIES_H

#include "mbed.h"
#include "LED_WS2812.h"


// Put the LED names in the order they are chained up 
enum LED_Nr{ ledAvG, ledAvD, ledArD, ledArG, NumLEDs };


// *****************************************************************
// Handle all the LEDs with some general function wrappers functions
// *****************************************************************

/** Control 4 LEDs around the Car: front / rear, left / right
 *
 * Example:
 * @code
 * // --- Define the PIN where the LED band is connected -----
 * LED_CAR ledBand(PB_5,4);
 * Setup rainbow colors for the ledBand
 * ledBand.LEDsRainbow();
 * Rotate the colors for the ledBand
 * ledBand.StartRotation(0.6) ;
 * Turn off the LEDs:
 * ledBand.LEDsOff();
 * @endcode
 */


class LED_CAR: public LED_WS2812
{
  public:
   /** Create a Car-LED object to control the four LEDs around the car
     *
     *  @param PinName Pin Name through wich the LEDs are controlled
     *  @param _nbLeds Number of LEDs actually implemented, defaults to 4
     */
    LED_CAR(PinName _PinOut,  int _nbLeds):LED_WS2812(_PinOut, _nbLeds) {  };
    
    void LEDsOff( void );
    void LEDsRainbow( void );
    void LEDNrCol(LED_Nr aNr, int parameter) ;
    void LEDsRainbowMove( double speed );
    void LEDClignote(LED_Nr aNr, int OnOff);
    int ColNr2Color( char ColNr);

    // *****************************************************************
    // Handle all the LEDs specifically with the LED Position definitions
    // *****************************************************************
    
    void LEDFront(int ColNr) ;
    void LEDRear(int ColNr) ;
    void LEDCligR(int speed);
    void LEDCligL(int speed);
    void LEDAnim(int speed);
}; // class LED_CAR

const int BuffLen = 512;

// Define States of the interpreter
enum InterpretState { isStartNew, isLineFilling, isOverflow, isWaitNewLine};

typedef struct RD_CMD_TYPE {
    char Command;    // Holds the next read command character
    int  Parameter ; // Holds one int Parameter
    int  NumParam ;  // Indicates how many parameters where found
    } RD_CMD_TYPE;


// Uses a Ring buffer to buffer incomiing characters
// Uses a parsing function to extract lines containing a command each
class Interpreter{
  public: 
    // Interpreter Class Creation 
    Interpreter();
    void Reinit( void );

  public: // the writing mechanics
    void AddChar ( char aChar ); // Barebone function, assumes that checks havee been performed by writeBuf!
    void writeBuf( char c) ; // High level method to add a Char to the buffer,
    char RingBuf[BuffLen];
    InterpretState MyState;// Indicates if buffer overflow, line ended etc. 
    int  WriteIndex   ;  // points to next index to write to
    int  BufAvail     ;  // indicates how much of the buffer is still available
    int  LinesComplete; // Indicates how many complete lines are available
    
  public: // the reading mechanics
    RD_CMD_TYPE ParseCommand( void ) ;
    int  ScanIndex;    // points to next index to read from to
    char actC     ;        // holds the actual character
  private:
    char GetAChar  ( void );
    void SkipBlanks( void );
    int  ReadAnInt ( void );
    char actPP     ( void );
}; // class Interpreter

#endif