my9221: rewrite to include new functionality and serve as a base class

This driver has been rewritten to support some new functionality, be
more generic and fix up some old bugs.  Multiple MY9221's can now be
chained together and are supported by the MY9221 base class.

In addition, the Grove LED Bar and Grove Circular LED drivers have
been incoporated into the my9221 library, using the new MY9221 class
as their base class.  Examples have been fixed to work with the new
library, and renamed where needed.

The current grovecircularled driver has been removed as it is now a
part of the my9221 library.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Jon Trulson
2015-12-03 18:21:54 -07:00
committed by Mihai Tudor Panu
parent 71b0791239
commit cbb289438e
11 changed files with 683 additions and 156 deletions

View File

@ -43,9 +43,9 @@ int main()
//! [Interesting]
// Instantiate a Grove Circular LED on gpio pins 5 and 4
// Instantiate a Grove Circular LED on D9 for data, D8 for clock
upm::GroveCircularLED *circle = new upm::GroveCircularLED(5, 4);
upm::GroveCircularLED *circle = new upm::GroveCircularLED(9, 8);
int level = 0;
while (shouldRun)
@ -54,6 +54,7 @@ int main()
level = (level + 1) % 24;
usleep(100000);
}
//! [Interesting]
cout << "Exiting" << endl;

View File

@ -27,37 +27,36 @@
#include "my9221.h"
#include <signal.h>
int running = 0;
int shouldRun = true;
void
sig_handler(int signo)
void sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
running = 1;
}
if (signo == SIGINT)
shouldRun = false;
}
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
//! [Interesting]
upm::MY9221 *bar = new upm::MY9221(8, 9);
signal(SIGINT, sig_handler);
signal(SIGINT, sig_handler);
//! [Interesting]
upm::MY9221 *bar = new upm::MY9221(8, 9);
while (!running) {
for (int idx = 1; idx < 11; idx++) {
bar->setBarLevel (idx);
usleep(1000);
// Green to Red
bar->setBarDirection(true);
while (shouldRun)
{
for (int i = 0; i < 11; i++)
{
bar->setBarLevel(i);
usleep(250000);
}
}
//! [Interesting]
//! [Interesting]
std::cout << "exiting application" << std::endl;
std::cout << "Existing..." << std::endl;
delete bar;
delete bar;
return 0;
return 0;
}

View File

@ -25,7 +25,7 @@
#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "my9221.h"
#include "groveledbar.h"
using namespace std;
@ -44,26 +44,25 @@ int main ()
//! [Interesting]
// Instantiate a MY9221, we use D2 for the data, and D3 for the
// data clock. This was tested with a Grove LED bar.
upm::MY9221* bar = new upm::MY9221(2, 3);
// Instantiate a GroveLEDBar, we use D8 for the data, and D9 for the
// clock. This was tested with a Grove LED bar.
upm::GroveLEDBar* bar = new upm::GroveLEDBar(8, 9);
while (shouldRun)
{
// count up from green to red
for (int i=1; i<=10; i++)
for (int i=0; i<=10; i++)
{
bar->setBarLevel(i, true);
usleep(50000);
usleep(100000);
}
sleep(1);
// count down from red to green
for (int i=1; i<=10; i++)
for (int i=0; i<=10; i++)
{
bar->setBarLevel(i, false);
usleep(50000);
usleep(100000);
}
sleep(1);
}
@ -71,7 +70,7 @@ int main ()
cout << "Exiting..." << endl;
// turn off the LED's
bar->setBarLevel(0, true);
bar->setBarLevel(0);
delete bar;
return 0;