mirror of
				https://github.com/eclipse/upm.git
				synced 2025-10-31 07:04:14 +03:00 
			
		
		
		
	DS2413: Add string based constructor for Switch
Signed-off-by: Adelin Dobre <adelin.dobre@rinftech.com>
This commit is contained in:
		 Adelin Dobre
					Adelin Dobre
				
			
				
					committed by
					
						 Stefan Andritoiu
						Stefan Andritoiu
					
				
			
			
				
	
			
			
			 Stefan Andritoiu
						Stefan Andritoiu
					
				
			
						parent
						
							5837c2ecf7
						
					
				
				
					commit
					93449a99f2
				
			| @@ -27,6 +27,8 @@ | |||||||
| #include <stdexcept> | #include <stdexcept> | ||||||
|  |  | ||||||
| #include "ds2413.hpp" | #include "ds2413.hpp" | ||||||
|  | #include "upm_string_parser.hpp" | ||||||
|  |  | ||||||
|  |  | ||||||
| using namespace upm; | using namespace upm; | ||||||
| using namespace std; | using namespace std; | ||||||
| @@ -48,6 +50,39 @@ DS2413::DS2413(int uart) : | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | DS2413::DS2413(std::string initStr) : m_uart(nullptr), mraaIo(initStr) | ||||||
|  | { | ||||||
|  |   mraa_io_descriptor* descs = mraaIo.getMraaDescriptors(); | ||||||
|  |   std::vector<std::string> upmTokens; | ||||||
|  |    | ||||||
|  |   if(!mraaIo.getLeftoverStr().empty()) { | ||||||
|  |     upmTokens = UpmStringParser::parse(mraaIo.getLeftoverStr()); | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   m_uart = descs->uart_ows[0]; | ||||||
|  |   m_devicesFound = 0; | ||||||
|  |  | ||||||
|  |   // check basic access to the 1-wire bus (presence detect) | ||||||
|  |   mraa::Result rv; | ||||||
|  |  | ||||||
|  |   if ((rv = m_uart.reset()) != mraa::SUCCESS) | ||||||
|  |   { | ||||||
|  |     throw std::runtime_error(std::string(__FUNCTION__) + | ||||||
|  |                               ": reset() failed, no devices on bus?"); | ||||||
|  |     return; | ||||||
|  |   } | ||||||
|  |    | ||||||
|  |   for(std::string tok : upmTokens) { | ||||||
|  |     if(tok.substr(0, 11) == "writeGpios:") { | ||||||
|  |       std::string::size_type sz; | ||||||
|  |       int index = std::stoi(tok.substr(11), &sz); | ||||||
|  |       tok = tok.substr(11); | ||||||
|  |       int value = std::stoi(tok.substr(sz+1), nullptr, 0); | ||||||
|  |       writeGpios(index, value); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  | } | ||||||
|  |  | ||||||
| DS2413::~DS2413() | DS2413::~DS2413() | ||||||
| { | { | ||||||
| } | } | ||||||
|   | |||||||
| @@ -26,6 +26,7 @@ | |||||||
| #include <string> | #include <string> | ||||||
| #include <iostream> | #include <iostream> | ||||||
| #include <map> | #include <map> | ||||||
|  | #include <vector> | ||||||
|  |  | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
| #include <unistd.h> | #include <unistd.h> | ||||||
| @@ -33,6 +34,7 @@ | |||||||
|  |  | ||||||
| #include <mraa/common.hpp> | #include <mraa/common.hpp> | ||||||
| #include <mraa/uart_ow.hpp> | #include <mraa/uart_ow.hpp> | ||||||
|  | #include <mraa/initio.hpp> | ||||||
|  |  | ||||||
| #define DS2413_DEFAULT_UART 0 | #define DS2413_DEFAULT_UART 0 | ||||||
|  |  | ||||||
| @@ -100,6 +102,13 @@ namespace upm { | |||||||
|      */ |      */ | ||||||
|     DS2413(int uart=DS2413_DEFAULT_UART); |     DS2413(int uart=DS2413_DEFAULT_UART); | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Instantiates DS2413 Switch object based on a given string. | ||||||
|  |      * | ||||||
|  |      * @param initStr string containing specific information for DS2413 Switch initialization. | ||||||
|  |      */ | ||||||
|  |     DS2413(std::string initStr);  | ||||||
|  |      | ||||||
|     /** |     /** | ||||||
|      * DS2413 object destructor |      * DS2413 object destructor | ||||||
|      */ |      */ | ||||||
| @@ -164,6 +173,7 @@ namespace upm { | |||||||
|  |  | ||||||
|   protected: |   protected: | ||||||
|     mraa::UartOW m_uart; |     mraa::UartOW m_uart; | ||||||
|  |     mraa::MraaIo mraaIo; | ||||||
|      |      | ||||||
|     // the total number of devices found |     // the total number of devices found | ||||||
|     int m_devicesFound; |     int m_devicesFound; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user