diff --git a/Arduios.ino b/Arduios.ino index 41f0f02..22fc178 100644 --- a/Arduios.ino +++ b/Arduios.ino @@ -1,38 +1,11 @@ -/* - * Arduios - * by John´s Project - * - * Arduios is like a operating system for the arduino, - * it enables you to use a sketch in different use cases, - * without having to upload a new one every time. - * - * You can easily write an app by including "kernel.h", - * extending and implementing the methods of the App class - * and registering it in the apps array here. - * (App class is in "kernel.h") - * - * If you need docs just take a look into the '.h' files. - * ---------------------------------------------------------- - * https://github.com/JohnsProject/Arduios - * ---------------------------------------------------------- - * - * This is the bootloader of the Arduios, it loads the kernel - * and is the place where your apps should be registered. - */ - -#include "Kernel.h" - -#include "Shell.h" -//#include "TestApp.h" - -// the kernel will call the first app in the array when its loaded -const App *apps[] = { - &shell, - //&testApp // uncomment to enable TestApp -}; +#include +#include +#include void setup() { - kernel.setup(apps, sizeof(apps) / sizeof(App)); + kernel.addApp(shell); + //kernel.addApp(testApp); + kernel.setup(); } void loop() { diff --git a/Kernel.cpp b/Kernel.cpp index 9e50407..71a7031 100644 --- a/Kernel.cpp +++ b/Kernel.cpp @@ -2,10 +2,8 @@ Kernel kernel; -void Kernel::setup(App *apps[], uint8_t appsCount) { - registry.appsCount = appsCount; +void Kernel::setup() { registry.currentApp = 0; - registry.apps = apps; registry.apps[registry.currentApp]->setup(); } @@ -13,16 +11,28 @@ void Kernel::loop() { registry.apps[registry.currentApp]->loop(); } +void Kernel::addApp(App &app) { + for (uint8_t i = 0; i < registry.MAX_APPS; i++) { + if(registry.apps[i] == NULL){ + registry.apps[i] = &app; + return; + } + } +} + void Kernel::loadApp(uint8_t app_index) { registry.currentApp = app_index; registry.apps[registry.currentApp]->setup(); } void Kernel::loadApp(String app_name) { - for (uint8_t i = 0; i < registry.appsCount; i++) { - if (app_name == registry.apps[i]->getName()) { - registry.currentApp = i; - registry.apps[registry.currentApp]->setup(); + for (uint8_t i = 0; i < registry.MAX_APPS; i++) { + if(registry.apps[i] != NULL){ + if (app_name == registry.apps[i]->getName()) { + registry.currentApp = i; + registry.apps[registry.currentApp]->setup(); + return; + } } } } diff --git a/Kernel.h b/Kernel.h index 0cd17e6..fc012c5 100644 --- a/Kernel.h +++ b/Kernel.h @@ -1,3 +1,24 @@ +/* + * Arduios + * by John´s Project + * + * Arduios is like a operating system for the arduino, + * it enables you to use a sketch in different use cases, + * without having to upload a new one every time. + * + * You can easily write an app by including "kernel.h", + * extending and implementing the methods of the App class + * and registering it in the apps array here. + * (App class is in "kernel.h") + * + * If you need docs just take a look into the '.h' files. + * ---------------------------------------------------------- + * https://github.com/JohnsProject/Arduios + * ---------------------------------------------------------- + * + * This is the bootloader of the Arduios, it loads the kernel + * and is the place where your apps should be registered. + */ #ifndef __KERNEL_H_INCLUDED__ #define __KERNEL_H_INCLUDED__ @@ -21,17 +42,18 @@ class App { extern struct Kernel { struct Registry { - App **apps; - uint8_t appsCount; + const static uint8_t MAX_APPS = 10; + const App *apps[MAX_APPS]; uint8_t currentApp; } registry; + void addApp(App &app); // method used to load an app from the registry by its index void loadApp(uint8_t app_index); // method used to load an app from the registry by its name void loadApp(String app_name); // method called by the bootloader once when the kernel is loaded - void setup(App *apps[], uint8_t appsCount); + void setup(); // method constantly called by the bootloader void loop(); } kernel; diff --git a/Shell.cpp b/Shell.cpp index e64931a..77bba2e 100644 --- a/Shell.cpp +++ b/Shell.cpp @@ -24,13 +24,11 @@ void Shell::loop() { Serial.println(F("commands: list., load:app_name.")); } if (content == F("list")) { - if (kernel.registry.appsCount > 1) { - for (uint8_t i = 1; i < kernel.registry.appsCount; i++) { - Serial.println(kernel.registry.apps[i]->getName()); + for (uint8_t i = 1; i < kernel.registry.MAX_APPS; i++) { + if(kernel.registry.apps[i] != NULL){ + Serial.println(kernel.registry.apps[i]->getName()); + } } - } else { - Serial.println(F("No apps found")); - } } if (content.substring(0, 5) == F("load:")) { content.replace("load:", ""); diff --git a/TestApp.h b/TestApp.h index 4d44516..b12cacb 100644 --- a/TestApp.h +++ b/TestApp.h @@ -16,12 +16,13 @@ class TestApp: public App { void setup() { // put your setup code here, to run once: - Serial.println("TestApp begin"); + Serial.begin(9600); + Serial.println(F("TestApp begin")); } void loop() { // put your main code here, to run repeatedly: - Serial.println("TestApp loop"); + Serial.println(F("TestApp loop")); delay(1000); }