Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5 from Koen-Leaphy/master
Browse files Browse the repository at this point in the history
Add new Compass Sensor
  • Loading branch information
paulsiersma authored Mar 25, 2023
2 parents 926f007 + 4936e1a commit fabbe93
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
6 changes: 3 additions & 3 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name=Leaphy Extra Extension
version=0.0.13
version=0.0.14
author=Leaphy Robotics
maintainer=Leaphy Robotics <[email protected]>
sentence=Provides Extra functionality to Leaphy robots
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
44 changes: 44 additions & 0 deletions src/LSM303AGR.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "LSM303AGR.h"

#define _ADDRESS_MAG 0x1E //!< Default address
#include <Adafruit_BusIO_Register.h>
#include <Adafruit_I2CDevice.h>
#include <Adafruit_SPIDevice.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>

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();
}
25 changes: 25 additions & 0 deletions src/LSM303AGR.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef LSM303AGR_H
#define LSM303AGR_H
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LIS2MDL.h>

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

0 comments on commit fabbe93

Please sign in to comment.