first commit
This commit is contained in:
72
include/drivers/AccelerometerController.h
Normal file
72
include/drivers/AccelerometerController.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#ifndef ADXL345_CONTROLLER_H
|
||||
#define ADXL345_CONTROLLER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
#define ADXL345_DEVID 0x00
|
||||
#define ADXL345_THRESH_TAP 0x1D
|
||||
#define ADXL345_OFSX 0x1E
|
||||
#define ADXL345_OFSY 0x1F
|
||||
#define ADXL345_OFSZ 0x20
|
||||
#define ADXL345_DUR 0x21
|
||||
#define ADXL345_LATENT 0x22
|
||||
#define ADXL345_WINDOW 0x23
|
||||
#define ADXL345_THRESH_ACT 0x24
|
||||
#define ADXL345_THRESH_INACT 0x25
|
||||
#define ADXL345_TIME_INACT 0x26
|
||||
#define ADXL345_ACT_INACT_CTL 0x27
|
||||
#define ADXL345_THRESH_FF 0x28
|
||||
#define ADXL345_TIME_FF 0x29
|
||||
#define ADXL345_TAP_AXES 0x2A
|
||||
#define ADXL345_ACT_TAP_STATUS 0x2B
|
||||
#define ADXL345_BW_RATE 0x2C
|
||||
#define ADXL345_POWER_CTL 0x2D
|
||||
#define ADXL345_INT_ENABLE 0x2E
|
||||
#define ADXL345_INT_MAP 0x2F
|
||||
#define ADXL345_INT_SOURCE 0x30
|
||||
#define ADXL345_DATA_FORMAT 0x31
|
||||
#define ADXL345_DATAX0 0x32
|
||||
#define ADXL345_DATAX1 0x33
|
||||
#define ADXL345_DATAY0 0x34
|
||||
#define ADXL345_DATAY1 0x35
|
||||
#define ADXL345_DATAZ0 0x36
|
||||
#define ADXL345_DATAZ1 0x37
|
||||
#define ADXL345_FIFO_CTL 0x38
|
||||
#define ADXL345_FIFO_STATUS 0x39
|
||||
|
||||
#define DEFAULT_MIN_READ_INTERVAL 50
|
||||
|
||||
class ADXL345Controller {
|
||||
private:
|
||||
uint8_t _deviceAddress;
|
||||
unsigned long _lastReadTime;
|
||||
unsigned long _minReadInterval;
|
||||
double _lastX;
|
||||
double _lastY;
|
||||
double _lastZ;
|
||||
bool _lastReadSuccess;
|
||||
|
||||
void setRegister(uint8_t reg, uint8_t value);
|
||||
uint8_t readRegister(uint8_t reg);
|
||||
void readRegisters(uint8_t reg, uint8_t count, uint8_t *buffer);
|
||||
|
||||
public:
|
||||
ADXL345Controller(uint8_t deviceAddress = 0x53);
|
||||
|
||||
void begin();
|
||||
|
||||
bool read();
|
||||
|
||||
double getX();
|
||||
double getY();
|
||||
double getZ();
|
||||
|
||||
bool isLastReadSuccessful() const;
|
||||
void setMinReadInterval(unsigned long interval);
|
||||
void setRange(uint8_t range);
|
||||
void setDataRate(uint8_t rate);
|
||||
void setOffsets(int8_t xOffset, int8_t yOffset, int8_t zOffset);
|
||||
};
|
||||
|
||||
#endif
|
||||
21
include/drivers/ButtonController.h
Normal file
21
include/drivers/ButtonController.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef BUTTON_CONTROLLER_H
|
||||
#define BUTTON_CONTROLLER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class ButtonController {
|
||||
private:
|
||||
const int _buttonPin;
|
||||
unsigned long _lastDebounceTime;
|
||||
unsigned long _debounceDelay;
|
||||
bool _lastButtonState;
|
||||
bool _buttonState;
|
||||
|
||||
public:
|
||||
ButtonController(int buttonPin, unsigned long debounceDelay = 50);
|
||||
bool wasOn();
|
||||
void tick();
|
||||
bool getState() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
27
include/drivers/DHTController.h
Normal file
27
include/drivers/DHTController.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef DHT_CONTROLLER_H
|
||||
#define DHT_CONTROLLER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <DHT.h>
|
||||
|
||||
class DHTController {
|
||||
private:
|
||||
DHT _dht;
|
||||
unsigned long _lastReadTime;
|
||||
unsigned long _minReadInterval;
|
||||
float _lastTemperature;
|
||||
float _lastHumidity;
|
||||
bool _lastReadSuccess;
|
||||
|
||||
public:
|
||||
DHTController(uint8_t pin, uint8_t type = DHT11);
|
||||
|
||||
void begin();
|
||||
bool read();
|
||||
float getTemperature();
|
||||
float getHumidity();
|
||||
bool isLastReadSuccessful() const;
|
||||
void setMinReadInterval(unsigned long interval);
|
||||
};
|
||||
|
||||
#endif
|
||||
37
include/drivers/DistanceSensorController.h
Normal file
37
include/drivers/DistanceSensorController.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef DISTANCE_SENSOR_CONTROLLER_H
|
||||
#define DISTANCE_SENSOR_CONTROLLER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#define DEFAULT_MIN_READ_INTERVAL_DIST 100
|
||||
#define DEFAULT_SAMPLES 3
|
||||
#define MAX_DISTANCE 400
|
||||
|
||||
class DistanceSensorController {
|
||||
private:
|
||||
uint8_t _trigPin;
|
||||
uint8_t _echoPin;
|
||||
unsigned long _lastReadTime;
|
||||
unsigned long _minReadInterval;
|
||||
long _lastDistanceCm;
|
||||
bool _lastReadSuccess;
|
||||
uint8_t _numSamples;
|
||||
unsigned long _timeout;
|
||||
|
||||
long microsecondsToCentimeters(long microseconds);
|
||||
|
||||
long takeMeasurement();
|
||||
|
||||
public:
|
||||
DistanceSensorController(uint8_t trigPin, uint8_t echoPin);
|
||||
void begin();
|
||||
bool read();
|
||||
long getDistanceCm();
|
||||
long getDistanceInch();
|
||||
bool isLastReadSuccessful() const;
|
||||
void setMinReadInterval(unsigned long interval);
|
||||
void setNumSamples(uint8_t samples);
|
||||
void setTimeout(unsigned long timeout);
|
||||
};
|
||||
|
||||
#endif
|
||||
68
include/drivers/JoystickController.h
Normal file
68
include/drivers/JoystickController.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#ifndef JOYSTICK_H
|
||||
#define JOYSTICK_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
enum JoystickDirection {
|
||||
CENTER,
|
||||
UP,
|
||||
UP_RIGHT,
|
||||
RIGHT,
|
||||
DOWN_RIGHT,
|
||||
DOWN,
|
||||
DOWN_LEFT,
|
||||
LEFT,
|
||||
UP_LEFT
|
||||
};
|
||||
|
||||
class JoystickController {
|
||||
private:
|
||||
uint8_t pinX;
|
||||
uint8_t pinY;
|
||||
uint8_t pinButton;
|
||||
|
||||
int centerX;
|
||||
int centerY;
|
||||
|
||||
int rawX;
|
||||
int rawY;
|
||||
bool buttonState;
|
||||
|
||||
int deadzone;
|
||||
int debounceDelay;
|
||||
unsigned long lastDebounceTime;
|
||||
|
||||
int lastX;
|
||||
int lastY;
|
||||
bool lastButtonState;
|
||||
|
||||
void readRawValues();
|
||||
|
||||
static JoystickController* _instance;
|
||||
|
||||
public:
|
||||
JoystickController(uint8_t xPin, uint8_t yPin, uint8_t buttonPin = 255);
|
||||
~JoystickController();
|
||||
|
||||
void begin();
|
||||
void calibrate();
|
||||
void setDeadzone(int value);
|
||||
void setDebounceDelay(int delayMs);
|
||||
void tick();
|
||||
|
||||
int getRawX();
|
||||
int getRawY();
|
||||
int getX();
|
||||
int getY();
|
||||
int getOffsetX();
|
||||
int getOffsetY();
|
||||
|
||||
bool isPressed();
|
||||
bool isCentered();
|
||||
|
||||
JoystickDirection getDirection();
|
||||
String getDirectionString();
|
||||
int getDistancePercent();
|
||||
};
|
||||
|
||||
#endif
|
||||
34
include/drivers/LCDController.h
Normal file
34
include/drivers/LCDController.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef LCD_CONTROLLER_H
|
||||
#define LCD_CONTROLLER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <stdio.h>
|
||||
#include <LiquidCrystal.h>
|
||||
#include "LEDController.h"
|
||||
|
||||
class LCDController {
|
||||
private:
|
||||
FILE* _lcdOutput;
|
||||
LiquidCrystal* _lcd;
|
||||
int _lcdCols;
|
||||
int _lcdRows;
|
||||
int _cursorRow;
|
||||
int _cursorCol;
|
||||
|
||||
static int lcdPutchar(char c, FILE* stream);
|
||||
static LCDController* _instance;
|
||||
|
||||
public:
|
||||
LCDController(uint8_t rs, uint8_t enable, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7,
|
||||
int cols = 16, int rows = 2);
|
||||
~LCDController();
|
||||
void begin();
|
||||
FILE* stream();
|
||||
void clear();
|
||||
void setCursor(int col, int row);
|
||||
void print(const char* text);
|
||||
|
||||
static LCDController* getInstance() { return _instance; }
|
||||
};
|
||||
|
||||
#endif
|
||||
31
include/drivers/LEDController.h
Normal file
31
include/drivers/LEDController.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef LED_CONTROLLER_H
|
||||
#define LED_CONTROLLER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class LEDController {
|
||||
private:
|
||||
const int _ledPin;
|
||||
bool _state;
|
||||
bool _isBlinking;
|
||||
unsigned long _previousMillis;
|
||||
unsigned long _blinkInterval;
|
||||
unsigned long _blinkCount;
|
||||
|
||||
public:
|
||||
LEDController(int ledPin);
|
||||
LEDController(int ledPin, bool state);
|
||||
void turnOn();
|
||||
void turnOff();
|
||||
void toggle();
|
||||
bool getState() const;
|
||||
void blink(bool enable);
|
||||
bool isBlinkingEnabled() const;
|
||||
void interval(unsigned long interval);
|
||||
unsigned long getBlinkInterval() const;
|
||||
unsigned long getBlinkCount() const;
|
||||
void tick();
|
||||
void set(bool value);
|
||||
};
|
||||
|
||||
#endif
|
||||
24
include/drivers/MotorController.h
Normal file
24
include/drivers/MotorController.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef DC_MOTOR_DRIVER_H
|
||||
#define DC_MOTOR_DRIVER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class MotorController {
|
||||
private:
|
||||
const int _pinIA;
|
||||
const int _pinIB;
|
||||
int _currentPower;
|
||||
|
||||
void applyPower();
|
||||
|
||||
public:
|
||||
MotorController(int pinIA, int pinIB);
|
||||
void set(int power);
|
||||
void stop();
|
||||
void maximum();
|
||||
void inc();
|
||||
void dec();
|
||||
int getPower() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
0
include/drivers/PassiveBuzzerController.h
Normal file
0
include/drivers/PassiveBuzzerController.h
Normal file
35
include/drivers/PhotoresistorController.h
Normal file
35
include/drivers/PhotoresistorController.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef PHOTORESISTOR_CONTROLLER_H
|
||||
#define PHOTORESISTOR_CONTROLLER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#define DEFAULT_MIN_READ_INTERVAL 50
|
||||
#define DEFAULT_SAMPLES 3
|
||||
|
||||
class PhotoresistorController {
|
||||
private:
|
||||
uint8_t _pin;
|
||||
unsigned long _lastReadTime;
|
||||
unsigned long _minReadInterval;
|
||||
int _lastRawValue;
|
||||
int _lastPercentValue;
|
||||
bool _lastReadSuccess;
|
||||
uint8_t _numSamples;
|
||||
int _maxValue;
|
||||
int _minValue;
|
||||
|
||||
public:
|
||||
PhotoresistorController(uint8_t pin, int minValue = 0, int maxValue = 1023);
|
||||
void begin();
|
||||
bool read();
|
||||
int getRawValue();
|
||||
int getPercentValue();
|
||||
void calibrate(int minValue, int maxValue);
|
||||
void autoCalibrateDark();
|
||||
void autoCalibrateBright();
|
||||
bool isLastReadSuccessful() const;
|
||||
void setMinReadInterval(unsigned long interval);
|
||||
void setNumSamples(uint8_t samples);
|
||||
};
|
||||
|
||||
#endif
|
||||
0
include/drivers/RGBLEDController.h
Normal file
0
include/drivers/RGBLEDController.h
Normal file
38
include/drivers/RelayController.h
Normal file
38
include/drivers/RelayController.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef RELAY_CONTROLLER_H
|
||||
#define RELAY_CONTROLLER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class RelayController {
|
||||
private:
|
||||
const int _relayPin;
|
||||
bool _isConnected;
|
||||
|
||||
public:
|
||||
RelayController(int relayPin) :
|
||||
_relayPin(relayPin),
|
||||
_isConnected(false) {
|
||||
pinMode(_relayPin, OUTPUT);
|
||||
disconnect();
|
||||
}
|
||||
|
||||
void connect() {
|
||||
digitalWrite(_relayPin, LOW);
|
||||
_isConnected = true;
|
||||
}
|
||||
|
||||
void disconnect() {
|
||||
digitalWrite(_relayPin, HIGH);
|
||||
_isConnected = false;
|
||||
}
|
||||
|
||||
bool isConnected() const {
|
||||
return _isConnected;
|
||||
}
|
||||
|
||||
int getPin() const {
|
||||
return _relayPin;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
54
include/drivers/ThermistorController.h
Normal file
54
include/drivers/ThermistorController.h
Normal file
@@ -0,0 +1,54 @@
|
||||
#ifndef THERMISTOR_CONTROLLER_H
|
||||
#define THERMISTOR_CONTROLLER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
class ThermistorController {
|
||||
private:
|
||||
const int _thermistorPin;
|
||||
const float _seriesResistor;
|
||||
const float _bParameter;
|
||||
const float _nominalTemp;
|
||||
|
||||
static const int _bufferSize = 10;
|
||||
float _rawReadings[_bufferSize];
|
||||
int _bufferIndex;
|
||||
bool _bufferFilled;
|
||||
|
||||
float _filteredRaw;
|
||||
float _smoothedRaw;
|
||||
float _resistance;
|
||||
float _temperatureC;
|
||||
|
||||
const float _weights[_bufferSize] = {0.05, 0.05, 0.05, 0.05, 0.1, 0.1, 0.1, 0.15, 0.15, 0.2};
|
||||
|
||||
const float _minTemp;
|
||||
const float _maxTemp;
|
||||
|
||||
float applySaltPepperFilter();
|
||||
float applyWeightedMovingAverage();
|
||||
float calculateResistance(float adcValue);
|
||||
float calculateTemperature(float resistance);
|
||||
float applySaturation(float value, float min, float max);
|
||||
|
||||
public:
|
||||
ThermistorController(
|
||||
int thermistorPin,
|
||||
float seriesResistor = 10000.0,
|
||||
float bParameter = 3435.0,
|
||||
float nominalTemp = 25.0,
|
||||
float minTemp = -55.0,
|
||||
float maxTemp = 125.0
|
||||
);
|
||||
|
||||
void update();
|
||||
|
||||
float getRawValue() const;
|
||||
float getFilteredRaw() const;
|
||||
float getSmoothedRaw() const;
|
||||
float getResistance() const;
|
||||
float getTemperatureC() const;
|
||||
float getTemperatureF() const;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user