-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create modules skeleton for new app structure (#382)
* Add modules and main.cpp skeleton * Fix typos
- Loading branch information
1 parent
49f90e2
commit acd0b4d
Showing
9 changed files
with
102 additions
and
6 deletions.
There are no files selected for viewing
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,9 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
#include "Module.h" | ||
|
||
std::vector<Module*> gModules = { | ||
// put modules here | ||
}; |
Empty file.
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,10 @@ | ||
#pragma once | ||
|
||
class Module { | ||
public: | ||
virtual void periodic_10s(void) = 0; | ||
virtual void periodic_1s(void) = 0; | ||
virtual void periodic_100ms(void) = 0; | ||
virtual void periodic_10ms(void) = 0; | ||
virtual void periodic_1ms(void) = 0; | ||
}; |
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,59 @@ | ||
#include "AppConfig.h" | ||
#include "mbed.h" | ||
|
||
Thread periodic_10s_thread(osPriorityNormal1); | ||
Thread periodic_1s_thread(osPriorityNormal2); | ||
Thread periodic_100ms_thread(osPriorityNormal3); | ||
Thread periodic_10ms_thread(osPriorityNormal4); | ||
Thread periodic_1ms_thread(osPriorityNormal5); | ||
|
||
void periodic_10s(void) { | ||
auto startTime = Kernel::Clock::now(); | ||
for (Module* module : gModules) { | ||
module->periodic_10s(); | ||
} | ||
ThisThread::sleep_until(startTime + 10s); | ||
} | ||
|
||
void periodic_1s(void) { | ||
auto startTime = Kernel::Clock::now(); | ||
for (Module* module : gModules) { | ||
module->periodic_1s(); | ||
} | ||
ThisThread::sleep_until(startTime + 1s); | ||
} | ||
|
||
void periodic_100ms(void) { | ||
auto startTime = Kernel::Clock::now(); | ||
for (Module* module : gModules) { | ||
module->periodic_100ms(); | ||
} | ||
ThisThread::sleep_until(startTime + 100ms); | ||
} | ||
|
||
void periodic_10ms(void) { | ||
auto startTime = Kernel::Clock::now(); | ||
for (Module* module : gModules) { | ||
module->periodic_10ms(); | ||
} | ||
ThisThread::sleep_until(startTime + 10ms); | ||
} | ||
|
||
void periodic_1ms(void) { | ||
auto startTime = Kernel::Clock::now(); | ||
for (Module* module : gModules) { | ||
module->periodic_1ms(); | ||
} | ||
ThisThread::sleep_until(startTime + 1ms); | ||
} | ||
|
||
int main() { | ||
periodic_1ms_thread.start(periodic_1ms); | ||
periodic_10ms_thread.start(periodic_10ms); | ||
periodic_100ms_thread.start(periodic_100ms); | ||
periodic_1s_thread.start(periodic_1s); | ||
periodic_10s_thread.start(periodic_10s); | ||
|
||
while (true) { | ||
} | ||
} |
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,9 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
#include "Module.h" | ||
|
||
std::vector<Module*> gModules = { | ||
// put modules here | ||
}; |
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,9 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
|
||
#include "Module.h" | ||
|
||
std::vector<Module*> gModules = { | ||
// put modules here | ||
}; |