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

add api for supplementary tasks, add button task

This commit is contained in:
andreas
2021-11-06 14:32:57 +01:00
parent 99beb82014
commit 2526c82562
5 changed files with 158 additions and 1 deletions

View File

@@ -1,43 +0,0 @@
/*
This code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This code is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _GWHARDWARE_H
#define _GWHARDWARE_H
//SERIAL_MODE can be: UNI (RX or TX only), BI (both), RX, TX
//board specific pins
#ifdef BOARD_M5ATOM
#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"
#elif BOARD_M5ATOM_CANUNIT
#define ESP32_CAN_TX_PIN GPIO_NUM_26
#define ESP32_CAN_RX_PIN GPIO_NUM_32
#elif BOARD_M5STICK_CANUNIT
#define ESP32_CAN_TX_PIN GPIO_NUM_32
#define ESP32_CAN_RX_PIN GPIO_NUM_33
#elif BOARD_HOMBERGER
#define ESP32_CAN_TX_PIN GPIO_NUM_5
#define ESP32_CAN_RX_PIN GPIO_NUM_4
//serial input only
#define GWSERIAL_RX 16
#define GWSERIAL_MODE "RX"
#else
#endif
#endif

View File

@@ -12,7 +12,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define VERSION "0.5.4"
#define VERSION "0.5.6"
// #define GW_MESSAGE_DEBUG_ENABLED
// #define FALLBACK_SERIAL
@@ -43,6 +43,8 @@ const unsigned long HEAP_REPORT_TIME=2000; //set to 0 to disable heap reporting
#include "GwSerial.h"
#include "GwWebServer.h"
#include "NMEA0183DataToN2K.h"
#include "GwApi.h"
#include "GwButtons.h"
//NMEA message channels
@@ -126,6 +128,41 @@ class GwSerialLog : public GwLogWriter{
};
class ApiImpl : public GwApi
{
private:
int sourceId = -1;
public:
ApiImpl(int sourceId)
{
this->sourceId = sourceId;
}
virtual GwRequestQueue *getQueue()
{
return &mainQueue;
}
virtual void sendN2kMessage(const tN2kMsg &msg)
{
NMEA2000.SendMsg(msg);
}
virtual void sendNMEA0183Message(const tNMEA0183Msg &msg, int sourceId)
{
SendNMEA0183Message(msg, sourceId);
}
virtual int getSourceId()
{
return sourceId;
};
virtual GwConfigHandler *getConfig()
{
return &config;
}
virtual GwLog* getLogger(){
return &logger;
}
};
void delayedRestart(){
xTaskCreate([](void *p){
delay(500);
@@ -134,6 +171,12 @@ void delayedRestart(){
},"reset",1000,NULL,0,NULL);
}
void startAddOnTask(TaskFunction_t task,int sourceId){
ApiImpl* api=new ApiImpl(sourceId);
xTaskCreate(task,"user",1000,api,3,NULL);
}
#define JSON_OK "{\"status\":\"OK\"}"
//WebServer requests that should
@@ -451,6 +494,7 @@ void setup() {
nmea0183Converter->HandleMsg(n2kMsg);
});
NMEA2000.Open();
startAddOnTask(handleButtons,100);
}
//*****************************************************************************