mirror of
				https://github.com/eclipse/upm.git
				synced 2025-10-30 22:54:44 +03:00 
			
		
		
		
	DS1808LC: Add string based cons for Controller
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
						
							2bb89d47ca
						
					
				
				
					commit
					5837c2ecf7
				
			| @@ -4,6 +4,7 @@ | ||||
| #include <cmath> | ||||
| #include "ds1808lc.hpp" | ||||
| #include "mraa-utils.hpp" | ||||
| #include "upm_string_parser.hpp" | ||||
|  | ||||
| #define DS1808_I2C_ADDR 0x28 | ||||
| #define DS1808_POT2_OFFSET 0x40 | ||||
| @@ -11,6 +12,10 @@ | ||||
| #define DS1808_LOW_VALUE 32 // Lowest pot value that the eye can differentiate from 0 | ||||
| #define DS1808_HIGH_VALUE 51 // Highest pot value that the eye can differentiate from full | ||||
|  | ||||
| static bool operator!(mraa::MraaIo &mraaIo) | ||||
| { | ||||
|    return mraaIo.getMraaDescriptors() == NULL; | ||||
| } | ||||
|  | ||||
| namespace upm { | ||||
| DS1808LC::DS1808LC(int gpioPower, int i2cBus) | ||||
| @@ -22,8 +27,41 @@ DS1808LC::DS1808LC(int gpioPower, int i2cBus) | ||||
|    getBrightness(); | ||||
| } | ||||
|  | ||||
| DS1808LC::DS1808LC(std::string initStr) : mraaIo(initStr) | ||||
| { | ||||
|    std::vector<std::string> upmTokens; | ||||
|     | ||||
|    mraa_set_log_level(7); | ||||
|    if(!mraaIo.i2cs.empty()) { | ||||
|       i2c = &mraaIo.i2cs[0]; | ||||
|    } else { | ||||
|       throw std::invalid_argument(std::string(__FUNCTION__) + ": I2c.init() failed"); | ||||
|    } | ||||
|    | ||||
|    status = i2c->address(DS1808_I2C_ADDR); | ||||
|    | ||||
|    if(!mraaIo.getLeftoverStr().empty()) { | ||||
|       upmTokens = UpmStringParser::parse(mraaIo.getLeftoverStr()); | ||||
|    } | ||||
|    | ||||
|    for(std::string tok : upmTokens) { | ||||
|       if(tok.substr(0, 10) == "gpioPower:") { | ||||
|          int gpioPower = std::stoi(tok.substr(10), nullptr, 0); | ||||
|          pinPower = gpioPower; | ||||
|       } | ||||
|       if(tok.substr(0, 14) == "setBrightness:") { | ||||
|          int dutyPercent = std::stoi(tok.substr(14), nullptr, 0); | ||||
|          setBrightness(dutyPercent); | ||||
|       } | ||||
|    } | ||||
|    | ||||
|    getBrightness(); | ||||
| } | ||||
|  | ||||
| DS1808LC::~DS1808LC() | ||||
| { | ||||
|    if(!mraaIo) | ||||
|       delete i2c; | ||||
| } | ||||
|  | ||||
| bool DS1808LC::isPowered() | ||||
|   | ||||
| @@ -21,9 +21,11 @@ | ||||
|  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||||
|  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||||
|  */ | ||||
| #include <string> | ||||
|  | ||||
| #include "iLightController.hpp" | ||||
| #include "mraa/i2c.hpp" | ||||
| #include "mraa/initio.hpp" | ||||
|  | ||||
| namespace upm | ||||
| { | ||||
| @@ -55,6 +57,7 @@ class DS1808LC : public upm::ILightController | ||||
| { | ||||
| public: | ||||
|    DS1808LC(int gpioPower, int i2cBus); | ||||
|    DS1808LC(std::string initStr); | ||||
|    ~DS1808LC(); | ||||
|  | ||||
|    const char* getModuleName() { return "ds1808lc"; } | ||||
| @@ -72,6 +75,7 @@ private: | ||||
|  | ||||
|    mraa::Result status; | ||||
|    mraa::I2c* i2c; | ||||
|    mraa::MraaIo mraaIo;  | ||||
|    int pinPower; | ||||
| }; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user