mirror of
https://github.com/eclipse/upm.git
synced 2025-07-08 04:41:12 +03:00
my9221: C implementation; C example; C++ wraps C
Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
@ -35,118 +35,96 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <mraa/common.hpp>
|
||||
#include <mraa/gpio.hpp>
|
||||
#include <my9221.h>
|
||||
|
||||
namespace upm {
|
||||
|
||||
/**
|
||||
* @brief MY9221 LED Controller library
|
||||
* @defgroup my9221 libupm-my9221
|
||||
* @ingroup seeed display gpio eak
|
||||
*/
|
||||
class MY9221 {
|
||||
public:
|
||||
|
||||
// 12 LED channels per chip (instance)
|
||||
static const int LEDS_PER_INSTANCE = 12;
|
||||
|
||||
/**
|
||||
* Instantiates an MY9221 object
|
||||
*
|
||||
* @param dataPin Data pin
|
||||
* @param clockPin Clock pin
|
||||
* @param instances Number of daisy-chained my9221s, default 1
|
||||
* @brief MY9221 LED Controller library
|
||||
* @defgroup my9221 libupm-my9221
|
||||
* @ingroup seeed display gpio eak
|
||||
*/
|
||||
MY9221(uint8_t dataPin, uint8_t clockPin, int instances=1);
|
||||
class MY9221 {
|
||||
public:
|
||||
|
||||
/**
|
||||
* MY9221 destructor
|
||||
*/
|
||||
virtual ~MY9221();
|
||||
/**
|
||||
* Instantiates an MY9221 object
|
||||
*
|
||||
* @param dataPin Data pin
|
||||
* @param clockPin Clock pin
|
||||
* @param instances Number of daisy-chained my9221s, default 1
|
||||
*/
|
||||
MY9221(uint8_t dataPin, uint8_t clockPin, int instances=1);
|
||||
|
||||
/**
|
||||
* Enable or disable auto refresh. When auto refresh is enabled,
|
||||
* update the LED display as soon as the internal state changes.
|
||||
* When false, the display(s) will not be updated until the
|
||||
* refresh() method is called.
|
||||
*
|
||||
* @param enable true to enable auto refresh, false otherwise
|
||||
*/
|
||||
void setAutoRefresh(bool enable)
|
||||
{
|
||||
m_autoRefresh = enable;
|
||||
}
|
||||
/**
|
||||
* MY9221 destructor
|
||||
*/
|
||||
virtual ~MY9221();
|
||||
|
||||
/**
|
||||
* Set an LED to a specific on (high intensity) or off (low
|
||||
* intensity) value.
|
||||
*
|
||||
* @param led The LED whose state you wish to change
|
||||
* @param on true to turn on the LED, false to turn the LED off
|
||||
*/
|
||||
void setLED(int led, bool on);
|
||||
/**
|
||||
* Enable or disable auto refresh. When auto refresh is enabled,
|
||||
* update the LED display as soon as the internal state changes.
|
||||
* When false, the display(s) will not be updated until the
|
||||
* refresh() method is called.
|
||||
*
|
||||
* @param enable true to enable auto refresh, false otherwise
|
||||
*/
|
||||
void setAutoRefresh(bool enable)
|
||||
{
|
||||
my9221_set_auto_refresh(m_my9221, enable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the greyscale intensity of an LED in the OFF state. The
|
||||
* intensity is a value from 0 (fully off) to 255 (fully on).
|
||||
* This will take effect on any future LED set or clear
|
||||
* operations.
|
||||
*
|
||||
* @param intensity a value from 0 (fully off) to 255 (fully on)
|
||||
*/
|
||||
void setLowIntensityValue(int intensity);
|
||||
/**
|
||||
* Set an LED to a specific on (high intensity) or off (low
|
||||
* intensity) value.
|
||||
*
|
||||
* @param led The LED whose state you wish to change
|
||||
* @param on true to turn on the LED, false to turn the LED off
|
||||
*/
|
||||
void setLED(int led, bool on);
|
||||
|
||||
/**
|
||||
* Set the greyscale intensity of an LED in the ON state. The
|
||||
* intensity is a value from 0 (fully off) to 255 (fully on).
|
||||
* This will take effect on any future LED set or clear
|
||||
* operations.
|
||||
*
|
||||
* @param intensity a value from 0 (fully off) to 255 (fully on)
|
||||
*/
|
||||
void setHighIntensityValue(int intensity);
|
||||
/**
|
||||
* Set the greyscale intensity of an LED in the OFF state. The
|
||||
* intensity is a value from 0 (fully off) to 255 (fully on).
|
||||
* This will take effect on any future LED set or clear
|
||||
* operations.
|
||||
*
|
||||
* @param intensity a value from 0 (fully off) to 255 (fully on)
|
||||
*/
|
||||
void setLowIntensityValue(int intensity);
|
||||
|
||||
/**
|
||||
* Set all of the LEDS to the ON (high intensity value) state.
|
||||
*/
|
||||
void setAll();
|
||||
/**
|
||||
* Set the greyscale intensity of an LED in the ON state. The
|
||||
* intensity is a value from 0 (fully off) to 255 (fully on).
|
||||
* This will take effect on any future LED set or clear
|
||||
* operations.
|
||||
*
|
||||
* @param intensity a value from 0 (fully off) to 255 (fully on)
|
||||
*/
|
||||
void setHighIntensityValue(int intensity);
|
||||
|
||||
/**
|
||||
* Set all of the LEDS to the OFF (low intensity value) state.
|
||||
*/
|
||||
void clearAll();
|
||||
/**
|
||||
* Set all of the LEDS to the ON (high intensity value) state.
|
||||
*/
|
||||
void setAll();
|
||||
|
||||
/**
|
||||
* Set the LED states to match the internal stored states. This
|
||||
* is useful when auto refresh (setAutoRefresh()) is false to
|
||||
* update the display.
|
||||
*/
|
||||
void refresh();
|
||||
/**
|
||||
* Set all of the LEDS to the OFF (low intensity value) state.
|
||||
*/
|
||||
void clearAll();
|
||||
|
||||
protected:
|
||||
virtual void lockData();
|
||||
virtual void send16bitBlock(uint16_t data);
|
||||
/**
|
||||
* Set the LED states to match the internal stored states. This
|
||||
* is useful when auto refresh (setAutoRefresh()) is false to
|
||||
* update the display.
|
||||
*/
|
||||
void refresh();
|
||||
|
||||
bool m_autoRefresh;
|
||||
// we're only doing 8-bit greyscale, so the high order bits are
|
||||
// always 0
|
||||
uint16_t m_lowIntensity;
|
||||
uint16_t m_highIntensity;
|
||||
protected:
|
||||
|
||||
unsigned int m_instances;
|
||||
my9221_context m_my9221;
|
||||
|
||||
mraa::Gpio m_gpioData;
|
||||
mraa::Gpio m_gpioClk;
|
||||
|
||||
// an array of uint16_t's representing our bit states (on/off)
|
||||
// intensities. Only the low 8 bits are used, but in the future
|
||||
// 16bit support can work here as well.
|
||||
uint16_t *m_bitStates;
|
||||
|
||||
uint16_t m_commandWord;
|
||||
|
||||
private:
|
||||
};
|
||||
private:
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user