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:
@@ -1,8 +1,8 @@
|
||||
#ifndef _GWAPI_H
|
||||
#define _GWAPI_H
|
||||
#include "GwMessage.h"
|
||||
#include "N2kMessages.h"
|
||||
#include "NMEA0183Messages.h"
|
||||
#include "N2kMsg.h"
|
||||
#include "NMEA0183Msg.h"
|
||||
#include "GWConfig.h"
|
||||
#include "GwBoatData.h"
|
||||
//API to be used for additional tasks
|
||||
@@ -16,4 +16,7 @@ class GwApi{
|
||||
virtual GwLog *getLogger()=0;
|
||||
virtual GwBoatData *getBoatData()=0;
|
||||
};
|
||||
#endif
|
||||
#ifndef DECLARE_USERTASK
|
||||
#define DECLARE_USERTASK(task)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
25
lib/exampletask/GwExampleHardware.h
Normal file
25
lib/exampletask/GwExampleHardware.h
Normal 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
|
||||
@@ -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
|
||||
@@ -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
31
lib/exampletask/Readme.md
Normal 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.
|
||||
|
||||
10
lib/exampletask/platformio.ini
Normal file
10
lib/exampletask/platformio.ini
Normal 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
|
||||
@@ -13,6 +13,7 @@
|
||||
*/
|
||||
#ifndef _GWHARDWARE_H
|
||||
#define _GWHARDWARE_H
|
||||
#include "GwUserTasks.h"
|
||||
|
||||
//SERIAL_MODE can be: UNI (RX or TX only), BI (both), RX, TX
|
||||
//board specific pins
|
||||
|
||||
Reference in New Issue
Block a user