Skip to content
Snippets Groups Projects
Commit c75f4917 authored by jdkruege's avatar jdkruege
Browse files

Changed LSM9DS0 to follow a singleton pattern,.

parent f7ea215a
No related branches found
No related tags found
No related merge requests found
/*
* @author Branden Sammons
* @author Branden Sammons & Jonathan Krueger
*/
#include "LSM9DS0.h"
bool LSM9DS0::initialized = false;
/**
* Constructor for the LSM9DS0 class.
* Sets up the right SPI channels, frequency, mode, and registers.
*/
LSM9DS0::LSM9DS0() {
// set up the mraa library
mraa_init();
......@@ -28,9 +29,21 @@ LSM9DS0::LSM9DS0() {
// set up registers
// place holder
}
LSM9DS0 LSM9DS0::instance()
{
if (!initialized)
{
myInstance = LSM9DS0();
initialized = true;
}
return myInstance;
}
/**
* Deconstructor for the LSM9DS0 class.
* Realeases the SPI channels.
......
......@@ -5,18 +5,27 @@
#include "mraa.h"
#include <unistd.h>
#include <stdint.h>
#include "Service.h"
class LSM9DS0 {
class LSM9DS0{
public:
LSM9DS0();
~LSM9DS0();
static LSM9DS0 instance();
void run();
uint8_t read_G(uint8_t address);
void write_G(uint8_t address, uint8_t data);
uint8_t read_XM(uint8_t address);
void write_XM(uint8_t address, uint8_t data);
private:
static bool initialized;
static LSM9DS0 myInstance;
LSM9DS0();
mraa_spi_context SPI_1;
mraa_spi_context SPI_2;
uint8_t read(mraa_spi_context SPI, uint8_t address);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment