mirror of
				https://github.com/eclipse/upm.git
				synced 2025-10-30 14:44:56 +03:00 
			
		
		
		
	tcs3414cs: remove custom exception and use standard ones
Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
		 Jon Trulson
					Jon Trulson
				
			
				
					committed by
					
						 Mihai Tudor Panu
						Mihai Tudor Panu
					
				
			
			
				
	
			
			
			 Mihai Tudor Panu
						Mihai Tudor Panu
					
				
			
						parent
						
							8dac9f7356
						
					
				
				
					commit
					448ee39c7f
				
			| @@ -29,25 +29,25 @@ | |||||||
| #include <iostream> | #include <iostream> | ||||||
| #include <unistd.h> | #include <unistd.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
|  | #include <stdexcept> | ||||||
|  |  | ||||||
| #include "tcs3414cs.h" | #include "tcs3414cs.h" | ||||||
|  |  | ||||||
| using namespace upm; | using namespace upm; | ||||||
|  |  | ||||||
| struct TCS3414CSException : public std::exception { |  | ||||||
|     std::string message; |  | ||||||
|     TCS3414CSException (std::string msg) : message (msg) { } |  | ||||||
|     ~TCS3414CSException () throw () { } |  | ||||||
|     const char* what() const throw () { return message.c_str(); } |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| TCS3414CS::TCS3414CS () { | TCS3414CS::TCS3414CS () { | ||||||
|     m_name = "TCS3414CS"; |     m_name = "TCS3414CS"; | ||||||
|     m_i2Ctx = mraa_i2c_init(0); |  | ||||||
|  |     if (!(m_i2Ctx = mraa_i2c_init(0))) | ||||||
|  |       { | ||||||
|  |         throw std::invalid_argument(std::string(__FUNCTION__) +  | ||||||
|  |                                     ": mraa_i2c_init() failed"); | ||||||
|  |       } | ||||||
|  |  | ||||||
|     mraa_result_t ret = mraa_i2c_address(m_i2Ctx, ADDR); |     mraa_result_t ret = mraa_i2c_address(m_i2Ctx, ADDR); | ||||||
|     if (ret != MRAA_SUCCESS) { |     if (ret != MRAA_SUCCESS) { | ||||||
|         throw TCS3414CSException ("Couldn't initilize I2C."); |         throw std::invalid_argument(std::string(__FUNCTION__) +  | ||||||
|  |                                     ": mraa_i2c_address() failed"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // Set timing register |     // Set timing register | ||||||
| @@ -92,15 +92,12 @@ void | |||||||
| TCS3414CS::clearInterrupt () { | TCS3414CS::clearInterrupt () { | ||||||
|     mraa_result_t error = MRAA_SUCCESS; |     mraa_result_t error = MRAA_SUCCESS; | ||||||
|  |  | ||||||
|     if (m_i2Ctx == NULL) { |  | ||||||
|         throw TCS3414CSException ("Couldn't find initilized I2C."); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     error = mraa_i2c_address (m_i2Ctx, ADDR); |     error = mraa_i2c_address (m_i2Ctx, ADDR); | ||||||
|     error = mraa_i2c_write_byte (m_i2Ctx, CLR_INT); |     error = mraa_i2c_write_byte (m_i2Ctx, CLR_INT); | ||||||
|  |  | ||||||
|     if (error != MRAA_SUCCESS) { |     if (error != MRAA_SUCCESS) { | ||||||
|         throw TCS3414CSException ("Couldn't clear interrupt."); |         throw std::runtime_error(std::string(__FUNCTION__) +  | ||||||
|  |                                  ": Couldn't clear interrupt"); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -113,10 +110,6 @@ uint16_t | |||||||
| TCS3414CS::i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer) { | TCS3414CS::i2cReadReg_N (int reg, unsigned int len, uint8_t * buffer) { | ||||||
|     int readByte = 0; |     int readByte = 0; | ||||||
|  |  | ||||||
|     if (m_i2Ctx == NULL) { |  | ||||||
|         throw TCS3414CSException ("Couldn't find initilized I2C."); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     mraa_i2c_address(m_i2Ctx, ADDR); |     mraa_i2c_address(m_i2Ctx, ADDR); | ||||||
|     mraa_i2c_write_byte(m_i2Ctx, reg); |     mraa_i2c_write_byte(m_i2Ctx, reg); | ||||||
|  |  | ||||||
| @@ -129,10 +122,6 @@ mraa_result_t | |||||||
| TCS3414CS::i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer) { | TCS3414CS::i2cWriteReg_N (uint8_t reg, unsigned int len, uint8_t * buffer) { | ||||||
|     mraa_result_t error = MRAA_SUCCESS; |     mraa_result_t error = MRAA_SUCCESS; | ||||||
|  |  | ||||||
|     if (m_i2Ctx == NULL) { |  | ||||||
|         throw TCS3414CSException ("Couldn't find initilized I2C."); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     error = mraa_i2c_address (m_i2Ctx, ADDR); |     error = mraa_i2c_address (m_i2Ctx, ADDR); | ||||||
|     error = mraa_i2c_write_byte (m_i2Ctx, reg); |     error = mraa_i2c_write_byte (m_i2Ctx, reg); | ||||||
|     error = mraa_i2c_write (m_i2Ctx, buffer, len); |     error = mraa_i2c_write (m_i2Ctx, buffer, len); | ||||||
| @@ -144,10 +133,6 @@ mraa_result_t | |||||||
| TCS3414CS::i2cWriteReg (uint8_t reg, uint8_t data) { | TCS3414CS::i2cWriteReg (uint8_t reg, uint8_t data) { | ||||||
|     mraa_result_t error = MRAA_SUCCESS; |     mraa_result_t error = MRAA_SUCCESS; | ||||||
|  |  | ||||||
|     if (m_i2Ctx == NULL) { |  | ||||||
|         throw TCS3414CSException ("Couldn't find initilized I2C."); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     error = mraa_i2c_address (m_i2Ctx, ADDR); |     error = mraa_i2c_address (m_i2Ctx, ADDR); | ||||||
|     error = mraa_i2c_write_byte (m_i2Ctx, reg); |     error = mraa_i2c_write_byte (m_i2Ctx, reg); | ||||||
|     error = mraa_i2c_write_byte (m_i2Ctx, data); |     error = mraa_i2c_write_byte (m_i2Ctx, data); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user