diff --git a/.vscode/settings.json b/.vscode/settings.json index 13f18c7..30a0ad1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,40 @@ "terminal.integrated.env.linux": { "PATH": "/home/master/.platformio/penv/bin:/home/master/.platformio/penv:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl", "PLATFORMIO_CALLER": "vscode" + }, + "files.associations": { + "array": "cpp", + "deque": "cpp", + "list": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "initializer_list": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "exception": "cpp", + "fstream": "cpp", + "functional": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "ostream": "cpp", + "numeric": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "type_traits": "cpp", + "tuple": "cpp", + "typeinfo": "cpp", + "utility": "cpp" } } \ No newline at end of file diff --git a/library.json b/library.json new file mode 100644 index 0000000..fb64f8b --- /dev/null +++ b/library.json @@ -0,0 +1,18 @@ +{ + "name": "sprocket-core", + "keywords": "esp8266, sprocket, stack", + "description": "Core stack for sprockets", + "authors": + { + "name": "Patrick Balsiger", + "email": "frupii@gmail.com", + "url": "https://gitlab.com/0x1d" + }, + "repository": + { + "type": "git", + "url": "https://gitlab.com/wirelos/sprocket-core/" + }, + "frameworks": "arduino", + "platforms": "espressif8266" +} \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index d026671..c2f08bf 100644 --- a/platformio.ini +++ b/platformio.ini @@ -8,7 +8,28 @@ ; Please visit documentation for the other options and examples ; http://docs.platformio.org/page/projectconf.html -[env:esp12e] +[platformio] +env_default = build + +[common] +framework = arduino +lib_deps = + ESPAsyncWifiManager + ESP Async WebServer + ESPAsyncTCP + TaskScheduler +; painlessMesh + +[env:build] +#platform = https://github.com/platformio/platform-espressif8266.git#feature/stage +#platform = https://github.com/platformio/platform-espressif8266.git +#platform = espressif8266@~1.6.0 platform = espressif8266 board = esp12e -framework = arduino +upload_speed = 921600 +monitor_baud = 115200 +framework = ${common.framework} +lib_deps = ${common.lib_deps} +#build_flags = -DLED_PIN=2 -g +;upload_port = /dev/ttyUSB0 +;upload_port = 192.168.1.168 \ No newline at end of file diff --git a/src/App.h b/src/App.h new file mode 100644 index 0000000..ea9bc28 --- /dev/null +++ b/src/App.h @@ -0,0 +1,28 @@ +#ifndef _APP_H_ +#define _APP_H_ + +#include +//#include "Sprocket.h" +#include "AppStack.h" + +/* template +class App { + private: + T* stack; + public: + App(); + App(T* stack); +}; + */ + +class App { + protected: + //Sprocket* sprocket; + public: + /* App(Sprocket* sprkt){ + sprocket = sprkt; + } */ + virtual void activate(Scheduler* scheduler); +}; + +#endif \ No newline at end of file diff --git a/src/AppStack.cpp b/src/AppStack.cpp new file mode 100644 index 0000000..3ddc157 --- /dev/null +++ b/src/AppStack.cpp @@ -0,0 +1,12 @@ +#include "AppStack.h" + +AppStack::AppStack(){ + +} + +void AppStack::begin(){ + +} + +void AppStack::loop(){ +} \ No newline at end of file diff --git a/src/AppStack.h b/src/AppStack.h new file mode 100644 index 0000000..9d697c1 --- /dev/null +++ b/src/AppStack.h @@ -0,0 +1,15 @@ +#ifndef __APPSTACK_H_INCLUDED__ +#define __APPSTACK_H_INCLUDED__ + +#include +#include +//#include + +class AppStack { + public: + AppStack(); + void begin(); + void loop(); +}; + +#endif \ No newline at end of file diff --git a/src/Sprocket.cpp b/src/Sprocket.cpp new file mode 100644 index 0000000..86580d1 --- /dev/null +++ b/src/Sprocket.cpp @@ -0,0 +1,24 @@ +#include "Sprocket.h" + +Sprocket::Sprocket(){ + Serial.println("init sprocket"); +} + +Sprocket* Sprocket::use(AppStack* stk){ + stack = stk; + return this; +} + +Sprocket* Sprocket::addTask(Task& tsk){ + scheduler.addTask(tsk); + tsk.enable(); +} + +Sprocket* Sprocket::registerApp(App& app){ + app.activate(&scheduler); +} + +void Sprocket::loop(){ + scheduler.execute(); + //stack->loop(); +} \ No newline at end of file diff --git a/src/Sprocket.h b/src/Sprocket.h new file mode 100644 index 0000000..389f456 --- /dev/null +++ b/src/Sprocket.h @@ -0,0 +1,25 @@ +#ifndef __SPROCKET_H__ +#define __SPROCKET_H__ + + +#include + +#include +#include "WiFiNet.h" +#include "AppStack.h" +#include "App.h" + + +class Sprocket { + private: + AppStack* stack; + Scheduler scheduler; + public: + Sprocket(); + Sprocket* use(AppStack* stack); + Sprocket* addTask(Task& tsk); + Sprocket* registerApp(App& app); + void loop(); +}; + +#endif \ No newline at end of file diff --git a/src/WebStack.h b/src/WebStack.h new file mode 100644 index 0000000..e02fdc8 --- /dev/null +++ b/src/WebStack.h @@ -0,0 +1,35 @@ +#ifndef __WEBSTACK_H_INCLUDED__ +#define __WEBSTACK_H_INCLUDED__ + +#include +#include +#include + +class WebStack : public AppStack { + public: + AsyncWebServer* server; + AsyncWebSocket* socket; + WebStack() : AppStack(){ + server = new AsyncWebServer(80); + initWebServer(); + } + WebStack(AsyncWebServer* webServer) : AppStack(){ + server = webServer; + initWebServer(); + } + WebStack(AsyncWebServer* webServer, AsyncWebSocket* webSocket) : AppStack(){ + server = webServer; + socket = webSocket; + initWebServer(); + } + void initWebServer(){ + //server->serveStatic(WEBSERVER_ROOT, SPIFFS, WEBSERVER_HTDOCS).setDefaultFile(WEBSERVER_DEFAULT_FILE); + //server->on(WEBCONFIG_GET_HEAP, HTTP_GET, HTTP_GET_HEAP); + } + void begin() { + server->begin(); + AppStack::begin(); + } +}; + +#endif \ No newline at end of file diff --git a/src/WiFiNet.h b/src/WiFiNet.h new file mode 100644 index 0000000..90fbcbc --- /dev/null +++ b/src/WiFiNet.h @@ -0,0 +1,49 @@ +#ifndef __WIFI_NET_H__ +#define __WIFI_NET_H__ + +#if defined(ESP8266) +#include //https://github.com/esp8266/Arduino +#include +#else +#include +#endif + +#include +#include +#include +#include //https://github.com/tzapu/WiFiManager + +class WiFiNet { + private: + AsyncWiFiManager* wifiManager; + AsyncWebServer* server; + DNSServer* dns; + const char* hostName = "foo"; + public: + WiFiNet(){ + //server = new AsyncWebServer(80); + dns = new DNSServer(); + } + WiFiNet* use(WebStack* stack) { + server = stack->server; + return this; + } + void connect(/* char const *apName, char const *apPassword */){ + wifiManager = new AsyncWiFiManager(server, dns); + wifiManager->autoConnect(/* apName, apPassword */); + Serial.println("Hostname: " + String(hostName)); + WiFi.hostname(hostName); + startMDNS(); + } + void startMDNS(){ + if (!MDNS.begin(hostName)) { + Serial.println("Error setting up MDNS responder!"); + } else { + Serial.println("mDNS responder started"); + MDNS.addService("http", "tcp", 80); + } + } + +}; + +#endif \ No newline at end of file diff --git a/src/examples/ExampleApp.h b/src/examples/ExampleApp.h new file mode 100644 index 0000000..30d6fbb --- /dev/null +++ b/src/examples/ExampleApp.h @@ -0,0 +1,24 @@ +#ifndef __EXAMPLE_APP__ +#define __EXAMPLE_APP__ + +//#include "Sprocket.h" +#include +#include "App.h" + +class ExampleApp : public App { + public: + Task someTask; + ExampleApp() /* App(sprkt) */ { + Serial.println("joo"); + } + void activate(Scheduler* scheduler) { + Serial.println("activate"); + someTask.set(TASK_SECOND, TASK_FOREVER, [this](){ + Serial.println("do stuff in task"); + }); + scheduler->addTask(someTask); + someTask.enable(); + } +}; + +#endif \ No newline at end of file diff --git a/src/examples/basic_sprocket.cpp b/src/examples/basic_sprocket.cpp new file mode 100644 index 0000000..2164537 --- /dev/null +++ b/src/examples/basic_sprocket.cpp @@ -0,0 +1,40 @@ + +#define _TASK_SLEEP_ON_IDLE_RUN +#define _TASK_STD_FUNCTION + +#include +#include "Sprocket.h" +#include "AppStack.h" +//#include "WiFiNet.h" + +#include "ExampleApp.h" + +#define SERIAL_BAUD_RATE 115200 +#define STARTUP_DELAY 3000 + +Sprocket sprocket; +AppStack stack; +WiFiNet net; + + +ExampleApp app; + +void setup() { + Serial.begin(SERIAL_BAUD_RATE); + SPIFFS.begin(); + delay(STARTUP_DELAY); + + Serial.println("setup"); + //net.use(&stack)->connect(); + + //sprocket.use(&stack); + sprocket.registerApp(app); + + //stack.begin(); + +} + +void loop() { + sprocket.loop(); + yield(); +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp deleted file mode 100644 index de7b395..0000000 --- a/src/main.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -void setup() { - // put your setup code here, to run once: -} - -void loop() { - // put your main code here, to run repeatedly: -} \ No newline at end of file