diff options
Diffstat (limited to 'src/Device/Device.cpp')
-rw-r--r-- | src/Device/Device.cpp | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/src/Device/Device.cpp b/src/Device/Device.cpp index 2d93ed7..e743dd6 100644 --- a/src/Device/Device.cpp +++ b/src/Device/Device.cpp @@ -703,19 +703,31 @@ unsigned int Device::gpio_request::offset() * assume the name is an attribute of the mts-io * driver. GPIOs can only be zero * or one, never a text string. + * + * If the data pointer (2nd parm) is not NULL, + * return the text of the value. This covers + * non-gpio instances, such as device-id. */ -int Device::getPinValue(const std::string &name) { +int Device::getPinValue(const std::string &name, std::string *data) +{ std::string fileData; if(isupper(name[0])) { gpio_request gr(this, name); if (gr.request()) { enum gpiod_line_value lv = gpiod_line_request_get_value(gr.request(),gr.offset()); if(lv != GPIOD_LINE_VALUE_ERROR) { - if(lv == GPIOD_LINE_VALUE_INACTIVE) + if(lv == GPIOD_LINE_VALUE_INACTIVE) { + if(data != NULL) + *data = "0"; return 0; - else - return 1; + } else { + if(data != NULL) { + *data = "1"; + return 0; + } else + return 1; + } } else simpleError("Invalid GPIO line value", errno, 109); } @@ -723,6 +735,10 @@ int Device::getPinValue(const std::string &name) { int32_t code = MTS::System::readFile(SYSFS_PLATFORM + name, fileData); if (code == 0) { + if (data != NULL) { + *data = fileData; + return 0; + } if (fileData == "1") { return 1; }; @@ -735,11 +751,15 @@ int Device::getPinValue(const std::string &name) { } void Device::show(std::string name) { + std::string fileData; + int result; if (regex_match(hw_version, iotRtrVersionFilters)) { showSerialModesMTR3(name); } - printf("%i", getPinValue(name)); - exitHandler(0); + result = getPinValue(name,&fileData); + if (result == 0) + printf("%s\n", fileData.c_str()); + exitHandler(result); } // End of show void Device::showTrigger(std::string name) { @@ -943,13 +963,13 @@ void Device::showSerialModesMTR3(const std::string ¶meter) { printUsage(); } if (mode == SERIAL_MODE) { - if (getPinValue(CONTROL_PIN_SERIAL_MODE) == 1) { + if (getPinValue(CONTROL_PIN_SERIAL_MODE,NULL) == 1) { std::cout << SERIAL_MODE_RS485 << std::endl; } else { std::cout << SERIAL_MODE_RS232 << std::endl; } } else if (mode == SERIAL_TERMINATION) { - std::cout << getPinValue(CONTROL_PIN_TERMINATION) << std::endl; + std::cout << getPinValue(CONTROL_PIN_TERMINATION,NULL) << std::endl; } else { printError("Unknown mode: %s", mode.c_str()); exitHandler(98); @@ -968,4 +988,4 @@ void Device::setHWVersion(){ return; } std::getline(is, hw_version); -}
\ No newline at end of file +} |