upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
rgbringcoder.h
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Copyright (c) 2015 Intel Corporation.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 #pragma once
25 
26 #include <iostream>
27 #include <string>
28 #include <stdint.h>
29 #include <unistd.h>
30 
31 #include <mraa/gpio.hpp>
32 
33 #include <mraa/pwm.hpp>
34 
35 
36 namespace upm {
65  class RGBRingCoder {
66  public:
67 
83  RGBRingCoder(int en, int latch, int clear, int clk, int dat, int sw,
84  int encA, int encB, int red, int green, int blue);
85 
89  ~RGBRingCoder();
90 
91  /*
92  * Sets the state of the ring LEDs. This is a 16-bit value, where
93  * each bit corresponds to one of the ring LEDs. A 1 bit means
94  * that a specific LED is on, and a 0 bit means that a specific LED is
95  * off.
96  *
97  * @param bits Bits representing the state of each LED
98  */
99  void setRingLEDS(uint16_t bits);
100 
101  /*
102  * Returns the state of the button
103  *
104  * @return True if the button is pressed, false otherwise
105  */
106  bool getButtonState();
107 
108  /*
109  * Gets the current rotary encoder counter value
110  *
111  * @return Current counter value
112  */
113  int getEncoderPosition() { return m_counter; };
114 
115  /*
116  * Sets the encoder counter to 0
117  */
118  void clearEncoderPosition() { m_counter = 0; };
119 
120  /*
121  * Sets the intensity of the red, green, and blue LEDs. Values can
122  * be between 0.0 and 1.0. Lower is brighter, higher is dimmer.
123  *
124  * @param r Red value; valid values are 0.0-1.0
125  * @param g Green value; valid values are 0.0-1.0
126  * @param b Blue value; valid values are 0.0-1.0
127  */
128  void setRGBLED(float r, float g, float b);
129 
130  private:
131 
132  mraa::Gpio m_gpioEn;
133 
134  mraa::Gpio m_gpioLatch;
135  mraa::Gpio m_gpioClear;
136  mraa::Gpio m_gpioClock;
137  mraa::Gpio m_gpioData;
138 
139  mraa::Gpio m_gpioSwitch;
140 
141  mraa::Pwm m_pwmRed;
142  mraa::Pwm m_pwmGreen;
143  mraa::Pwm m_pwmBlue;
144 
145  mraa::Gpio m_gpioEncA;
146  mraa::Gpio m_gpioEncB;
147 
148  static void interruptHandler(void *ctx);
149  volatile int m_counter;
150 
151  };
152 }
153 
154 
~RGBRingCoder()
Definition: rgbringcoder.cxx:101
API for the SparkFun* RGB RingCoder.
Definition: rgbringcoder.h:65
RGBRingCoder(int en, int latch, int clear, int clk, int dat, int sw, int encA, int encB, int red, int green, int blue)
Definition: rgbringcoder.cxx:35