From b7cc798a3697ddfd2522e833f3b6d4ebd70cd9a5 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Tue, 23 Jul 2024 14:44:08 +0200 Subject: [PATCH] Provide conversion of expansion type to string for easier reading. --- examples/opcua_server/opcua_server.ino | 3 +- src/ArduinoOpta.h | 1 + src/ArduinoOptaExpansionType.h | 58 ++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/ArduinoOptaExpansionType.h diff --git a/examples/opcua_server/opcua_server.ino b/examples/opcua_server/opcua_server.ino index 0ce31b3..2e2f5d3 100644 --- a/examples/opcua_server/opcua_server.ino +++ b/examples/opcua_server/opcua_server.ino @@ -322,7 +322,8 @@ void setup() uint8_t const opta_expansion_num = OptaController.getExpansionNum(); UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "OptaController %d expansion modules detected.", opta_expansion_num); for(uint8_t i = 0; i < opta_expansion_num; i++) - UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Expansion %d: type = %d, I2C address= 0x%02X", i, OptaController.getExpansionType(i), OptaController.getExpansionI2Caddress(i)); + UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Expansion %d: type = %d (\"%16s\"), I2C address= 0x%02X", + i, OptaController.getExpansionType(i), opcua::ArduinoOptaExpansionType::toStr(OptaController.getExpansionType(i)).c_str(), OptaController.getExpansionI2Caddress(i)); #if USE_MODBUS_SENSOR_MD02 { diff --git a/src/ArduinoOpta.h b/src/ArduinoOpta.h index 364cd52..dd462a5 100644 --- a/src/ArduinoOpta.h +++ b/src/ArduinoOpta.h @@ -23,6 +23,7 @@ #include "DigitalInputManager.h" #include "UserButton.h" #include "ArduinoOptaVariant.h" +#include "ArduinoOptaExpansionType.h" /************************************************************************************** * NAMESPACE diff --git a/src/ArduinoOptaExpansionType.h b/src/ArduinoOptaExpansionType.h new file mode 100644 index 0000000..aa33024 --- /dev/null +++ b/src/ArduinoOptaExpansionType.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2024 Arduino + * + * SPDX-License-Identifier: MPL-2.0 + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#include "OptaBlue.h" + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +namespace opcua +{ + +/************************************************************************************** + * CLASS DECLARATION + **************************************************************************************/ + +class ArduinoOptaExpansionType +{ +public: + ArduinoOptaExpansionType() = delete; + ArduinoOptaExpansionType(ArduinoOptaExpansionType const &) = delete; + + static std::string toStr(ExpansionType_t const type) + { + if(type == EXPANSION_NOT_VALID) + return std::string("Invalid"); + else if(type == EXPANSION_OPTA_DIGITAL_MEC) + return std::string("Digital [Mech.]"); + else if(type == EXPANSION_OPTA_DIGITAL_STS) + return std::string("Digital [Solid]"); + else if(type == EXPANSION_DIGITAL_INVALID) + return std::string("Digital [Inva.]"); + else if(type == EXPANSION_OPTA_ANALOG) + return std::string("Analog"); + else + return std::string("Unknown"); + } +}; + +/************************************************************************************** + * NAMESPACE + **************************************************************************************/ + +}