mirror of
				https://github.com/eclipse/upm.git
				synced 2025-10-31 23:24:20 +03:00 
			
		
		
		
	Added interface iButton
Signed-off-by: Stefan Andritoiu <stefan.andritoiu@gmail.com>
This commit is contained in:
		 Stefan Andritoiu
					Stefan Andritoiu
				
			
				
					committed by
					
						 Serban Waltter
						Serban Waltter
					
				
			
			
				
	
			
			
			 Serban Waltter
						Serban Waltter
					
				
			
						parent
						
							3dc21b1dc8
						
					
				
				
					commit
					b2441100fa
				
			
							
								
								
									
										44
									
								
								include/interfaces/iButton.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								include/interfaces/iButton.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,44 @@ | |||||||
|  | /* | ||||||
|  |  * Author: Mihai Stefanescu <mihai.stefanescu@rinftech.com> | ||||||
|  |  * Copyright (c) 2018 Intel Corporation. | ||||||
|  |  * | ||||||
|  |  * Permission is hereby granted, free of charge, to any person obtaining | ||||||
|  |  * a copy of this software and associated documentation files (the | ||||||
|  |  * "Software"), to deal in the Software without restriction, including | ||||||
|  |  * without limitation the rights to use, copy, modify, merge, publish, | ||||||
|  |  * distribute, sublicense, and/or sell copies of the Software, and to | ||||||
|  |  * permit persons to whom the Software is furnished to do so, subject to | ||||||
|  |  * the following conditions: | ||||||
|  |  * | ||||||
|  |  * The above copyright notice and this permission notice shall be | ||||||
|  |  * included in all copies or substantial portions of the Software. | ||||||
|  |  * | ||||||
|  |  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||||||
|  |  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||||||
|  |  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||||||
|  |  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||||||
|  |  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||||||
|  |  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||||||
|  |  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||||||
|  |  */ | ||||||
|  |  | ||||||
|  | #pragma once | ||||||
|  |  | ||||||
|  | namespace upm | ||||||
|  | { | ||||||
|  | /** | ||||||
|  |  * @brief Interface for Button sensors | ||||||
|  | */ | ||||||
|  |   class iButton | ||||||
|  |   { | ||||||
|  |   public: | ||||||
|  |     virtual ~iButton() {} | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Gets the current button press state. | ||||||
|  |      * | ||||||
|  |      * @returns Button state | ||||||
|  |      */ | ||||||
|  |     virtual bool isPressed() = 0; | ||||||
|  |   }; | ||||||
|  | } | ||||||
| @@ -59,6 +59,11 @@ int Button::value() | |||||||
|     return mraa_gpio_read(m_gpio); |     return mraa_gpio_read(m_gpio); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | bool Button::isPressed() | ||||||
|  | { | ||||||
|  |     return (bool) Button::value(); | ||||||
|  | } | ||||||
|  |  | ||||||
| void Button::installISR(mraa::Edge level, void (*isr)(void *), void *arg) | void Button::installISR(mraa::Edge level, void (*isr)(void *), void *arg) | ||||||
| { | { | ||||||
|   if (m_isrInstalled) |   if (m_isrInstalled) | ||||||
|   | |||||||
| @@ -28,6 +28,7 @@ | |||||||
|  |  | ||||||
| #include <string> | #include <string> | ||||||
| #include <mraa/gpio.hpp> | #include <mraa/gpio.hpp> | ||||||
|  | #include <interfaces/iButton.hpp> | ||||||
|  |  | ||||||
| namespace upm { | namespace upm { | ||||||
|  |  | ||||||
| @@ -54,7 +55,7 @@ namespace upm { | |||||||
|  * @image html button.jpg |  * @image html button.jpg | ||||||
|  * @snippet button.cxx Interesting |  * @snippet button.cxx Interesting | ||||||
|  */ |  */ | ||||||
| class Button{ | class Button : virtual public iButton { | ||||||
|     public: |     public: | ||||||
|         /** |         /** | ||||||
|          * button constructor |          * button constructor | ||||||
| @@ -79,6 +80,13 @@ class Button{ | |||||||
|          */ |          */ | ||||||
|         int value(); |         int value(); | ||||||
|  |  | ||||||
|  |         /** | ||||||
|  |          * Gets the current button press state. | ||||||
|  |          * | ||||||
|  |          * @returns Button state | ||||||
|  |          */ | ||||||
|  |          virtual bool isPressed(); | ||||||
|  |  | ||||||
|         /** |         /** | ||||||
|          * Installs an interrupt service routine (ISR) to be called when |          * Installs an interrupt service routine (ISR) to be called when | ||||||
|          * the button is activated or deactivated. |          * the button is activated or deactivated. | ||||||
|   | |||||||
| @@ -58,6 +58,11 @@ int GroveButton::value() | |||||||
|     return mraa_gpio_read(m_gpio); |     return mraa_gpio_read(m_gpio); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | bool GroveButton::isPressed() | ||||||
|  | { | ||||||
|  |     return (bool) GroveButton::value(); | ||||||
|  | } | ||||||
|  |  | ||||||
| void GroveButton::installISR(mraa::Edge level, void (*isr)(void *), void *arg) | void GroveButton::installISR(mraa::Edge level, void (*isr)(void *), void *arg) | ||||||
| { | { | ||||||
|   if (m_isrInstalled) |   if (m_isrInstalled) | ||||||
|   | |||||||
| @@ -29,6 +29,7 @@ | |||||||
| #include <string> | #include <string> | ||||||
| #include <mraa/gpio.hpp> | #include <mraa/gpio.hpp> | ||||||
| #include "grovebase.hpp" | #include "grovebase.hpp" | ||||||
|  | #include <interfaces/iButton.hpp> | ||||||
|  |  | ||||||
| namespace upm { | namespace upm { | ||||||
|  |  | ||||||
| @@ -51,7 +52,7 @@ namespace upm { | |||||||
|  * @image html grovebutton.jpg |  * @image html grovebutton.jpg | ||||||
|  * @snippet grove-grovebutton.cxx Interesting |  * @snippet grove-grovebutton.cxx Interesting | ||||||
|  */ |  */ | ||||||
| class GroveButton: public Grove { | class GroveButton: public Grove, virtual public iButton { | ||||||
|     public: |     public: | ||||||
|         /** |         /** | ||||||
|          * Grove button constructor |          * Grove button constructor | ||||||
| @@ -76,6 +77,13 @@ class GroveButton: public Grove { | |||||||
|          */ |          */ | ||||||
|         int value(); |         int value(); | ||||||
|  |  | ||||||
|  |         /** | ||||||
|  |          * Gets the current button press state. | ||||||
|  |          * | ||||||
|  |          * @returns Button state | ||||||
|  |          */ | ||||||
|  |          virtual bool isPressed(); | ||||||
|  |  | ||||||
|         /** |         /** | ||||||
|          * Installs an interrupt service routine (ISR) to be called when |          * Installs an interrupt service routine (ISR) to be called when | ||||||
|          * the button is activated or deactivated. |          * the button is activated or deactivated. | ||||||
|   | |||||||
| @@ -25,6 +25,7 @@ | |||||||
|  |  | ||||||
| #include <string> | #include <string> | ||||||
| #include <mraa/gpio.hpp> | #include <mraa/gpio.hpp> | ||||||
|  | #include <interfaces/iButton.hpp> | ||||||
|  |  | ||||||
| namespace upm { | namespace upm { | ||||||
| /** | /** | ||||||
| @@ -52,7 +53,7 @@ namespace upm { | |||||||
|  * @image html ttp223.jpg |  * @image html ttp223.jpg | ||||||
|  * @snippet ttp223.cxx Interesting |  * @snippet ttp223.cxx Interesting | ||||||
|  */ |  */ | ||||||
| class TTP223 { | class TTP223 : virtual public iButton { | ||||||
|     public: |     public: | ||||||
|         /** |         /** | ||||||
|          * TTP223 constructor |          * TTP223 constructor | ||||||
| @@ -85,7 +86,7 @@ class TTP223 { | |||||||
|          * |          * | ||||||
|          * @return True if touched, false otherwise |          * @return True if touched, false otherwise | ||||||
|          */ |          */ | ||||||
|         bool isPressed(); |         virtual bool isPressed(); | ||||||
|  |  | ||||||
|         /** |         /** | ||||||
|          * Installs an interrupt service routine (ISR) to be called when |          * Installs an interrupt service routine (ISR) to be called when | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user