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 03:03:39 2018 +0000
Revision:
1:3a86ce26147b
Parent:
0:c1d649c7b904
Remove stdint.h

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