From 358965a855a6bf59d6674442db8649b6073973d5 Mon Sep 17 00:00:00 2001 From: Koen <124458132+Koen-Leaphy@users.noreply.github.com> Date: Sat, 4 Feb 2023 20:38:26 +0100 Subject: [PATCH 1/7] Make .h file --- SERIAL_BLUETOOTH.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 SERIAL_BLUETOOTH.h diff --git a/SERIAL_BLUETOOTH.h b/SERIAL_BLUETOOTH.h new file mode 100644 index 0000000..c823a31 --- /dev/null +++ b/SERIAL_BLUETOOTH.h @@ -0,0 +1,15 @@ +#ifndef SERIAL_BLUETOOTH_H +#define SERIAL_BLUETOOTH_H + +// default module is HC-05 + +class SERIALBLUETOOTH { + public: + OLEDDISPLAY(int TX, int RX, bool inverse_logic); + bool begin(); + String recieve(); + void send(); + int available(); +} + +#endif From c6eed0e061db6178e525682b8c18b771c999e1ee Mon Sep 17 00:00:00 2001 From: Koen <124458132+Koen-Leaphy@users.noreply.github.com> Date: Sat, 4 Feb 2023 19:50:33 +0000 Subject: [PATCH 2/7] Add bluetooth code, testing now Co-authored-by: Koen --- SERIAL_BLUETOOTH.h | 15 --------------- src/SERIAL_BLUETOOTH.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/SERIAL_BLUETOOTH.h | 16 ++++++++++++++++ 3 files changed, 52 insertions(+), 15 deletions(-) delete mode 100644 SERIAL_BLUETOOTH.h create mode 100644 src/SERIAL_BLUETOOTH.cpp create mode 100644 src/SERIAL_BLUETOOTH.h diff --git a/SERIAL_BLUETOOTH.h b/SERIAL_BLUETOOTH.h deleted file mode 100644 index c823a31..0000000 --- a/SERIAL_BLUETOOTH.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef SERIAL_BLUETOOTH_H -#define SERIAL_BLUETOOTH_H - -// default module is HC-05 - -class SERIALBLUETOOTH { - public: - OLEDDISPLAY(int TX, int RX, bool inverse_logic); - bool begin(); - String recieve(); - void send(); - int available(); -} - -#endif diff --git a/src/SERIAL_BLUETOOTH.cpp b/src/SERIAL_BLUETOOTH.cpp new file mode 100644 index 0000000..15e409b --- /dev/null +++ b/src/SERIAL_BLUETOOTH.cpp @@ -0,0 +1,36 @@ +#include "SERIAL_BLUETOOTH.h" +#include + +// Constructor +SERIALBLUETOOTH::SERIALBLUETOOTH(int baudRate, int TX, int RX, bool inverse_logic) { + SoftwareSerial *ss = new SoftwareSerial(TX, RX, inverse_logic); + // set as private member + this->ss = ss; + ss->begin(baudRate); + +} + +SERIALBLUETOOTH::~SERIALBLUETOOTH() { + delete ss; +} + +int SERIALBLUETOOTH::available() { + return ss->available(); +} + +bool SERIALBLUETOOTH::begin(int baudRate) { + return ss->begin(baudRate); +} + +char SERIALBLUETOOTH::read() { + return ss->read(); +} + +char SERIALBLUETOOTH::readString() { + return ss->readString(); +} + +void SERIALBLUETOOTH::send(char c) { + ss->write(c); +} + diff --git a/src/SERIAL_BLUETOOTH.h b/src/SERIAL_BLUETOOTH.h new file mode 100644 index 0000000..1f2d389 --- /dev/null +++ b/src/SERIAL_BLUETOOTH.h @@ -0,0 +1,16 @@ +#ifndef SERIAL_BLUETOOTH_H +#define SERIAL_BLUETOOTH_H + +// default module is HC-05 + +class SERIALBLUETOOTH { + public: + SERIALBLUETOOTH(int baudRate, int TX, int RX, bool inverse_logic); + bool begin(int baudRate); + char read(); + char readString(); + void send(char c); + int available(); +} + +#endif From 805182b54a46d9f9460327c8a1bc38ba123731de Mon Sep 17 00:00:00 2001 From: Koen <124458132+Koen-Leaphy@users.noreply.github.com> Date: Mon, 6 Mar 2023 13:45:04 +0100 Subject: [PATCH 3/7] Add new Compass Sensor --- src/LSM303AGR.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/LSM303AGR.h | 25 +++++++++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 src/LSM303AGR.cpp create mode 100644 src/LSM303AGR.h diff --git a/src/LSM303AGR.cpp b/src/LSM303AGR.cpp new file mode 100644 index 0000000..ef172f0 --- /dev/null +++ b/src/LSM303AGR.cpp @@ -0,0 +1,44 @@ +#include "LSM303AGR.h" + +#define _ADDRESS_MAG 0x1E //!< Default address +#include +#include +#include +#include +#include + +CompassSensor::CompassSensor() { + CompassSensor::mag = Adafruit_LIS2MDL(); + // initiate the event + CompassSensor::mag.getEvent(&data); +} + +bool CompassSensor::begin(uint8_t i2c_addr = _ADDRESS_MAG, TwoWire *wire = &Wire) { + CompassSensor::mag.begin(i2c_addr = _ADDRESS_MAG, wire = &Wire); + + return true; +} + +bool CompassSensor::begin_SPI(uint8_t cs_pin, SPIClass *theSPI = &SPI) { + CompassSensor::mag.begin_SPI(cs_pin, theSPI); + + return true; +} + +bool CompassSensor::begin_SPI(int8_t cs_pin, int8_t sck_pin, int8_t miso_pin, int8_t mosi_pin) { + CompassSensor::mag.begin_SPI(cs_pin, sck_pin, miso_pin, mosi_pin); + + return true; +} + +lis2mdl_rate_t CompassSensor::getDataRate() { + return CompassSensor::mag.getDataRate(); +} + +void CompassSensor::setDataRate(lis2mdl_rate_t rate) { + CompassSensor::mag.setDataRate(rate); +} + +void CompassSensor::reset() { + CompassSensor::mag.reset(); +} \ No newline at end of file diff --git a/src/LSM303AGR.h b/src/LSM303AGR.h new file mode 100644 index 0000000..485c624 --- /dev/null +++ b/src/LSM303AGR.h @@ -0,0 +1,25 @@ +#ifndef LSM303AGR_H +#define LSM303AGR_H +#include +#include +#include + +class CompassSensor { + private: + Adafruit_LIS2MDL mag; + + + public: + sensors_event_t * data; + CompassSensor(); + bool begin(uint8_t i2c_addr = _ADDRESS_MAG, TwoWire *wire = &Wire); + bool begin_SPI(uint8_t cs_pin, SPIClass *theSPI = &SPI); + bool begin_SPI(int8_t cs_pin, int8_t sck_pin, int8_t miso_pin, + int8_t mosi_pin); + + lis2mdl_rate_t getDataRate(); + void setDataRate(lis2mdl_rate_t rate); + void reset(); +}; + +#endif From fb38142ee31619d911ac3a1045c72f8938ff0408 Mon Sep 17 00:00:00 2001 From: Koen <124458132+Koen-Leaphy@users.noreply.github.com> Date: Mon, 6 Mar 2023 13:46:31 +0100 Subject: [PATCH 4/7] Delete SERIAL_BLUETOOTH.cpp --- src/SERIAL_BLUETOOTH.cpp | 36 ------------------------------------ 1 file changed, 36 deletions(-) delete mode 100644 src/SERIAL_BLUETOOTH.cpp diff --git a/src/SERIAL_BLUETOOTH.cpp b/src/SERIAL_BLUETOOTH.cpp deleted file mode 100644 index 15e409b..0000000 --- a/src/SERIAL_BLUETOOTH.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "SERIAL_BLUETOOTH.h" -#include - -// Constructor -SERIALBLUETOOTH::SERIALBLUETOOTH(int baudRate, int TX, int RX, bool inverse_logic) { - SoftwareSerial *ss = new SoftwareSerial(TX, RX, inverse_logic); - // set as private member - this->ss = ss; - ss->begin(baudRate); - -} - -SERIALBLUETOOTH::~SERIALBLUETOOTH() { - delete ss; -} - -int SERIALBLUETOOTH::available() { - return ss->available(); -} - -bool SERIALBLUETOOTH::begin(int baudRate) { - return ss->begin(baudRate); -} - -char SERIALBLUETOOTH::read() { - return ss->read(); -} - -char SERIALBLUETOOTH::readString() { - return ss->readString(); -} - -void SERIALBLUETOOTH::send(char c) { - ss->write(c); -} - From e2d8bffa95828182d0d330bafcb2691be0b83abe Mon Sep 17 00:00:00 2001 From: Koen <124458132+Koen-Leaphy@users.noreply.github.com> Date: Mon, 6 Mar 2023 13:46:39 +0100 Subject: [PATCH 5/7] Delete SERIAL_BLUETOOTH.h --- src/SERIAL_BLUETOOTH.h | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 src/SERIAL_BLUETOOTH.h diff --git a/src/SERIAL_BLUETOOTH.h b/src/SERIAL_BLUETOOTH.h deleted file mode 100644 index 1f2d389..0000000 --- a/src/SERIAL_BLUETOOTH.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef SERIAL_BLUETOOTH_H -#define SERIAL_BLUETOOTH_H - -// default module is HC-05 - -class SERIALBLUETOOTH { - public: - SERIALBLUETOOTH(int baudRate, int TX, int RX, bool inverse_logic); - bool begin(int baudRate); - char read(); - char readString(); - void send(char c); - int available(); -} - -#endif From d41428145560c096959d509e6c06bcc175bfce7d Mon Sep 17 00:00:00 2001 From: Koen <124458132+Koen-Leaphy@users.noreply.github.com> Date: Fri, 17 Mar 2023 14:41:11 +0100 Subject: [PATCH 6/7] Library update --- library.properties | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library.properties b/library.properties index 3240ced..d5fa797 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Leaphy Extra Extension -version=0.0.13 +version=0.0.14 author=Leaphy Robotics maintainer=Leaphy Robotics sentence=Provides Extra functionality to Leaphy robots @@ -7,5 +7,5 @@ paragraph= category=Device Control url=https://github.com/leaphy-robotics/leaphy-extensions-extra architectures=avr -includes=Adafruit_NeoPixel.h,Adafruit_TCS34725.h,ledstrip.h,Leaphy_Extra.h,OLED_Display.h -depends=Adafruit SSD1306,Adafruit GFX Library +includes=Adafruit_NeoPixel.h,Adafruit_TCS34725.h,ledstrip.h,Leaphy_Extra.h,OLED_Display.h,LSM303AGR.h +depends=Adafruit SSD1306,Adafruit GFX Library,Adafruit LSM303 Accel,Adafruit LIS2MDL,Adafruit_BusIO_Register,Adafruit_I2CDevice,Adafruit_SPIDevice,Adafruit_Sensor,Wire From 4936e1a90caf4e5a82a2b3945d4c10ecbceed53a Mon Sep 17 00:00:00 2001 From: Koen <124458132+Koen-Leaphy@users.noreply.github.com> Date: Fri, 17 Mar 2023 14:56:28 +0100 Subject: [PATCH 7/7] Update library.properties --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index d5fa797..a34a7e5 100644 --- a/library.properties +++ b/library.properties @@ -8,4 +8,4 @@ category=Device Control url=https://github.com/leaphy-robotics/leaphy-extensions-extra architectures=avr includes=Adafruit_NeoPixel.h,Adafruit_TCS34725.h,ledstrip.h,Leaphy_Extra.h,OLED_Display.h,LSM303AGR.h -depends=Adafruit SSD1306,Adafruit GFX Library,Adafruit LSM303 Accel,Adafruit LIS2MDL,Adafruit_BusIO_Register,Adafruit_I2CDevice,Adafruit_SPIDevice,Adafruit_Sensor,Wire +depends=Adafruit SSD1306,Adafruit GFX Library,Adafruit LSM303 Accel,Adafruit LIS2MDL,Adafruit BusIO Register,Adafruit I2CDevice,Adafruit SPIDevice,Adafruit Sensor,Wire \ No newline at end of file