Skip to content

Commit

Permalink
Fixed service iteration & added service toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmicro committed May 20, 2021
1 parent 84b2ca6 commit f94e8ef
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
14 changes: 12 additions & 2 deletions include/osw_service.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#ifndef OSW_SERVICE_H
#define OSW_SERVICE_H
#include <osw_app.h>
#include <osw_app.h>

typedef OswApp OswServiceTask;
class OswServiceTask : public OswApp {
public:
OswServiceTask() : OswApp() {}
virtual void setup(OswHal* hal);
bool isRunning();
virtual void stop(OswHal* hal);
virtual ~OswServiceTask(){};

private:
bool taskEnabled = false;
};
#endif
1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ void setup() {
xTaskCreatePinnedToCore(core2Worker, "core2Worker", 1000 /*stack*/, NULL /*input*/, 0 /*prio*/,
&Core2WorkerTask /*handle*/, 0);

OswServiceManager &serviceManager = OswServiceManager::getInstance();
mainAppSwitcher->setup(hal);
displayTimeout = OswConfigAllKeys::settingDisplayTimeout.get();
}
Expand Down
10 changes: 10 additions & 0 deletions src/osw_service.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "osw_service.h"

void OswServiceTask::setup(OswHal* hal) {
this->taskEnabled = true;
}
void OswServiceTask::stop(OswHal* hal) {
this->taskEnabled = false;
}

bool OswServiceTask::isRunning() { return this->taskEnabled; }
11 changes: 5 additions & 6 deletions src/services/OswServiceManager.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#include "./services/OswServiceManager.h"

#include "./services/OswServiceTasks.h"

void OswServiceManager::setup(OswHal *hal) {
for (unsigned char i = 0; i < oswServiceTasksCount; i++)
return oswServiceTasks[i]->setup(hal);
for (unsigned char i = 0; i < oswServiceTasksCount; i++) oswServiceTasks[i]->setup(hal);
}

void OswServiceManager::loop(OswHal *hal) {
for (unsigned char i = 0; i < oswServiceTasksCount; i++)
return oswServiceTasks[i]->loop(hal);
for (unsigned char i = 0; i < oswServiceTasksCount; i++)
if (oswServiceTasks[i]->isRunning()) oswServiceTasks[i]->loop(hal);
}

void OswServiceManager::stop(OswHal *hal) {
for (unsigned char i = 0; i < oswServiceTasksCount; i++)
return oswServiceTasks[i]->stop(hal);
for (unsigned char i = 0; i < oswServiceTasksCount; i++) oswServiceTasks[i]->stop(hal);
}
3 changes: 2 additions & 1 deletion src/services/OswServiceTaskBLECompanion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class NotificationCallback: public BLECharacteristicCallbacks {
};

void OswServiceTaskBLECompanion::setup(OswHal* hal) {
OswServiceTask::setup(hal);
BLEDevice::init(BLE_DEVICE_NAME);
bleServer = BLEDevice::createServer();
notificationService = bleServer->createService(NOTIFICATION_SERVICE_UID);
Expand Down Expand Up @@ -85,5 +86,5 @@ void OswServiceTaskBLECompanion::loop(OswHal* hal) {
}

void OswServiceTaskBLECompanion::stop(OswHal* hal) {

OswServiceTask::stop(hal);
}
2 changes: 2 additions & 0 deletions src/services/OswServiceTaskExample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <time.h>

void OswServiceTaskExample::setup(OswHal* hal) {
OswServiceTask::setup(hal);
Serial.println(String(__FILE__) + "->" + __FUNCTION__ + "()");
}

Expand All @@ -15,5 +16,6 @@ void OswServiceTaskExample::loop(OswHal* hal) {
}

void OswServiceTaskExample::stop(OswHal* hal) {
OswServiceTask::stop(hal);
Serial.println(String(__FILE__) + "->" + __FUNCTION__ + "()");
}

0 comments on commit f94e8ef

Please sign in to comment.