SparkFun Line Follower Array Library. based on https://github.com/sparkfun/SparkFun_Line_Follower_Array_Arduino_Library

Dependents:   WRS_mechanamu_test

Committer:
sgrsn
Date:
Fri Aug 31 02:52:24 2018 +0000
Revision:
0:c1d649c7b904
Child:
1:3a86ce26147b
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sgrsn 0:c1d649c7b904 1 #ifndef SENSORBAR_H
sgrsn 0:c1d649c7b904 2 #define SENSORBAR_H
sgrsn 0:c1d649c7b904 3
sgrsn 0:c1d649c7b904 4 #include "mbed.h"
sgrsn 0:c1d649c7b904 5 #include "stdint.h"
sgrsn 0:c1d649c7b904 6
sgrsn 0:c1d649c7b904 7 #define RECEIVE_TIMEOUT_VALUE 1000 // Timeout for I2C receive
sgrsn 0:c1d649c7b904 8
sgrsn 0:c1d649c7b904 9 // These are used for setting LED driver to linear or log mode:
sgrsn 0:c1d649c7b904 10 #define LINEAR 0
sgrsn 0:c1d649c7b904 11 #define LOGARITHMIC 1
sgrsn 0:c1d649c7b904 12
sgrsn 0:c1d649c7b904 13 // These are used for clock config:
sgrsn 0:c1d649c7b904 14 #define INTERNAL_CLOCK 2
sgrsn 0:c1d649c7b904 15 #define EXTERNAL_CLOCK 1
sgrsn 0:c1d649c7b904 16
sgrsn 0:c1d649c7b904 17 class SensorBar
sgrsn 0:c1d649c7b904 18 {
sgrsn 0:c1d649c7b904 19 public:
sgrsn 0:c1d649c7b904 20 //New functions for bar specific operation
sgrsn 0:c1d649c7b904 21 SensorBar(I2C *i2c, uint8_t address, uint8_t resetPin = 255, uint8_t interruptPin = 255, uint8_t oscillatorPin = 255 );
sgrsn 0:c1d649c7b904 22 uint8_t begin( void );
sgrsn 0:c1d649c7b904 23 uint8_t getRaw( void );
sgrsn 0:c1d649c7b904 24 int8_t getPosition( void );
sgrsn 0:c1d649c7b904 25 uint8_t getDensity( void );
sgrsn 0:c1d649c7b904 26 void setBarStrobe( void );
sgrsn 0:c1d649c7b904 27 void clearBarStrobe( void );
sgrsn 0:c1d649c7b904 28 void setInvertBits( void ); //Dark (no reflection) = 1, position returns center of dark
sgrsn 0:c1d649c7b904 29 void clearInvertBits( void ); //Light (reflection) = 1, position returns center of light
sgrsn 0:c1d649c7b904 30
sgrsn 0:c1d649c7b904 31 //Functions pulled from the SX1509 driver
sgrsn 0:c1d649c7b904 32 void reset( void );
sgrsn 0:c1d649c7b904 33 void debounceConfig( uint8_t configValue );
sgrsn 0:c1d649c7b904 34 void debounceEnable( uint8_t pin );
sgrsn 0:c1d649c7b904 35 void enableInterrupt( uint8_t pin, uint8_t riseFall );
sgrsn 0:c1d649c7b904 36 unsigned int interruptSource( void );
sgrsn 0:c1d649c7b904 37 void configClock( uint8_t oscSource = 2, uint8_t oscPinFunction = 0, uint8_t oscFreqOut = 0, uint8_t oscDivider = 1 );
sgrsn 0:c1d649c7b904 38
sgrsn 0:c1d649c7b904 39
sgrsn 0:c1d649c7b904 40 private:
sgrsn 0:c1d649c7b904 41 //Holding variables
sgrsn 0:c1d649c7b904 42 uint8_t lastBarRawValue;
sgrsn 0:c1d649c7b904 43 uint8_t lastBarPositionValue;
sgrsn 0:c1d649c7b904 44
sgrsn 0:c1d649c7b904 45 //Settings
sgrsn 0:c1d649c7b904 46 uint8_t deviceAddress; // I2C Address of SX1509
sgrsn 0:c1d649c7b904 47 uint8_t barStrobe; // 0 = always on, 1 = power saving by IR LED strobe
sgrsn 0:c1d649c7b904 48 uint8_t invertBits; // 1 = invert
sgrsn 0:c1d649c7b904 49
sgrsn 0:c1d649c7b904 50 // Pin definitions:
sgrsn 0:c1d649c7b904 51 uint8_t pinInterrupt;
sgrsn 0:c1d649c7b904 52 uint8_t pinOscillator;
sgrsn 0:c1d649c7b904 53 uint8_t pinReset;
sgrsn 0:c1d649c7b904 54
sgrsn 0:c1d649c7b904 55 // Read Functions:
sgrsn 0:c1d649c7b904 56 void scan( void );
sgrsn 0:c1d649c7b904 57 uint8_t readByte(uint8_t registerAddress);
sgrsn 0:c1d649c7b904 58 unsigned int readWord(uint8_t registerAddress);
sgrsn 0:c1d649c7b904 59 void readBytes(uint8_t firstRegisterAddress, char * destination, uint8_t length);
sgrsn 0:c1d649c7b904 60 // Write functions:
sgrsn 0:c1d649c7b904 61 void writeByte(uint8_t registerAddress, uint8_t writeValue);
sgrsn 0:c1d649c7b904 62 void writeWord(uint8_t registerAddress, unsigned int writeValue);
sgrsn 0:c1d649c7b904 63 void writeBytes(uint8_t firstRegisterAddress, uint8_t * writeArray, uint8_t length);
sgrsn 0:c1d649c7b904 64
sgrsn 0:c1d649c7b904 65 I2C *_i2c;
sgrsn 0:c1d649c7b904 66 };
sgrsn 0:c1d649c7b904 67
sgrsn 0:c1d649c7b904 68 //****************************************************************************//
sgrsn 0:c1d649c7b904 69 //
sgrsn 0:c1d649c7b904 70 // Circular Buffer
sgrsn 0:c1d649c7b904 71 //
sgrsn 0:c1d649c7b904 72 //****************************************************************************//
sgrsn 0:c1d649c7b904 73
sgrsn 0:c1d649c7b904 74 //Class CircularBuffer is int16_t
sgrsn 0:c1d649c7b904 75 //Does not care about over-running real data ( if request is outside length's bounds ).
sgrsn 0:c1d649c7b904 76 //For example, the underlying machine writes [48], [49], [0], [1] ...
sgrsn 0:c1d649c7b904 77
sgrsn 0:c1d649c7b904 78 namespace name
sgrsn 0:c1d649c7b904 79 {
sgrsn 0:c1d649c7b904 80 class CircularBuffer
sgrsn 0:c1d649c7b904 81 {
sgrsn 0:c1d649c7b904 82 public:
sgrsn 0:c1d649c7b904 83 CircularBuffer( uint16_t inputSize );
sgrsn 0:c1d649c7b904 84 ~CircularBuffer();
sgrsn 0:c1d649c7b904 85 int16_t getElement( uint16_t ); //zero is the push location
sgrsn 0:c1d649c7b904 86 void pushElement( int16_t );
sgrsn 0:c1d649c7b904 87 int16_t averageLast( uint16_t );
sgrsn 0:c1d649c7b904 88 uint16_t recordLength( void );
sgrsn 0:c1d649c7b904 89 private:
sgrsn 0:c1d649c7b904 90 uint16_t cBufferSize;
sgrsn 0:c1d649c7b904 91 int16_t *cBufferData;
sgrsn 0:c1d649c7b904 92 int16_t cBufferLastPtr;
sgrsn 0:c1d649c7b904 93 uint8_t cBufferElementsUsed;
sgrsn 0:c1d649c7b904 94 };
sgrsn 0:c1d649c7b904 95 }
sgrsn 0:c1d649c7b904 96 #endif // SENSORBAR_H