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:
DataSource();
DataSource(usb_serial_class, int);
DataSource(TwoWire);
DataSource(HardwareSerial*, int);
DataSource(TwoWire*);
DataSource(int, bool);
public:
@ -23,17 +23,18 @@ class DataSource {
public:
enum Protocols {
P_NULL,
P_I2C,
P_RXTX,
P_APIN,
P_PIND
P_DPIN
};
usb_serial_class* ser;
HardwareSerial* ser;
TwoWire* i2c;
Protocols protocol;
int pin;
int protocol;
int value;

View File

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

View File

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

View File

@ -1,7 +1,7 @@
#include "data_source_ball.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(){

View File

@ -3,7 +3,7 @@
//bool loaded = false;
DataSourceBNO055::DataSourceBNO055(){
// protocol = Protocols.P_I2C;
protocol = P_I2C;
bno = Adafruit_BNO055();
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();
//should recenter using predefined values
// drive->drive(0, 0, 0);
ball->test();
compass->test();
delay(100);
}

View File

@ -4,7 +4,7 @@
void initSensors(){
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));
ball = new DataSourceBall(Serial, 57600);
ball = new DataSourceBall(&Serial4, 57600);
}
void updateSensors(){