Using enums instead of ints for transmission protocols

code_midgen
u-siri-ous 2019-11-18 15:07:46 +01:00
parent 46fe1ca4a3
commit 9547cf935b
7 changed files with 24 additions and 23 deletions

View File

@ -9,8 +9,8 @@ class DataSource {
public: public:
DataSource(); DataSource();
DataSource(usb_serial_class, int); DataSource(HardwareSerial*, int);
DataSource(TwoWire); DataSource(TwoWire*);
DataSource(int, bool); DataSource(int, bool);
public: public:
@ -23,17 +23,18 @@ class DataSource {
public: public:
enum Protocols { enum Protocols {
P_NULL,
P_I2C, P_I2C,
P_RXTX, P_RXTX,
P_APIN, P_APIN,
P_PIND P_DPIN
}; };
usb_serial_class* ser; HardwareSerial* ser;
TwoWire* i2c; TwoWire* i2c;
Protocols protocol;
int pin; int pin;
int protocol;
int value; int value;

View File

@ -3,7 +3,7 @@
class DataSourceBall : public DataSource{ class DataSourceBall : public DataSource{
public: public:
DataSourceBall(usb_serial_class ser, int baud); DataSourceBall(HardwareSerial* ser, int baud);
void postProcess() override; void postProcess() override;
void test() override; void test() override;
int angle,distance; int angle,distance;

View File

@ -1,29 +1,28 @@
#include "data_source.h" #include "data_source.h"
DataSource::DataSource(void){ DataSource::DataSource(void){
protocol = 0; protocol = P_NULL;
} }
DataSource::DataSource(TwoWire i2c_){ DataSource::DataSource(TwoWire* i2c_){
protocol = P_I2C;
this->i2c = &(i2c_); this->i2c = i2c_;
protocol = 1;
i2c->begin(); i2c->begin();
} }
DataSource::DataSource(usb_serial_class ser_, int baud){ DataSource::DataSource(HardwareSerial* ser_, int baud){
this->ser = &(ser_); protocol = P_RXTX;
protocol = 2; this->ser = ser_;
ser->begin(baud); ser->begin(baud);
} }
DataSource::DataSource(int pin_, bool analog){ DataSource::DataSource(int pin_, bool analog){
this->pin = pin_; this->pin = pin_;
if(analog) protocol = 3; if(analog) protocol = P_APIN;
else protocol = 4; else {
protocol = P_DPIN;
digitalWrite(pin, OUTPUT);
}
} }
int DataSource::getValue(){ int DataSource::getValue(){

View File

@ -1,7 +1,7 @@
#include "data_source_ball.h" #include "data_source_ball.h"
#include "vars.h" #include "vars.h"
DataSourceBall::DataSourceBall(usb_serial_class ser_, int baud) : DataSource(ser_, baud) { DataSourceBall::DataSourceBall(HardwareSerial* ser_, int baud) : DataSource(ser_, baud) {
} }
void DataSourceBall :: postProcess(){ void DataSourceBall :: postProcess(){

View File

@ -3,7 +3,7 @@
//bool loaded = false; //bool loaded = false;
DataSourceBNO055::DataSourceBNO055(){ DataSourceBNO055::DataSourceBNO055(){
// protocol = Protocols.P_I2C; protocol = P_I2C;
bno = Adafruit_BNO055(); bno = Adafruit_BNO055();
bno.begin(bno.OPERATION_MODE_IMUPLUS); //Posizione impostata a P7 alle righe 105,107 di Adafruit_BNO55.cpp bno.begin(bno.OPERATION_MODE_IMUPLUS); //Posizione impostata a P7 alle righe 105,107 di Adafruit_BNO55.cpp

View File

@ -17,5 +17,6 @@ void loop() {
updateSensors(); updateSensors();
//should recenter using predefined values //should recenter using predefined values
// drive->drive(0, 0, 0); // drive->drive(0, 0, 0);
ball->test(); compass->test();
delay(100);
} }

View File

@ -4,7 +4,7 @@
void initSensors(){ void initSensors(){
compass = new DataSourceBNO055(); compass = new DataSourceBNO055();
drive = new DriveController(new Motor(12, 11, 2, 45),new Motor(25, 24, 5, 135), new Motor(27, 26, 6, 225), new Motor(21, 22, 23, 315)); drive = new DriveController(new Motor(12, 11, 2, 45),new Motor(25, 24, 5, 135), new Motor(27, 26, 6, 225), new Motor(21, 22, 23, 315));
ball = new DataSourceBall(Serial, 57600); ball = new DataSourceBall(&Serial4, 57600);
} }
void updateSensors(){ void updateSensors(){