1
0
mirror of https://github.com/thooge/esp32-nmea2000-obp60.git synced 2025-12-13 05:53:06 +01:00

intermediate: generic handling of user tasks

This commit is contained in:
wellenvogel
2021-11-27 14:57:16 +01:00
parent 5bf2aeaffe
commit 1e4285fe5d
11 changed files with 157 additions and 19 deletions

View File

@@ -0,0 +1,25 @@
#ifndef _GWEXAMPLEHARDWARE_H
#define _GWEXAMPLEHARDWARE_H
#ifdef BOARD_TEST
#define ESP32_CAN_TX_PIN GPIO_NUM_22
#define ESP32_CAN_RX_PIN GPIO_NUM_19
//if using tail485
#define GWSERIAL_TX 26
#define GWSERIAL_RX 32
#define GWSERIAL_MODE "UNI"
#define GWBUTTON_PIN GPIO_NUM_39
#define GWBUTTON_ACTIVE LOW
//if GWBUTTON_PULLUPDOWN we enable a pulup/pulldown
#define GWBUTTON_PULLUPDOWN
//led handling
//if we define GWLED_FASTNET the arduino fastnet lib is used
#define GWLED_FASTLED
#define GWLED_TYPE SK6812
//color schema for fastled
#define GWLED_SCHEMA GRB
#define GWLED_PIN GPIO_NUM_27
//brightness 0...255
#define GWLED_BRIGHTNESS 64
#endif
#endif

View File

@@ -1,4 +1,7 @@
//we only compile for some boards
#ifdef BOARD_TEST
#include "GwExampleTask.h"
#include "GwApi.h"
#define INVALID_COORD -99999
@@ -79,4 +82,6 @@ void exampleTask(void *param){
}
vTaskDelete(NULL);
}
}
#endif

View File

@@ -1,5 +1,11 @@
#ifndef _GWEXAMPLETASK_H
#define _GWEXAMPLETASK_H
//task function
#include "GwExampleHardware.h"
#include "GwApi.h"
//we only compile for some boards
#ifdef BOARD_TEST
void exampleTask(void *param);
//make the task known to the core
DECLARE_USERTASK(exampleTask);
#endif
#endif

31
lib/exampletask/Readme.md Normal file
View File

@@ -0,0 +1,31 @@
Extending the Core
==================
This directory contains an example on how you can extend the base functionality of the gateway.
Basically you can define own boards here and can add one or more tasks that will be started by the core.
You can also add additional libraries that will be used for your task.
In this example we define an addtional board (environment) with the name "testboard".
When building for this board we add the -DTEST_BOARD to the compilation - see [platformio.ini](platformio.ini).
The additional task that we defined will only be compiled and started for this environment (see the #ifdef TEST_BOARD in the code).
You can add your own directory below "lib". The name of the directory must contain "task".
Files
-----
* [platformio.ini](platformio.ini)
extend the base configuration - we add a dummy library here and define our buil environment (board)
* [GwExampleTask.h](GwExampleTask.h) the name of this include must match the name of the directory (ignoring case) with a "gw" in front. This file includes our special hardware definitions and registers our task at the core (DECLARE_USERTASK in the code).
* [GwExampleTaks.cpp](GwExampleTask.cpp) includes the implementation of our task. This tasks runs in an own thread - see the comments in the code.
* [GwExampleHardware.h](GwExampleHardware.h) includes our pin definitions for the board.
Hints
-----
Just be careful not to interfere with names from the core - so it is a good practice to prefix your files and class like in the example.
Developing
----------
To develop I recommend forking the gateway repository and adding your own directory below lib (with the string task in it's name).
As your code goes into a separate directory it should be very easy to fetch upstream changes without the need to adapt your code.
Future Plans
------------
If there will be a need we can extend this extension API by means of adding config items and specific java script code and css for the UI.

View File

@@ -0,0 +1,10 @@
[env:testboard]
board = m5stack-atom
lib_deps =
${env.lib_deps}
own_lib
build_flags=
-D BOARD_TEST
${env.build_flags}
upload_port = /dev/esp32
upload_protocol = esptool