Prepared formatter class for boat values. E.g. for better config handling
This commit is contained in:
parent
ae9334236b
commit
fbe6c1a9a5
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "OBP60Hardware.h"
|
#include "OBP60Hardware.h"
|
||||||
|
#include "OBP60Formatter.h"
|
||||||
#include "LedSpiTask.h"
|
#include "LedSpiTask.h"
|
||||||
#include "Graphics.h"
|
#include "Graphics.h"
|
||||||
#include <GxEPD2_BW.h> // E-paper lib V2
|
#include <GxEPD2_BW.h> // E-paper lib V2
|
||||||
|
|
|
@ -3,11 +3,27 @@
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "GwApi.h"
|
#include "GwApi.h"
|
||||||
#include "Pagedata.h"
|
#include "Pagedata.h"
|
||||||
|
#include "OBP60Formatter.h"
|
||||||
|
|
||||||
// ToDo
|
// ToDo
|
||||||
// simulation data
|
// simulation data
|
||||||
// hold values by missing data
|
// hold values by missing data
|
||||||
|
|
||||||
|
Formatter::Formatter(GwConfigHandler *config) {
|
||||||
|
// Load configuration values
|
||||||
|
// TODO do not use strings but enums, see header file
|
||||||
|
stimeZone = config->getString(config->timeZone);
|
||||||
|
timeZone = stimeZone.toDouble();
|
||||||
|
lengthFormat = config->getString(config->lengthFormat);
|
||||||
|
distanceFormat = config->getString(config->distanceFormat);
|
||||||
|
speedFormat = config->getString(config->speedFormat);
|
||||||
|
windspeedFormat = config->getString(config->windspeedFormat);
|
||||||
|
tempFormat = config->getString(config->tempFormat);
|
||||||
|
dateFormat = config->getString(config->dateFormat);
|
||||||
|
usesimudata = config->getBool(config->useSimuData);
|
||||||
|
precision = config->getString(config->valueprecision);
|
||||||
|
}
|
||||||
|
|
||||||
String formatDate(String fmttype, uint16_t year, uint8_t month, uint8_t day) {
|
String formatDate(String fmttype, uint16_t year, uint8_t month, uint8_t day) {
|
||||||
char buffer[12];
|
char buffer[12];
|
||||||
if (fmttype == "GB") {
|
if (fmttype == "GB") {
|
||||||
|
|
|
@ -0,0 +1,123 @@
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
#ifndef _OBP60FORMATTER_H
|
||||||
|
#define _OBP60FORMATTER_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
Formatter names as defined in BoatItemBase
|
||||||
|
formatCourse
|
||||||
|
formatKnots
|
||||||
|
formatWind
|
||||||
|
formatLatitude
|
||||||
|
formatLongitude
|
||||||
|
formatXte
|
||||||
|
formatFixed0
|
||||||
|
formatDepth
|
||||||
|
kelvinToC TODO not a format but conversion
|
||||||
|
mtr2nm TODO not a format but conversion
|
||||||
|
formatDop dilution of precision
|
||||||
|
formatRot
|
||||||
|
formatDate
|
||||||
|
formatTime
|
||||||
|
formatName
|
||||||
|
|
||||||
|
XDR Formatter names
|
||||||
|
formatXdr:P:P // pressure percent
|
||||||
|
formatXdr:P:B // pressure bar
|
||||||
|
formatXdr:U:V // voltage volt
|
||||||
|
formatXdr:I:A // current ampere
|
||||||
|
formatXdr:C:K // temperature kelvin
|
||||||
|
formatXdr:C:C // temperature celsius
|
||||||
|
formatXdr:H:P // humidity percent
|
||||||
|
formatXdr:V:P // volume percent
|
||||||
|
formatXdr:V:M // volume cubic meters
|
||||||
|
formatXdr:R:I // flow liter per second?
|
||||||
|
formatXdr:G: // generic
|
||||||
|
formatXdr:A:P // angle percent
|
||||||
|
formatXdr:A:D // angle degrees
|
||||||
|
formatXdr:T:R // tachometer rpm
|
||||||
|
|
||||||
|
XDR types
|
||||||
|
A Angular displacement
|
||||||
|
C Temperature
|
||||||
|
D Linear displacement
|
||||||
|
F Frequency
|
||||||
|
G Generic
|
||||||
|
H Humidity
|
||||||
|
I Current
|
||||||
|
L Salinity
|
||||||
|
N Force
|
||||||
|
P Pressure
|
||||||
|
R Flow
|
||||||
|
S Switch or valve
|
||||||
|
T Tachometer
|
||||||
|
U Voltage
|
||||||
|
V Volume
|
||||||
|
|
||||||
|
XDR units
|
||||||
|
A Ampere
|
||||||
|
B Bar
|
||||||
|
C Celsius
|
||||||
|
D Degrees
|
||||||
|
H Hertz
|
||||||
|
I Liter per second?
|
||||||
|
M Meter / Cubic meter
|
||||||
|
N Newton
|
||||||
|
P Percent
|
||||||
|
R RPM
|
||||||
|
V Volt
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Possible formats as scoped enums
|
||||||
|
enum class fmtDate {DE, EN, GB, ISO};
|
||||||
|
enum class fmtTime {MMHH, MMHHSS};
|
||||||
|
enum class fmtLength {METER, FEET, FATHOM, CABLE};
|
||||||
|
enum class fmtDepth {METER, FEET, FATHOM};
|
||||||
|
enum class fmtWind {KMH, MS, KN, BFT};
|
||||||
|
enum class fmtCourse {DEG, RAD};
|
||||||
|
enum class fmtRot {DEGS, RADS};
|
||||||
|
enum class fmtXte {M, KM, NM, CABLE};
|
||||||
|
enum class fmtPress {PA, BAR};
|
||||||
|
enum class fmtTemp {KELVIN, CELSUIS, FAHRENHEIT};
|
||||||
|
|
||||||
|
// Conversion factors
|
||||||
|
#define CONV_M_FT 3.2808399 // meter too feet
|
||||||
|
#define CONV_M_FM 0.5468 // meter to fathom
|
||||||
|
#define CONV_M_CBL 0.0053961182483768 // meter to cable
|
||||||
|
#define CONV_CBL_FT 608 // cable to feet
|
||||||
|
#define CONV_FM_FT 6 // fathom to feet
|
||||||
|
|
||||||
|
// Structure for formatted boat values
|
||||||
|
typedef struct {
|
||||||
|
double value;
|
||||||
|
String svalue;
|
||||||
|
String unit;
|
||||||
|
} FormattedData;
|
||||||
|
|
||||||
|
// Formatter for boat values
|
||||||
|
FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata);
|
||||||
|
|
||||||
|
class Formatter {
|
||||||
|
private:
|
||||||
|
String stimeZone = "0";
|
||||||
|
double timeZone = 0.0; // [UTC -14.00...+12.00]
|
||||||
|
String lengthFormat = "m"; // [m|ft]
|
||||||
|
String distanceFormat = "nm"; // [m|km|nm]
|
||||||
|
String speedFormat = "kn"; // [m/s|km/h|kn]
|
||||||
|
String windspeedFormat = "kn"; // [m/s|km/h|kn|bft]
|
||||||
|
String tempFormat = "C"; // [K|°C|°F]
|
||||||
|
String dateFormat = "ISO"; // [DE|GB|US|ISO]
|
||||||
|
bool usesimudata = false; // [on|off]
|
||||||
|
String precision = "2"; // [1|2]
|
||||||
|
public:
|
||||||
|
Formatter(GwConfigHandler *config);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Standard format functions without overhead
|
||||||
|
String formatDate(String fmttype, uint16_t year, uint8_t month, uint8_t day);
|
||||||
|
String formatTime(char fmttype, uint8_t hour, uint8_t minute, uint8_t second);
|
||||||
|
String formatLatitude(double lat);
|
||||||
|
String formatLongitude(double lon);
|
||||||
|
|
||||||
|
#endif
|
|
@ -105,18 +105,20 @@ typedef struct{
|
||||||
int voltage = 0;
|
int voltage = 0;
|
||||||
} AvgData;
|
} AvgData;
|
||||||
|
|
||||||
|
class Formatter; // forward declaration
|
||||||
typedef struct{
|
typedef struct{
|
||||||
GwApi::Status status;
|
GwApi::Status status;
|
||||||
GwLog *logger=NULL;
|
GwLog *logger = nullptr;
|
||||||
GwConfigHandler *config=NULL;
|
GwConfigHandler *config = nullptr;
|
||||||
|
Formatter *fmt = nullptr;
|
||||||
SensorData data;
|
SensorData data;
|
||||||
SunData sundata;
|
SunData sundata;
|
||||||
TouchKeyData keydata[6];
|
TouchKeyData keydata[6];
|
||||||
BacklightData backlight;
|
BacklightData backlight;
|
||||||
AlarmData alarm;
|
AlarmData alarm;
|
||||||
AvgData avgdata;
|
AvgData avgdata;
|
||||||
GwApi::BoatValue *time=NULL;
|
GwApi::BoatValue *time = nullptr;
|
||||||
GwApi::BoatValue *date=NULL;
|
GwApi::BoatValue *date = nullptr;
|
||||||
uint16_t fgcolor;
|
uint16_t fgcolor;
|
||||||
uint16_t bgcolor;
|
uint16_t bgcolor;
|
||||||
bool keylock = false;
|
bool keylock = false;
|
||||||
|
@ -210,19 +212,3 @@ class PageStruct{
|
||||||
PageData parameters;
|
PageData parameters;
|
||||||
PageDescription *description=NULL;
|
PageDescription *description=NULL;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Standard format functions without overhead
|
|
||||||
String formatDate(String fmttype, uint16_t year, uint8_t month, uint8_t day);
|
|
||||||
String formatTime(char fmttype, uint8_t hour, uint8_t minute, uint8_t second);
|
|
||||||
String formatLatitude(double lat);
|
|
||||||
String formatLongitude(double lon);
|
|
||||||
|
|
||||||
// Structure for formatted boat values
|
|
||||||
typedef struct{
|
|
||||||
double value;
|
|
||||||
String svalue;
|
|
||||||
String unit;
|
|
||||||
} FormattedData;
|
|
||||||
|
|
||||||
// Formatter for boat values
|
|
||||||
FormattedData formatValue(GwApi::BoatValue *value, CommonData &commondata);
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ WIP
|
||||||
Please format your new code the same as already existing code.
|
Please format your new code the same as already existing code.
|
||||||
Preprocessor directives go to column zero.
|
Preprocessor directives go to column zero.
|
||||||
|
|
||||||
|
Identation is 4 spaces
|
||||||
|
|
||||||
Git commands
|
Git commands
|
||||||
------------
|
------------
|
||||||
|
|
|
@ -15,3 +15,5 @@
|
||||||
- page clock: sunrise / sunset in local time or UTC
|
- page clock: sunrise / sunset in local time or UTC
|
||||||
|
|
||||||
- implement alerts
|
- implement alerts
|
||||||
|
|
||||||
|
- implement formatter as class
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#if defined BOARD_OBP60S3 || defined BOARD_OBP40S3
|
#if defined BOARD_OBP60S3 || defined BOARD_OBP40S3
|
||||||
#include "obp60task.h"
|
#include "obp60task.h"
|
||||||
#include "Pagedata.h" // Data exchange for pages
|
#include "Pagedata.h" // Data exchange for pages
|
||||||
|
#include "OBP60Formatter.h" // Data formatting for boat values
|
||||||
#include "OBP60Hardware.h" // PIN definitions
|
#include "OBP60Hardware.h" // PIN definitions
|
||||||
#include <Wire.h> // I2C connections
|
#include <Wire.h> // I2C connections
|
||||||
#include <MCP23017.h> // MCP23017 extension Port
|
#include <MCP23017.h> // MCP23017 extension Port
|
||||||
|
@ -550,6 +551,7 @@ void OBP60Task(GwApi *api){
|
||||||
CommonData commonData;
|
CommonData commonData;
|
||||||
commonData.logger = logger;
|
commonData.logger = logger;
|
||||||
commonData.config = config;
|
commonData.config = config;
|
||||||
|
commonData.fmt = new Formatter(config);
|
||||||
|
|
||||||
#ifdef HARDWARE_V21
|
#ifdef HARDWARE_V21
|
||||||
// Keyboard coordinates for page footer
|
// Keyboard coordinates for page footer
|
||||||
|
|
Loading…
Reference in New Issue