Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed Sensor Constructors to allow Variable Polling Frequency #39

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Software/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ int main() {
std::array<spartan::Sensor*, 1> sensors;

// TODO: Initialize Sensors
sensors[0] = new spartan::LSM6DS33(1, 0);
sensors[0] = new spartan::LSM6DS33(1, 0, 1000);

// TODO: Initialize DataPackets
spartan::MasterDataPacket mdp;
Expand Down
2 changes: 1 addition & 1 deletion Software/spartan/src/sensors/ads1115.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace spartan
{
class ADS1115 : public Sensor {
public:
ADS1115(int bus, uint8_t address);
ADS1115(int bus, uint8_t address, int polling_frequency);
virtual bool pollData(spartan::MasterDataPacket &dp);
virtual int printValues() const;
};
Expand Down
8 changes: 4 additions & 4 deletions Software/spartan/src/sensors/lsm6ds33.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

// Constructors

spartan::LSM6DS33::LSM6DS33(int busID, int lsm6ID, spartan::LSM6DS33::lsm6Settings settings)
: Sensor(busID, lsm6ID), m_settings(settings), m_i2c(busID, true) { // raw=true, disable pinmapper for board
spartan::LSM6DS33::LSM6DS33(int busID, int lsm6ID, int polling_frequency, spartan::LSM6DS33::lsm6Settings settings)
: Sensor(busID, lsm6ID, polling_frequency), m_settings(settings), m_i2c(busID, true) { // raw=true, disable pinmapper for board
if (lsm6ID)
lsm6Address = lsm6ds33::HIGH_ADDRESS;
else
lsm6Address = lsm6ds33::LOW_ADDRESS;
setMultipliers();
}

spartan::LSM6DS33::LSM6DS33(int busID, int lsm6ID)
: Sensor(busID, lsm6ID), m_i2c(busID, true) {
spartan::LSM6DS33::LSM6DS33(int busID, int lsm6ID, int polling_frequency)
: Sensor(busID, lsm6ID, polling_frequency), m_i2c(busID, true) {
if (lsm6ID)
lsm6Address = lsm6ds33::HIGH_ADDRESS;
else
Expand Down
4 changes: 2 additions & 2 deletions Software/spartan/src/sensors/lsm6ds33.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ namespace spartan {
uint8_t lsm6Address;

// Note: busID can be either 0 or 1 (can only connect 2 lsm6ds33 modules)
LSM6DS33(int busID, int lsm6ID, lsm6Settings settings);
LSM6DS33(int busID, int lsm6ID);
LSM6DS33(int busID, int lsm6ID, int polling_frequency, lsm6Settings settings);
LSM6DS33(int busID, int lsm6IDm, int polling_frequency);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why we changed the second parameter to lsm6ID to lsm6IDm? This probably should be producing a compilation error.


virtual int powerOn();
virtual int powerOff();
Expand Down
5 changes: 3 additions & 2 deletions Software/spartan/src/sensors/sensor.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "sensor.h"

// Constructor
spartan::Sensor::Sensor(int busID, int instance)
: m_busID(busID), m_status(STATUS_OFF), m_instance(instance) {}
spartan::Sensor::Sensor(int busID, int instance, int pollingFrequency)
: m_busID(busID), m_status(STATUS_OFF), m_instance(instance), m_polling_frequency(pollingFrequency) {}

// Debug output
void spartan::Sensor::printEscapedValues(bool normalize) const {
Expand All @@ -18,3 +18,4 @@ void spartan::Sensor::printEscapedValues(bool normalize) const {
int spartan::Sensor::getBusID() const { return m_busID; }
int spartan::Sensor::getStatus() const { return m_status; }
int spartan::Sensor::getInstance() const { return m_instance; }
int spartan::Sensor::getInstance() const { return m_polling_frequency;}
9 changes: 6 additions & 3 deletions Software/spartan/src/sensors/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace spartan {
class Sensor {
public:
// Constructor that takes in pin number that sensor is connected to; this pin number would be used for all
// member functions
Sensor(int busID, int instance);
// member functions, as well as instance number and polling frequency of the sensor
Sensor(int busID, int instance, int polling_frequency);

// Identification, standard max length is 15 characters
virtual const char * name() const = 0;
Expand All @@ -21,21 +21,24 @@ namespace spartan {
virtual int powerOn() = 0;
virtual int powerOff() = 0;
virtual int poll(MasterDataPacket &dp) = 0;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unneeded indentation to keep proper style.

// Debug options
virtual int printValues() const = 0;
void printEscapedValues(bool normalize) const;

// Data getters
int getBusID() const;
int getInstance() const;
int getPollingfrequency() const;

// Return status (operate with interfaced constants described in globals.h)
virtual int getStatus() const;

protected:
int m_status;
int m_busID;
int m_instance; // support for multiple sensors of same type
int m_polling_frequency;
};
} // namespace spartan

Expand Down