-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: rewrite basesensor to superclass
- Loading branch information
Showing
17 changed files
with
303 additions
and
454 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 7 additions & 15 deletions
22
senseBox-bike-atrai-v2/src/sensors/AccelerationSensor/AccelerationSensor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "BaseSensor.h" | ||
|
||
BaseSensor::BaseSensor(const char *taskName, uint32_t taskStackSize, uint32_t taskDelay) | ||
: activeSubscription(false), sendBLE(false), taskStackSize(taskStackSize), taskDelay(taskDelay) {} | ||
|
||
void BaseSensor::begin() | ||
{ | ||
initSensor(); | ||
delay(1000); | ||
xTaskCreate(sensorTask, taskName, taskStackSize, this, 1, NULL); | ||
} | ||
|
||
void BaseSensor::subscribe(std::function<void(std::vector<float>)> callback) | ||
{ | ||
this->measurementCallback = callback; | ||
} | ||
|
||
void BaseSensor::startSubscription() | ||
{ | ||
activeSubscription = true; | ||
} | ||
|
||
void BaseSensor::stopSubscription() | ||
{ | ||
activeSubscription = false; | ||
} | ||
|
||
void BaseSensor::startBLE() | ||
{ | ||
sendBLE = true; | ||
} | ||
|
||
void BaseSensor::stopBLE() | ||
{ | ||
sendBLE = false; | ||
} | ||
|
||
void BaseSensor::sensorTask(void *pvParameters) | ||
{ | ||
BaseSensor *sensor = static_cast<BaseSensor *>(pvParameters); | ||
while (true) | ||
{ | ||
if (sensor->activeSubscription) | ||
{ | ||
sensor->readSensorData(); | ||
} | ||
vTaskDelay(pdMS_TO_TICKS(sensor->taskDelay)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef BASESENSOR_H | ||
#define BASESENSOR_H | ||
|
||
#include <Arduino.h> | ||
#include <functional> | ||
#include <vector> | ||
#include "../ble/BLEModule.h" | ||
|
||
class BaseSensor | ||
{ | ||
public: | ||
BaseSensor(const char *taskName, uint32_t taskStackSize = 8192, uint32_t taskDelay = 1000); | ||
|
||
void begin(); | ||
void subscribe(std::function<void(std::vector<float>)> callback); | ||
void startSubscription(); | ||
void stopSubscription(); | ||
void startBLE(); | ||
void stopBLE(); | ||
|
||
protected: | ||
virtual void initSensor() = 0; | ||
virtual void readSensorData() = 0; | ||
static void sensorTask(void *pvParameters); | ||
bool activeSubscription; | ||
bool sendBLE; | ||
std::function<void(std::vector<float>)> measurementCallback; | ||
|
||
private: | ||
const char *taskName; | ||
uint32_t taskStackSize; | ||
uint32_t taskDelay; | ||
}; | ||
|
||
#endif // BASESENSOR_H |
Oops, something went wrong.