mirror of
https://github.com/thooge/esp32-nmea2000-obp60.git
synced 2025-12-14 22:43:07 +01:00
add calset input
This commit is contained in:
44
src/main.cpp
44
src/main.cpp
@@ -235,15 +235,38 @@ void SendNMEA0183Message(const tNMEA0183Msg &NMEA0183Msg, int sourceId,bool conv
|
||||
});
|
||||
}
|
||||
|
||||
class CalibrationValues {
|
||||
using Map=std::map<String,double>;
|
||||
Map values;
|
||||
SemaphoreHandle_t lock;
|
||||
public:
|
||||
CalibrationValues(){
|
||||
lock=xSemaphoreCreateMutex();
|
||||
}
|
||||
void set(const String &name,double value){
|
||||
GWSYNCHRONIZED(&lock);
|
||||
values[name]=value;
|
||||
}
|
||||
bool get(const String &name, double &value){
|
||||
GWSYNCHRONIZED(&lock);
|
||||
auto it=values.find(name);
|
||||
if (it==values.end()) return false;
|
||||
value=it->second;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class ApiImpl : public GwApiInternal
|
||||
{
|
||||
private:
|
||||
int sourceId = -1;
|
||||
std::unique_ptr<CalibrationValues> calibrations;
|
||||
|
||||
public:
|
||||
ApiImpl(int sourceId)
|
||||
{
|
||||
this->sourceId = sourceId;
|
||||
calibrations.reset(new CalibrationValues());
|
||||
}
|
||||
virtual GwRequestQueue *getQueue()
|
||||
{
|
||||
@@ -332,6 +355,13 @@ public:
|
||||
virtual bool addUserTask(GwUserTaskFunction task,const String Name, int stackSize=2000){
|
||||
return false;
|
||||
}
|
||||
virtual void setCalibrationValue(const String &name, double value){
|
||||
calibrations->set(name,value);
|
||||
}
|
||||
|
||||
bool getCalibrationValue(const String &name,double &value){
|
||||
return calibrations->get(name,value);
|
||||
}
|
||||
};
|
||||
|
||||
bool delayedRestart(){
|
||||
@@ -803,7 +833,19 @@ void setup() {
|
||||
[](AsyncWebServerRequest *request){
|
||||
|
||||
},
|
||||
handleConfigRequestData);
|
||||
handleConfigRequestData);
|
||||
webserver.registerHandler("/api/calibrate",[](AsyncWebServerRequest *request){
|
||||
const String name=request->arg("name");
|
||||
double value;
|
||||
if (! apiImpl->getCalibrationValue(name,value)){
|
||||
request->send(400, "text/plain", "name not found");
|
||||
return;
|
||||
}
|
||||
char buffer[30];
|
||||
snprintf(buffer,29,"%g",value);
|
||||
buffer[29]=0;
|
||||
request->send(200,"text/plain",buffer);
|
||||
});
|
||||
|
||||
webserver.begin();
|
||||
xdrMappings.begin();
|
||||
|
||||
Reference in New Issue
Block a user