mirror of
https://github.com/clockworkpi/WiringPi.git
synced 2025-12-12 16:08:49 +01:00
Added in the PiGlow devLib extension driver.
Written some examples for the PiGlow board bumped wiringPi version
This commit is contained in:
parent
cbf6d642b5
commit
e25cbc0a62
2
build
2
build
@ -27,6 +27,8 @@ if [ x$1 = "xclean" ]; then
|
||||
echo -n "PiFace: " ; make clean
|
||||
cd ../q2w
|
||||
echo -n "Quick2Wire: " ; make clean
|
||||
cd ../PiGlow
|
||||
echo -n "PiGlow: " ; make clean
|
||||
exit
|
||||
fi
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
|
||||
#include "piGlow.h"
|
||||
|
||||
static int myBase ;
|
||||
#define PIGLOW_BASE 577
|
||||
|
||||
static int leg0 [6] = { 6, 7, 8, 5, 4, 9 } ;
|
||||
static int leg1 [6] = { 17, 16, 15, 13, 11, 10 } ;
|
||||
@ -54,7 +54,7 @@ void piGlow1 (const int leg, const int ring, const int intensity)
|
||||
else
|
||||
legLeds = leg2 ;
|
||||
|
||||
analogWrite (myBase + legLeds [ring], intensity) ;
|
||||
analogWrite (PIGLOW_BASE + legLeds [ring], intensity) ;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -65,7 +65,7 @@ void piGlow1 (const int leg, const int ring, const int intensity)
|
||||
|
||||
void piGlowLeg (const int leg, const int intensity)
|
||||
{
|
||||
int i ;
|
||||
int i ;
|
||||
int *legLeds ;
|
||||
|
||||
if ((leg < 0) || (leg > 2))
|
||||
@ -79,7 +79,7 @@ void piGlowLeg (const int leg, const int intensity)
|
||||
legLeds = leg2 ;
|
||||
|
||||
for (i = 0 ; i < 6 ; ++i)
|
||||
analogWrite (myBase + legLeds [i], intensity) ;
|
||||
analogWrite (PIGLOW_BASE + legLeds [i], intensity) ;
|
||||
}
|
||||
|
||||
|
||||
@ -94,9 +94,9 @@ void piGlowRing (const int ring, const int intensity)
|
||||
if ((ring < 0) || (ring > 5))
|
||||
return ;
|
||||
|
||||
analogWrite (myBase + leg0 [ring], intensity) ;
|
||||
analogWrite (myBase + leg1 [ring], intensity) ;
|
||||
analogWrite (myBase + leg2 [ring], intensity) ;
|
||||
analogWrite (PIGLOW_BASE + leg0 [ring], intensity) ;
|
||||
analogWrite (PIGLOW_BASE + leg1 [ring], intensity) ;
|
||||
analogWrite (PIGLOW_BASE + leg2 [ring], intensity) ;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -105,13 +105,14 @@ void piGlowRing (const int ring, const int intensity)
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void piGlowSetup (const int pinBase)
|
||||
void piGlowSetup (int clear)
|
||||
{
|
||||
sn3218Setup (myBase = pinBase) ;
|
||||
sn3218Setup (PIGLOW_BASE) ;
|
||||
|
||||
// Turn all off to start with
|
||||
|
||||
piGlowLeg (0, 0) ;
|
||||
piGlowLeg (1, 0) ;
|
||||
piGlowLeg (2, 0) ;
|
||||
if (clear)
|
||||
{
|
||||
piGlowLeg (0, 0) ;
|
||||
piGlowLeg (1, 0) ;
|
||||
piGlowLeg (2, 0) ;
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,6 +22,15 @@
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
|
||||
#define PIGLOW_RED 0
|
||||
#define PIGLOW_YELLOW 1
|
||||
#define PIGLOW_ORANGE 2
|
||||
#define PIGLOW_GREEN 3
|
||||
#define PIGLOW_BLUE 4
|
||||
#define PIGLOW_WHITE 5
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -29,7 +38,7 @@ extern "C" {
|
||||
extern void piGlow1 (const int leg, const int ring, const int intensity) ;
|
||||
extern void piGlowLeg (const int leg, const int intensity) ;
|
||||
extern void piGlowRing (const int ring, const int intensity) ;
|
||||
extern void piGlowSetup (const int pinBase) ;
|
||||
extern void piGlowSetup (int clear) ;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ LDLIBS = -lwiringPi -lwiringPiDev -lpthread -lm
|
||||
# Should not alter anything below this line
|
||||
###############################################################################
|
||||
|
||||
SRC = piGlow0.c piGlow1.c
|
||||
SRC = piGlow0.c piGlow1.c piglow.c
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
@ -51,6 +51,10 @@ piGlow1: piGlow1.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ piGlow1.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
piglow: piglow.o
|
||||
@echo [link]
|
||||
@$(CC) -o $@ piglow.o $(LDFLAGS) $(LDLIBS)
|
||||
|
||||
.c.o:
|
||||
@echo [CC] $<
|
||||
@$(CC) -c $(CFLAGS) $< -o $@
|
||||
@ -63,6 +67,12 @@ tags: $(SRC)
|
||||
@echo [ctags]
|
||||
@ctags $(SRC)
|
||||
|
||||
install: piglow
|
||||
@echo Installing piglow into /usr/local/bin
|
||||
@cp -a piglow /usr/local/bin/piglow
|
||||
@chmod 755 /usr/local/bin/piglow
|
||||
@echo Done. Remember to load the I2C drivers!
|
||||
|
||||
depend:
|
||||
makedepend -Y $(SRC)
|
||||
|
||||
|
||||
@ -32,6 +32,11 @@
|
||||
|
||||
#define PIGLOW_BASE 533
|
||||
|
||||
#ifndef TRUE
|
||||
# define TRUE (1==1)
|
||||
# define FALSE (!TRUE)
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* keypressed: clearKeypressed:
|
||||
@ -123,6 +128,37 @@ static void pulseRing (int ring)
|
||||
}
|
||||
}
|
||||
|
||||
#define LEG_STEPS 3
|
||||
|
||||
static int legSequence [] =
|
||||
{
|
||||
4, 12, 99,
|
||||
99, 4, 12,
|
||||
12, 99, 4,
|
||||
} ;
|
||||
|
||||
|
||||
#define RING_STEPS 16
|
||||
|
||||
static int ringSequence [] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 64,
|
||||
0, 0, 0, 0, 64, 64,
|
||||
0, 0, 0, 64, 64, 0,
|
||||
0, 0, 64, 64, 0, 0,
|
||||
0, 64, 64, 0, 0, 0,
|
||||
64, 64, 0, 0, 0, 0,
|
||||
64, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
64, 0, 0, 0, 0, 0,
|
||||
64, 64, 0, 0, 0, 0,
|
||||
0, 64, 64, 0, 0, 0,
|
||||
0, 0, 64, 64, 0, 0,
|
||||
0, 0, 0, 64, 64, 0,
|
||||
0, 0, 0, 0, 64, 64,
|
||||
0, 0, 0, 0, 0, 64,
|
||||
0, 0, 0, 0, 0, 0,
|
||||
} ;
|
||||
|
||||
/*
|
||||
* main:
|
||||
@ -133,7 +169,7 @@ static void pulseRing (int ring)
|
||||
int main (void)
|
||||
{
|
||||
int i ;
|
||||
int ring, leg ;
|
||||
int step, ring, leg ;
|
||||
|
||||
// Always initialise wiringPi:
|
||||
// Use the Sys method if you don't need to run as root
|
||||
@ -142,7 +178,7 @@ int main (void)
|
||||
|
||||
// Initialise the piGlow devLib with our chosen pin base
|
||||
|
||||
piGlowSetup (PIGLOW_BASE) ;
|
||||
piGlowSetup (1) ;
|
||||
|
||||
// LEDs, one at a time
|
||||
|
||||
@ -190,28 +226,27 @@ int main (void)
|
||||
// Sequence - alternating rings, legs and random
|
||||
|
||||
printf ("Sequence now\n") ;
|
||||
|
||||
for (; !keypressed () ;)
|
||||
{
|
||||
for (i = 0 ; i < 20 ; ++i)
|
||||
for (leg = 2 ; leg >= 0 ; --leg)
|
||||
for (step = 0 ; step < LEG_STEPS ; ++step)
|
||||
{
|
||||
piGlowLeg (leg, 100) ;
|
||||
delay (100) ;
|
||||
piGlowLeg (leg, 0) ;
|
||||
for (leg = 0 ; leg < 3 ; ++leg)
|
||||
piGlowLeg (leg, legSequence [step * 3 + leg]) ;
|
||||
delay (80) ;
|
||||
}
|
||||
|
||||
for (i = 0 ; i < 20 ; ++i)
|
||||
for (ring = 5 ; ring >= 0 ; --ring)
|
||||
for (i = 0 ; i < 10 ; ++i)
|
||||
for (step = 0 ; step < RING_STEPS ; ++step)
|
||||
{
|
||||
piGlowRing (ring, 100) ;
|
||||
delay (50) ;
|
||||
piGlowRing (ring, 0) ;
|
||||
for (ring = 0 ; ring < 6 ; ++ring)
|
||||
piGlowRing (ring, ringSequence [step * 6 + ring]) ;
|
||||
delay (80) ;
|
||||
}
|
||||
|
||||
for (i = 0 ; i < 1000 ; ++i)
|
||||
{
|
||||
leg = random () % 3 ;
|
||||
leg = random () % 3 ;
|
||||
ring = random () % 6 ;
|
||||
piGlow1 (leg, ring, random () % 256) ;
|
||||
delay (5) ;
|
||||
|
||||
176
examples/PiGlow/piglow.c
Normal file
176
examples/PiGlow/piglow.c
Normal file
@ -0,0 +1,176 @@
|
||||
/*
|
||||
* piglow.c:
|
||||
* Very simple demonstration of the PiGlow board.
|
||||
* This uses the piGlow devLib.
|
||||
*
|
||||
* Copyright (c) 2013 Gordon Henderson.
|
||||
***********************************************************************
|
||||
* This file is part of wiringPi:
|
||||
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
||||
*
|
||||
* wiringPi is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wiringPi is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef TRUE
|
||||
# define TRUE (1==1)
|
||||
# define FALSE (!TRUE)
|
||||
#endif
|
||||
|
||||
#include <wiringPi.h>
|
||||
#include <piGlow.h>
|
||||
|
||||
static void failUsage (void)
|
||||
{
|
||||
fprintf (stderr, "Usage examples:\n") ;
|
||||
fprintf (stderr, " piglow off # All off\n") ;
|
||||
fprintf (stderr, " piglow red 50 # Light the 3 red LEDs to 50%%\n") ;
|
||||
fprintf (stderr, " colours are: red, yellow, orange, green, blue and white\n") ;
|
||||
fprintf (stderr, " piglow all 75 # Light all to 75%%\n") ;
|
||||
fprintf (stderr, " piglow leg 0 25 # Light leg 0 to 25%%\n") ;
|
||||
fprintf (stderr, " piglow ring 3 100 # Light ring 3 to 100%%\n") ;
|
||||
fprintf (stderr, " piglow led 2 5 100 # Light the single LED on Leg 2, ring 5 to 100%%\n") ;
|
||||
|
||||
exit (EXIT_FAILURE) ;
|
||||
}
|
||||
|
||||
static int getPercent (char *typed)
|
||||
{
|
||||
int percent ;
|
||||
|
||||
percent = atoi (typed) ;
|
||||
if ((percent < 0) || (percent > 100))
|
||||
{
|
||||
fprintf (stderr, "piglow: percent value out of range\n") ;
|
||||
exit (EXIT_FAILURE) ;
|
||||
}
|
||||
return (percent * 255) / 100 ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* main:
|
||||
* Our little demo prgoram
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
int main (int argc, char *argv [])
|
||||
{
|
||||
int percent ;
|
||||
int ring, leg ;
|
||||
|
||||
// Always initialise wiringPi:
|
||||
// Use the Sys method if you don't need to run as root
|
||||
|
||||
wiringPiSetupSys () ;
|
||||
|
||||
// Initialise the piGlow devLib
|
||||
|
||||
piGlowSetup (FALSE) ;
|
||||
|
||||
if (argc == 1)
|
||||
failUsage () ;
|
||||
|
||||
if ((argc == 2) && (strcasecmp (argv [1], "off") == 0))
|
||||
{
|
||||
for (leg = 0 ; leg < 3 ; ++leg)
|
||||
piGlowLeg (leg, 0) ;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
if (argc == 3)
|
||||
{
|
||||
percent = getPercent (argv [2]) ;
|
||||
|
||||
/**/ if (strcasecmp (argv [1], "red") == 0)
|
||||
piGlowRing (PIGLOW_RED, percent) ;
|
||||
else if (strcasecmp (argv [1], "yellow") == 0)
|
||||
piGlowRing (PIGLOW_YELLOW, percent) ;
|
||||
else if (strcasecmp (argv [1], "orange") == 0)
|
||||
piGlowRing (PIGLOW_ORANGE, percent) ;
|
||||
else if (strcasecmp (argv [1], "green") == 0)
|
||||
piGlowRing (PIGLOW_GREEN, percent) ;
|
||||
else if (strcasecmp (argv [1], "blue") == 0)
|
||||
piGlowRing (PIGLOW_BLUE, percent) ;
|
||||
else if (strcasecmp (argv [1], "white") == 0)
|
||||
piGlowRing (PIGLOW_WHITE, percent) ;
|
||||
else if (strcasecmp (argv [1], "all") == 0)
|
||||
for (ring = 0 ; ring < 6 ; ++ring)
|
||||
piGlowRing (ring, percent) ;
|
||||
else
|
||||
{
|
||||
fprintf (stderr, "piglow: invalid colour\n") ;
|
||||
exit (EXIT_FAILURE) ;
|
||||
}
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
if (argc == 4)
|
||||
{
|
||||
/**/ if (strcasecmp (argv [1], "leg") == 0)
|
||||
{
|
||||
leg = atoi (argv [2]) ;
|
||||
if ((leg < 0) || (leg > 2))
|
||||
{
|
||||
fprintf (stderr, "piglow: leg value out of range\n") ;
|
||||
exit (EXIT_FAILURE) ;
|
||||
}
|
||||
percent = getPercent (argv [3]) ;
|
||||
piGlowLeg (leg, percent) ;
|
||||
}
|
||||
else if (strcasecmp (argv [1], "ring") == 0)
|
||||
{
|
||||
ring = atoi (argv [2]) ;
|
||||
if ((ring < 0) || (ring > 5))
|
||||
{
|
||||
fprintf (stderr, "piglow: ring value out of range\n") ;
|
||||
exit (EXIT_FAILURE) ;
|
||||
}
|
||||
percent = getPercent (argv [3]) ;
|
||||
piGlowRing (ring, percent) ;
|
||||
}
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
if (argc == 5)
|
||||
{
|
||||
if (strcasecmp (argv [1], "led") != 0)
|
||||
failUsage () ;
|
||||
|
||||
leg = atoi (argv [2]) ;
|
||||
if ((leg < 0) || (leg > 2))
|
||||
{
|
||||
fprintf (stderr, "piglow: leg value out of range\n") ;
|
||||
exit (EXIT_FAILURE) ;
|
||||
}
|
||||
ring = atoi (argv [3]) ;
|
||||
if ((ring < 0) || (ring > 5))
|
||||
{
|
||||
fprintf (stderr, "piglow: ring value out of range\n") ;
|
||||
exit (EXIT_FAILURE) ;
|
||||
}
|
||||
percent = getPercent (argv [4]) ;
|
||||
piGlow1 (leg, ring, percent) ;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
failUsage () ;
|
||||
return 0 ;
|
||||
}
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ extern void doReadallOld (void) ;
|
||||
# define FALSE (1==2)
|
||||
#endif
|
||||
|
||||
#define VERSION "2.10"
|
||||
#define VERSION "2.11"
|
||||
#define I2CDETECT "/usr/sbin/i2cdetect"
|
||||
|
||||
int wpMode ;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user