upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
rgbringcoder.hpp
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 
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 
118  void clearEncoderPosition() { m_counter = 0; };
119 
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::Gpio m_gpioEncA;
142  mraa::Gpio m_gpioEncB;
143 
144  mraa::Pwm m_pwmRed;
145  mraa::Pwm m_pwmGreen;
146  mraa::Pwm m_pwmBlue;
147 
148  static void interruptHandler(void *ctx);
149  volatile int m_counter;
150 
151  };
152 }
~RGBRingCoder()
Definition: rgbringcoder.cxx:98
API for the SparkFun* RGB RingCoder.
Definition: rgbringcoder.hpp:65
bool getButtonState()
Definition: rgbringcoder.cxx:177
C++ API wrapper for the bh1749 driver.
Definition: a110x.hpp:29
void clearEncoderPosition()
Definition: rgbringcoder.hpp:118
void setRGBLED(float r, float g, float b)
Definition: rgbringcoder.cxx:182
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:32