-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add support for sensor polling at a specific frequency #38
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
#include "sensor.h" | ||
|
||
#include "utilis.h" | ||
// Constructor | ||
spartan::Sensor::Sensor(int busID, int instance) | ||
: m_busID(busID), m_status(STATUS_OFF), m_instance(instance) {} | ||
|
||
unsigned long spartan::Sensor::poll_correct_frequency() { | ||
if (getTimeMillis() > last_polled + frequency) { | ||
last_polled = getTimeMillis(); | ||
} | ||
} | ||
Comment on lines
+7
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on what is shown here, I presume this method is meant to provide the This is good! This is needed in some fashion in order to implement the functionality we desire: polling at different frequencies. Currently, however, there's a few problems:
|
||
|
||
// Debug output | ||
void spartan::Sensor::printEscapedValues(bool normalize) const { | ||
int lines = printValues(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ namespace spartan { | |
// Standard sensor implementation | ||
virtual int powerOn() = 0; | ||
virtual int powerOff() = 0; | ||
virtual long last_polled() = 0; | ||
virtual unsigned long poll_correct_frequency(); | ||
Comment on lines
+23
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a styling/lint issue: try to keep the indentation the same if possible! |
||
virtual int poll(MasterDataPacket &dp) = 0; | ||
|
||
// Debug options | ||
|
@@ -29,6 +31,7 @@ namespace spartan { | |
// Data getters | ||
int getBusID() const; | ||
int getInstance() const; | ||
const long frequency = 1000; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a styling/lint issue: try to keep the indentation the same if possible! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Specifying this variable that represents the frequency/period of polling should likely not be something we want to be in the In other words, this is something that should only be handled by the internal methods of the Here's my quick thoughts:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a particular reason why we have our "default" value as When making some of the other changes I mentioned in this review, remember that we want our |
||
// Return status (operate with interfaced constants described in globals.h) | ||
virtual int getStatus() const; | ||
|
||
|
@@ -40,3 +43,4 @@ namespace spartan { | |
} // namespace spartan | ||
|
||
#endif // SENSOR_H_INCLUDED | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a styling/lint issue: adding a newline between the include directives and the rest of the source code helps keep the file more readable.