Skip to content

Commit b7cc798

Browse files
committed
Provide conversion of expansion type to string for easier reading.
1 parent 1290037 commit b7cc798

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

examples/opcua_server/opcua_server.ino

+2-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ void setup()
322322
uint8_t const opta_expansion_num = OptaController.getExpansionNum();
323323
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "OptaController %d expansion modules detected.", opta_expansion_num);
324324
for(uint8_t i = 0; i < opta_expansion_num; i++)
325-
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Expansion %d: type = %d, I2C address= 0x%02X", i, OptaController.getExpansionType(i), OptaController.getExpansionI2Caddress(i));
325+
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Expansion %d: type = %d (\"%16s\"), I2C address= 0x%02X",
326+
i, OptaController.getExpansionType(i), opcua::ArduinoOptaExpansionType::toStr(OptaController.getExpansionType(i)).c_str(), OptaController.getExpansionI2Caddress(i));
326327

327328
#if USE_MODBUS_SENSOR_MD02
328329
{

src/ArduinoOpta.h

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "DigitalInputManager.h"
2424
#include "UserButton.h"
2525
#include "ArduinoOptaVariant.h"
26+
#include "ArduinoOptaExpansionType.h"
2627

2728
/**************************************************************************************
2829
* NAMESPACE

src/ArduinoOptaExpansionType.h

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2024 Arduino
3+
*
4+
* SPDX-License-Identifier: MPL-2.0
5+
* This Source Code Form is subject to the terms of the Mozilla Public
6+
* License, v. 2.0. If a copy of the MPL was not distributed with this
7+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
8+
*/
9+
10+
#pragma once
11+
12+
/**************************************************************************************
13+
* INCLUDE
14+
**************************************************************************************/
15+
16+
#include <string>
17+
18+
#include "OptaBlue.h"
19+
20+
/**************************************************************************************
21+
* NAMESPACE
22+
**************************************************************************************/
23+
24+
namespace opcua
25+
{
26+
27+
/**************************************************************************************
28+
* CLASS DECLARATION
29+
**************************************************************************************/
30+
31+
class ArduinoOptaExpansionType
32+
{
33+
public:
34+
ArduinoOptaExpansionType() = delete;
35+
ArduinoOptaExpansionType(ArduinoOptaExpansionType const &) = delete;
36+
37+
static std::string toStr(ExpansionType_t const type)
38+
{
39+
if(type == EXPANSION_NOT_VALID)
40+
return std::string("Invalid");
41+
else if(type == EXPANSION_OPTA_DIGITAL_MEC)
42+
return std::string("Digital [Mech.]");
43+
else if(type == EXPANSION_OPTA_DIGITAL_STS)
44+
return std::string("Digital [Solid]");
45+
else if(type == EXPANSION_DIGITAL_INVALID)
46+
return std::string("Digital [Inva.]");
47+
else if(type == EXPANSION_OPTA_ANALOG)
48+
return std::string("Analog");
49+
else
50+
return std::string("Unknown");
51+
}
52+
};
53+
54+
/**************************************************************************************
55+
* NAMESPACE
56+
**************************************************************************************/
57+
58+
}

0 commit comments

Comments
 (0)