Maybe now it less confusing

hardware
EmaMaker 2019-10-21 08:57:58 +02:00
parent b726d39470
commit da20da5e0a
12 changed files with 86 additions and 68 deletions

10
.vscode/settings.json vendored
View File

@ -11,6 +11,14 @@
"functional": "cpp", "functional": "cpp",
"tuple": "cpp", "tuple": "cpp",
"type_traits": "cpp", "type_traits": "cpp",
"utility": "cpp" "utility": "cpp",
"hash_map": "cpp",
"deque": "cpp",
"list": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"string_view": "cpp",
"initializer_list": "cpp"
} }
} }

View File

@ -1,16 +1,31 @@
#include "Wire.h" #include "Wire.h"
#include "Arduino.h" #include "Arduino.h"
#include "HardwareSerial.h" #include "HardwareSerial.h"
#include "vars.h"
class DataSource { class DataSource {
public: public:
float value; DataSource();
DataSource(HardwareSerial, int);
DataSource(TwoWire);
DataSource(int, bool);
public: public:
void update(); void update();
void test(); void test();
void readSensor();
void postProcess(); void postProcess();
int getValue(); int getValue();
public:
HardwareSerial* ser;
TwoWire* i2c;
int pin;
int protocol;
int value;
}; };

View File

@ -1,11 +0,0 @@
#include "data_source.h"
class DataSourceAnalog : public DataSource{
public:
DataSourceAnalog(int);
public:
int pin;
};

View File

@ -1,15 +1,15 @@
#include "data_source_i2c.h" #include "data_source.h"
#include <Adafruit_BNO055.h> #include <Adafruit_BNO055.h>
#include <Arduino.h> #include <Arduino.h>
class DataSourceBN0O55 : public DataSourceI2C{ class DataSourceBNO055 : public DataSource{
public: public:
DataSourceBN0O55(); DataSourceBNO055();
void update(); void readSensor();
void postProcess();
public: public:
int value;
Adafruit_BNO055 bno; Adafruit_BNO055 bno;
}; };

View File

@ -1,14 +0,0 @@
#include "data_source.h"
//i2c_t3
class DataSourceI2C : public DataSource{
public:
DataSourceI2C();
DataSourceI2C(TwoWire);
void update();
public:
TwoWire i2c;
};

View File

@ -1,13 +0,0 @@
#include "data_source.h"
class DataSourceRXTX : public DataSource{
public:
DataSourceRXTX(HardwareSerial);
void update();
public:
HardwareSerial ser;
};

1
include/vars.h Normal file
View File

@ -0,0 +1 @@
#define DEBUG_PRINT Serial

View File

@ -1,5 +1,48 @@
#include "data_source.h" #include "data_source.h"
DataSource::DataSource(void){
protocol = 0;
}
DataSource::DataSource(TwoWire i2c_){
i2c = &(i2c_);
protocol = 1;
i2c->begin();
}
DataSource::DataSource(HardwareSerial ser_, int baud){
ser = &(ser_);
protocol = 2;
ser->begin(baud);
}
DataSource::DataSource(int pin_, bool analog){
pin = pin_;
if(analog) protocol = 3;
else protocol = 4;
}
int DataSource::getValue(){ int DataSource::getValue(){
return value; return value;
} }
void DataSource::update(){
readSensor();
postProcess();
}
void DataSource::readSensor(){
if(protocol == 1) value = i2c->read();
else if(protocol == 2) while(ser->available() > 0) value = ser->read();
else if(protocol == 3) analogRead(pin);
else if(protocol == 4) digitalRead(pin);
}
void DataSource::test(){
update();
DEBUG_PRINT.println(value);
}

View File

@ -1,15 +1,15 @@
#include "data_source_bno055.h" #include "data_source_bno055.h"
DataSourceBN0O55::DataSourceBN0O55(){ DataSourceBNO055::DataSourceBNO055(){
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
bno.setExtCrystalUse(true); bno.setExtCrystalUse(true);
} }
void DataSourceBN0O55::update(){ void DataSourceBNO055::readSensor(){
imu::Vector<3> euler = bno.getVector(Adafruit_BNO055::VECTOR_EULER); imu::Vector<3> euler = bno.getVector(Adafruit_BNO055::VECTOR_EULER);
if (euler.x() != value) { if (euler.x() != value) {
value = euler.x(); value = euler.x();
} }
return;
} }

View File

@ -1,5 +0,0 @@
#include "data_source_i2c.h"
void DataSourceI2C::update(){
value = i2c.read();
}

View File

@ -1,7 +0,0 @@
#include "data_source_rxtx.h"
void DataSourceRXTX::update(){
while(ser.available() > 0) value = ser.read();
postProcess();
}

View File

@ -1,9 +1,10 @@
#include <Arduino.h> #include <Arduino.h>
#include "vars.h"
// #include <imu_class/imu.cpp> // #include <imu_class/imu.cpp>
//cyao c: //cyao c:
void setup() { void setup() {
Serial.begin(9600); DEBUG_PRINT.begin(9600);
} }
void loop() { void loop() {