1 /* 2 * Author: Jun Kato and Yevgeniy Kiveisha <yevgeniy.kiveisha (at) intel.com> 3 * Contributions: Jon Trulson <jtrulson (at) ics.com> 4 * Copyright (c) 2014 Intel Corporation. 5 * 6 * This module is based on the my9221 driver 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining 9 * a copy of this software and associated documentation files (the 10 * "Software"), to deal in the Software without restriction, including 11 * without limitation the rights to use, copy, modify, merge, publish, 12 * distribute, sublicense, and/or sell copies of the Software, and to 13 * permit persons to whom the Software is furnished to do so, subject to 14 * the following conditions: 15 * 16 * The above copyright notice and this permission notice shall be 17 * included in all copies or substantial portions of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 */ 27 #pragma once 28 29 #include <string> 30 #include <mraa/aio.hpp> 31 #include <mraa/common.hpp> 32 33 #include <mraa/gpio.hpp> 34 35 #define MAX_BIT_PER_BLOCK 16 36 #define CMDMODE 0x0000 37 #define BIT_HIGH 0x00ff 38 #define BIT_LOW 0x0000 39 40 #define HIGH 1 41 #define LOW 0 42 43 namespace upm { 44 45 /** 46 * @brief Grove Circular LED library 47 * @defgroup grovecircularled libupm-grovecircularled 48 * @ingroup seeed display gpio 49 */ 50 51 /** 52 * @library grovecircularled 53 * @sensor grovecircularled 54 * @comname Grove Circular LED 55 * @type display 56 * @man seeed 57 * @web http://www.seeedstudio.com/wiki/Grove_-_Circular_LED 58 * @con gpio 59 * 60 * @brief API for the Grove Circular LED module 61 * 62 * This is a circular LED ring based on the MY9221 chip. It is often used 63 * with a rotary encoder and has 24 controllable LEDs. 64 * 65 * @image html grovecircularled.jpg 66 * @snippet grovecircularled.cxx Interesting 67 */ 68 class GroveCircularLED { 69 public: 70 /** 71 * Instantiates an MY9221 object 72 * 73 * @param di Data pin 74 * @param dcki Clock pin 75 */ 76 GroveCircularLED (uint8_t di, uint8_t dcki); 77 78 /** 79 * Sets the lighting status 80 * 81 * @param level Selected level for the circular LED (0-24) 82 * @param direction Up or down; up is true and default 83 */ 84 mraa::Result setLevel (uint8_t level, bool direction=true); 85 86 /** 87 * Sets the spinner (lights up all the other LEDs but one) 88 * 89 * @param position Selected position for the spinner (0-23) 90 */ 91 mraa::Result setSpinner (uint8_t position); 92 93 /** 94 * Sets the lighting status 95 * 96 * @param status Boolean array (24 elements) 97 */ 98 mraa::Result setStatus (bool status[24]); 99 100 /** 101 * Returns the name of the component 102 */ 103 std::string name() 104 { 105 return m_name; 106 } 107 private: 108 mraa::Result lockData (); 109 mraa::Result send16bitBlock (short data); 110 111 std::string m_name; 112 mraa::Gpio m_clkPinCtx; 113 mraa::Gpio m_dataPinCtx; 114 }; 115 116 } 117