parent
f388d58fbd
commit
2204176408
@ -0,0 +1,8 @@
|
|||||||
|
all: bindings
|
||||||
|
python setup.py build
|
||||||
|
|
||||||
|
bindings:
|
||||||
|
swig2.0 -python wiringpi.i
|
||||||
|
|
||||||
|
install:
|
||||||
|
sudo python setup.py install
|
||||||
@ -0,0 +1,79 @@
|
|||||||
|
#
|
||||||
|
# Makefile:
|
||||||
|
# wiringPi - Wiring Compatable library for the Raspberry Pi
|
||||||
|
# https://projects.drogon.net/wiring-pi
|
||||||
|
#
|
||||||
|
# Copyright (c) 2012-2013 Gordon Henderson
|
||||||
|
#################################################################################
|
||||||
|
# This file is part of wiringPi:
|
||||||
|
# Wiring Compatable library for the Raspberry Pi
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
#################################################################################
|
||||||
|
|
||||||
|
|
||||||
|
#DEBUG = -g -O0
|
||||||
|
DEBUG = -O3
|
||||||
|
CC = gcc
|
||||||
|
INCLUDE = -I/usr/local/include
|
||||||
|
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe
|
||||||
|
|
||||||
|
LDFLAGS = -L/usr/local/lib
|
||||||
|
LDLIBS = -lwiringPi -lwiringPiDev -lpthread -lm
|
||||||
|
|
||||||
|
# Should not alter anything below this line
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
SRC = piGlow0.c piGlow1.c piglow.c
|
||||||
|
|
||||||
|
OBJ = $(SRC:.c=.o)
|
||||||
|
|
||||||
|
BINS = $(SRC:.c=)
|
||||||
|
|
||||||
|
all: $(BINS)
|
||||||
|
|
||||||
|
piGlow0: piGlow0.o
|
||||||
|
@echo [link]
|
||||||
|
@$(CC) -o $@ piGlow0.o $(LDFLAGS) $(LDLIBS)
|
||||||
|
|
||||||
|
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 $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@echo "[Clean]"
|
||||||
|
@rm -f $(OBJ) *~ core tags $(BINS)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
# DO NOT DELETE
|
||||||
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* piglow.c:
|
||||||
|
* Very simple demonstration of the PiGlow board.
|
||||||
|
* This uses the SN3218 directly - soon there will be a new PiGlow
|
||||||
|
* devLib device which will handle the PiGlow board on a more easy
|
||||||
|
* to use manner...
|
||||||
|
*
|
||||||
|
* 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 <wiringPi.h>
|
||||||
|
#include <sn3218.h>
|
||||||
|
|
||||||
|
#define LED_BASE 533
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
int i, j ;
|
||||||
|
|
||||||
|
wiringPiSetupSys () ;
|
||||||
|
|
||||||
|
sn3218Setup (LED_BASE) ;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
for (i = 0 ; i < 256 ; ++i)
|
||||||
|
for (j = 0 ; j < 18 ; ++j)
|
||||||
|
analogWrite (LED_BASE + j, i) ;
|
||||||
|
|
||||||
|
for (i = 255 ; i >= 0 ; --i)
|
||||||
|
for (j = 0 ; j < 18 ; ++j)
|
||||||
|
analogWrite (LED_BASE + j, i) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,258 @@
|
|||||||
|
/*
|
||||||
|
* piGlow1.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 <stdlib.h>
|
||||||
|
#include <poll.h>
|
||||||
|
|
||||||
|
#include <wiringPi.h>
|
||||||
|
#include <piGlow.h>
|
||||||
|
|
||||||
|
#define PIGLOW_BASE 533
|
||||||
|
|
||||||
|
#ifndef TRUE
|
||||||
|
# define TRUE (1==1)
|
||||||
|
# define FALSE (!TRUE)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* keypressed: clearKeypressed:
|
||||||
|
* Simple but effective ways to tell if the enter key has been pressed
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int keypressed (void)
|
||||||
|
{
|
||||||
|
struct pollfd polls ;
|
||||||
|
|
||||||
|
polls.fd = fileno (stdin) ;
|
||||||
|
polls.events = POLLIN ;
|
||||||
|
|
||||||
|
return poll (&polls, 1, 0) != 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void clearKeypressed (void)
|
||||||
|
{
|
||||||
|
while (keypressed ())
|
||||||
|
(void)getchar () ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pulseLed:
|
||||||
|
* Pulses the LED at position leg, ring from off to a max. value,
|
||||||
|
* then off again
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void pulseLed (int leg, int ring)
|
||||||
|
{
|
||||||
|
int i ;
|
||||||
|
|
||||||
|
for (i = 0 ; i < 140 ; ++i)
|
||||||
|
{
|
||||||
|
piGlow1 (leg, ring, i) ;
|
||||||
|
delay (1) ;
|
||||||
|
}
|
||||||
|
delay (10) ;
|
||||||
|
for (i = 140 ; i >= 0 ; --i)
|
||||||
|
{
|
||||||
|
piGlow1 (leg, ring, i) ;
|
||||||
|
delay (1) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pulseLeg:
|
||||||
|
* Same as above, but a whole leg at a time
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void pulseLeg (int leg)
|
||||||
|
{
|
||||||
|
int i ;
|
||||||
|
|
||||||
|
for (i = 0 ; i < 140 ; ++i)
|
||||||
|
{
|
||||||
|
piGlowLeg (leg, i) ; delay (1) ;
|
||||||
|
}
|
||||||
|
delay (10) ;
|
||||||
|
for (i = 140 ; i >= 0 ; --i)
|
||||||
|
{
|
||||||
|
piGlowLeg (leg, i) ; delay (1) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* pulse Ring:
|
||||||
|
* Same as above, but a whole ring at a time
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void pulseRing (int ring)
|
||||||
|
{
|
||||||
|
int i ;
|
||||||
|
|
||||||
|
for (i = 0 ; i < 140 ; ++i)
|
||||||
|
{
|
||||||
|
piGlowRing (ring, i) ; delay (1) ;
|
||||||
|
}
|
||||||
|
delay (10) ;
|
||||||
|
for (i = 140 ; i >= 0 ; --i)
|
||||||
|
{
|
||||||
|
piGlowRing (ring, i) ; delay (1) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#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:
|
||||||
|
* Our little demo prgoram
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
int i ;
|
||||||
|
int step, ring, leg ;
|
||||||
|
|
||||||
|
// Always initialise wiringPi:
|
||||||
|
// Use the Sys method if you don't need to run as root
|
||||||
|
|
||||||
|
wiringPiSetupSys () ;
|
||||||
|
|
||||||
|
// Initialise the piGlow devLib with our chosen pin base
|
||||||
|
|
||||||
|
piGlowSetup (1) ;
|
||||||
|
|
||||||
|
// LEDs, one at a time
|
||||||
|
|
||||||
|
printf ("LEDs, one at a time\n") ;
|
||||||
|
for (; !keypressed () ;)
|
||||||
|
for (leg = 0 ; leg < 3 ; ++leg)
|
||||||
|
{
|
||||||
|
for (ring = 0 ; ring < 6 ; ++ring)
|
||||||
|
{
|
||||||
|
pulseLed (leg, ring) ;
|
||||||
|
if (keypressed ())
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
if (keypressed ())
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
clearKeypressed () ;
|
||||||
|
|
||||||
|
// Rings, one at a time
|
||||||
|
|
||||||
|
printf ("Rings, one at a time\n") ;
|
||||||
|
for (; !keypressed () ;)
|
||||||
|
for (ring = 0 ; ring < 6 ; ++ring)
|
||||||
|
{
|
||||||
|
pulseRing (ring) ;
|
||||||
|
if (keypressed ())
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
clearKeypressed () ;
|
||||||
|
|
||||||
|
// Legs, one at a time
|
||||||
|
|
||||||
|
printf ("Legs, one at a time\n") ;
|
||||||
|
for (; !keypressed () ;)
|
||||||
|
for (leg = 0 ; leg < 3 ; ++leg)
|
||||||
|
{
|
||||||
|
pulseLeg (leg) ;
|
||||||
|
if (keypressed ())
|
||||||
|
break ;
|
||||||
|
}
|
||||||
|
clearKeypressed () ;
|
||||||
|
|
||||||
|
delay (1000) ;
|
||||||
|
|
||||||
|
// Sequence - alternating rings, legs and random
|
||||||
|
|
||||||
|
printf ("Sequence now\n") ;
|
||||||
|
for (; !keypressed () ;)
|
||||||
|
{
|
||||||
|
for (i = 0 ; i < 20 ; ++i)
|
||||||
|
for (step = 0 ; step < LEG_STEPS ; ++step)
|
||||||
|
{
|
||||||
|
for (leg = 0 ; leg < 3 ; ++leg)
|
||||||
|
piGlowLeg (leg, legSequence [step * 3 + leg]) ;
|
||||||
|
delay (80) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0 ; i < 10 ; ++i)
|
||||||
|
for (step = 0 ; step < RING_STEPS ; ++step)
|
||||||
|
{
|
||||||
|
for (ring = 0 ; ring < 6 ; ++ring)
|
||||||
|
piGlowRing (ring, ringSequence [step * 6 + ring]) ;
|
||||||
|
delay (80) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0 ; i < 1000 ; ++i)
|
||||||
|
{
|
||||||
|
leg = random () % 3 ;
|
||||||
|
ring = random () % 6 ;
|
||||||
|
piGlow1 (leg, ring, random () % 256) ;
|
||||||
|
delay (5) ;
|
||||||
|
piGlow1 (leg, ring, 0) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
@ -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 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,125 @@
|
|||||||
|
/*
|
||||||
|
* blink12drcs.c:
|
||||||
|
* Simple sequence over the first 12 GPIO pins - LEDs
|
||||||
|
* Aimed at the Gertboard, but it's fairly generic.
|
||||||
|
* This version uses DRC totalk to the ATmega on the Gertboard
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>
|
||||||
|
***********************************************************************
|
||||||
|
* 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 <wiringPi.h>
|
||||||
|
#include <drcSerial.h>
|
||||||
|
|
||||||
|
#define GERT_BASE 100
|
||||||
|
|
||||||
|
static int pinMap [] =
|
||||||
|
{
|
||||||
|
0, 1, 2, 3, // Pi Native
|
||||||
|
GERT_BASE + 2, GERT_BASE + 3, GERT_BASE + 4, GERT_BASE + 5,
|
||||||
|
GERT_BASE + 6, GERT_BASE + 7, GERT_BASE + 8, GERT_BASE + 9,
|
||||||
|
} ;
|
||||||
|
|
||||||
|
// Simple sequencer data
|
||||||
|
// Triplets of LED, On/Off and delay
|
||||||
|
|
||||||
|
|
||||||
|
int data [] =
|
||||||
|
{
|
||||||
|
0, 1, 1,
|
||||||
|
1, 1, 1,
|
||||||
|
0, 0, 0, 2, 1, 1,
|
||||||
|
1, 0, 0, 3, 1, 1,
|
||||||
|
2, 0, 0, 4, 1, 1,
|
||||||
|
3, 0, 0, 5, 1, 1,
|
||||||
|
4, 0, 0, 6, 1, 1,
|
||||||
|
5, 0, 0, 7, 1, 1,
|
||||||
|
6, 0, 0, 8, 1, 1,
|
||||||
|
7, 0, 0, 9, 1, 1,
|
||||||
|
8, 0, 0, 10, 1, 1,
|
||||||
|
9, 0, 0, 11, 1, 1,
|
||||||
|
10, 0, 1,
|
||||||
|
11, 0, 1,
|
||||||
|
|
||||||
|
0, 0, 1, // Extra delay
|
||||||
|
|
||||||
|
// Back again
|
||||||
|
|
||||||
|
11, 1, 1,
|
||||||
|
10, 1, 1,
|
||||||
|
11, 0, 0, 9, 1, 1,
|
||||||
|
10, 0, 0, 8, 1, 1,
|
||||||
|
9, 0, 0, 7, 1, 1,
|
||||||
|
8, 0, 0, 6, 1, 1,
|
||||||
|
7, 0, 0, 5, 1, 1,
|
||||||
|
6, 0, 0, 4, 1, 1,
|
||||||
|
5, 0, 0, 3, 1, 1,
|
||||||
|
4, 0, 0, 2, 1, 1,
|
||||||
|
3, 0, 0, 1, 1, 1,
|
||||||
|
2, 0, 0, 0, 1, 1,
|
||||||
|
1, 0, 1,
|
||||||
|
0, 0, 1,
|
||||||
|
|
||||||
|
0, 0, 1, // Extra delay
|
||||||
|
|
||||||
|
0, 9, 0, // End marker
|
||||||
|
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
int pin ;
|
||||||
|
int dataPtr ;
|
||||||
|
int l, s, d ;
|
||||||
|
|
||||||
|
printf ("Raspberry Pi - 12-LED Sequence\n") ;
|
||||||
|
printf ("==============================\n") ;
|
||||||
|
printf ("\n") ;
|
||||||
|
printf ("Connect LEDs up to the first 4 Pi pins and 8 pins on the ATmega\n") ;
|
||||||
|
printf (" from PD2 through PB1 in that order,\n") ;
|
||||||
|
printf (" then sit back and watch the show!\n") ;
|
||||||
|
|
||||||
|
wiringPiSetup () ;
|
||||||
|
drcSetupSerial (GERT_BASE, 20, "/dev/ttyAMA0", 115200) ;
|
||||||
|
|
||||||
|
for (pin = 0 ; pin < 12 ; ++pin)
|
||||||
|
pinMode (pinMap [pin], OUTPUT) ;
|
||||||
|
|
||||||
|
dataPtr = 0 ;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
l = data [dataPtr++] ; // LED
|
||||||
|
s = data [dataPtr++] ; // State
|
||||||
|
d = data [dataPtr++] ; // Duration (10ths)
|
||||||
|
|
||||||
|
if (s == 9) // 9 -> End Marker
|
||||||
|
{
|
||||||
|
dataPtr = 0 ;
|
||||||
|
continue ;
|
||||||
|
}
|
||||||
|
|
||||||
|
digitalWrite (pinMap [l], s) ;
|
||||||
|
delay (d * analogRead (GERT_BASE) / 4) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
* blink6drcs.c:
|
||||||
|
* Simple sequence over 6 pins on a remote DRC board.
|
||||||
|
* Aimed at the Gertduino, but it's fairly generic.
|
||||||
|
* This version uses DRC to talk to the ATmega on the Gertduino
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012-2014 Gordon Henderson. <projects@drogon.net>
|
||||||
|
***********************************************************************
|
||||||
|
* 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 <wiringPi.h>
|
||||||
|
#include <drcSerial.h>
|
||||||
|
|
||||||
|
#define GERT_BASE 100
|
||||||
|
|
||||||
|
static int pinMap [] =
|
||||||
|
{
|
||||||
|
GERT_BASE + 6, GERT_BASE + 5, GERT_BASE + 3, GERT_BASE + 10, GERT_BASE + 9, GERT_BASE + 13,
|
||||||
|
} ;
|
||||||
|
|
||||||
|
// Simple sequencer data
|
||||||
|
// Triplets of LED, On/Off and delay
|
||||||
|
|
||||||
|
|
||||||
|
int data [] =
|
||||||
|
{
|
||||||
|
0, 1, 1,
|
||||||
|
1, 1, 1,
|
||||||
|
0, 0, 0, 2, 1, 1,
|
||||||
|
1, 0, 0, 3, 1, 1,
|
||||||
|
2, 0, 0, 4, 1, 1,
|
||||||
|
3, 0, 0, 5, 1, 1,
|
||||||
|
4, 0, 1,
|
||||||
|
5, 0, 1,
|
||||||
|
|
||||||
|
0, 0, 1, // Extra delay
|
||||||
|
|
||||||
|
// Back again
|
||||||
|
|
||||||
|
5, 1, 1,
|
||||||
|
4, 1, 1,
|
||||||
|
5, 0, 0, 3, 1, 1,
|
||||||
|
4, 0, 0, 2, 1, 1,
|
||||||
|
3, 0, 0, 1, 1, 1,
|
||||||
|
2, 0, 0, 0, 1, 1,
|
||||||
|
1, 0, 1,
|
||||||
|
0, 0, 1,
|
||||||
|
|
||||||
|
0, 0, 1, // Extra delay
|
||||||
|
|
||||||
|
0, 9, 0, // End marker
|
||||||
|
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
int pin ;
|
||||||
|
int dataPtr ;
|
||||||
|
int l, s, d ;
|
||||||
|
|
||||||
|
printf ("Raspberry Pi - 6-LED Sequence\n") ;
|
||||||
|
printf ("=============================\n") ;
|
||||||
|
printf ("\n") ;
|
||||||
|
printf (" Use the 2 buttons to temporarily speed up the sequence\n") ;
|
||||||
|
|
||||||
|
wiringPiSetupSys () ; // Not using the Pi's GPIO here
|
||||||
|
drcSetupSerial (GERT_BASE, 20, "/dev/ttyAMA0", 115200) ;
|
||||||
|
|
||||||
|
for (pin = 0 ; pin < 6 ; ++pin)
|
||||||
|
pinMode (pinMap [pin], OUTPUT) ;
|
||||||
|
|
||||||
|
pinMode (GERT_BASE + 16, INPUT) ; // Buttons
|
||||||
|
pinMode (GERT_BASE + 17, INPUT) ;
|
||||||
|
|
||||||
|
pullUpDnControl (GERT_BASE + 16, PUD_UP) ;
|
||||||
|
pullUpDnControl (GERT_BASE + 17, PUD_UP) ;
|
||||||
|
|
||||||
|
dataPtr = 0 ;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
l = data [dataPtr++] ; // LED
|
||||||
|
s = data [dataPtr++] ; // State
|
||||||
|
d = data [dataPtr++] ; // Duration (10ths)
|
||||||
|
|
||||||
|
if (s == 9) // 9 -> End Marker
|
||||||
|
{
|
||||||
|
dataPtr = 0 ;
|
||||||
|
continue ;
|
||||||
|
}
|
||||||
|
|
||||||
|
digitalWrite (pinMap [l], s) ;
|
||||||
|
delay (d * digitalRead (GERT_BASE + 16) * 15 + digitalRead (GERT_BASE + 17) * 20) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
@ -0,0 +1,238 @@
|
|||||||
|
/*
|
||||||
|
* ds1302.c:
|
||||||
|
* Real Time clock
|
||||||
|
*
|
||||||
|
* 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 <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include <wiringPi.h>
|
||||||
|
#include <ds1302.h>
|
||||||
|
|
||||||
|
// Register defines
|
||||||
|
|
||||||
|
#define RTC_SECS 0
|
||||||
|
#define RTC_MINS 1
|
||||||
|
#define RTC_HOURS 2
|
||||||
|
#define RTC_DATE 3
|
||||||
|
#define RTC_MONTH 4
|
||||||
|
#define RTC_DAY 5
|
||||||
|
#define RTC_YEAR 6
|
||||||
|
#define RTC_WP 7
|
||||||
|
#define RTC_TC 8
|
||||||
|
#define RTC_BM 31
|
||||||
|
|
||||||
|
|
||||||
|
static unsigned int masks [] = { 0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0x07, 0xFF } ;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bcdToD: dToBCD:
|
||||||
|
* BCD decode/encode
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int bcdToD (unsigned int byte, unsigned int mask)
|
||||||
|
{
|
||||||
|
unsigned int b1, b2 ;
|
||||||
|
byte &= mask ;
|
||||||
|
b1 = byte & 0x0F ;
|
||||||
|
b2 = ((byte >> 4) & 0x0F) * 10 ;
|
||||||
|
return b1 + b2 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned int dToBcd (unsigned int byte)
|
||||||
|
{
|
||||||
|
return ((byte / 10) << 4) + (byte % 10) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ramTest:
|
||||||
|
* Simple test of the 31 bytes of RAM inside the DS1302 chip
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int ramTestValues [] =
|
||||||
|
{ 0x00, 0xFF, 0xAA, 0x55, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0xF0, 0x0F, -1 } ;
|
||||||
|
|
||||||
|
static int ramTest (void)
|
||||||
|
{
|
||||||
|
int addr ;
|
||||||
|
int got ;
|
||||||
|
int i = 0 ;
|
||||||
|
int errors = 0 ;
|
||||||
|
int testVal ;
|
||||||
|
|
||||||
|
printf ("DS1302 RAM TEST\n") ;
|
||||||
|
|
||||||
|
testVal = ramTestValues [i] ;
|
||||||
|
|
||||||
|
while (testVal != -1)
|
||||||
|
{
|
||||||
|
for (addr = 0 ; addr < 31 ; ++addr)
|
||||||
|
ds1302ramWrite (addr, testVal) ;
|
||||||
|
|
||||||
|
for (addr = 0 ; addr < 31 ; ++addr)
|
||||||
|
if ((got = ds1302ramRead (addr)) != testVal)
|
||||||
|
{
|
||||||
|
printf ("DS1302 RAM Failure: Address: %2d, Expected: 0x%02X, Got: 0x%02X\n",
|
||||||
|
addr, testVal, got) ;
|
||||||
|
++errors ;
|
||||||
|
}
|
||||||
|
testVal = ramTestValues [++i] ;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (addr = 0 ; addr < 31 ; ++addr)
|
||||||
|
ds1302ramWrite (addr, addr) ;
|
||||||
|
|
||||||
|
for (addr = 0 ; addr < 31 ; ++addr)
|
||||||
|
if ((got = ds1302ramRead (addr)) != addr)
|
||||||
|
{
|
||||||
|
printf ("DS1302 RAM Failure: Address: %2d, Expected: 0x%02X, Got: 0x%02X\n",
|
||||||
|
addr, addr, got) ;
|
||||||
|
++errors ;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errors == 0)
|
||||||
|
printf ("-- DS1302 RAM TEST: OK\n") ;
|
||||||
|
else
|
||||||
|
printf ("-- DS1302 RAM TEST FAILURE. %d errors.\n", errors) ;
|
||||||
|
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* setLinuxClock:
|
||||||
|
* Set the Linux clock from the hardware
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int setLinuxClock (void)
|
||||||
|
{
|
||||||
|
char dateTime [20] ;
|
||||||
|
char command [64] ;
|
||||||
|
int clock [8] ;
|
||||||
|
|
||||||
|
|
||||||
|
printf ("Setting the Linux Clock from the DS1302... ") ; fflush (stdout) ;
|
||||||
|
|
||||||
|
ds1302clockRead (clock) ;
|
||||||
|
|
||||||
|
// [MMDDhhmm[[CC]YY][.ss]]
|
||||||
|
|
||||||
|
sprintf (dateTime, "%02d%02d%02d%02d%02d%02d.%02d",
|
||||||
|
bcdToD (clock [RTC_MONTH], masks [RTC_MONTH]),
|
||||||
|
bcdToD (clock [RTC_DATE], masks [RTC_DATE]),
|
||||||
|
bcdToD (clock [RTC_HOURS], masks [RTC_HOURS]),
|
||||||
|
bcdToD (clock [RTC_MINS], masks [RTC_MINS]),
|
||||||
|
20,
|
||||||
|
bcdToD (clock [RTC_YEAR], masks [RTC_YEAR]),
|
||||||
|
bcdToD (clock [RTC_SECS], masks [RTC_SECS])) ;
|
||||||
|
|
||||||
|
sprintf (command, "/bin/date %s", dateTime) ;
|
||||||
|
system (command) ;
|
||||||
|
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* setDSclock:
|
||||||
|
* Set the DS1302 block from Linux time
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
static int setDSclock (void)
|
||||||
|
{
|
||||||
|
struct tm t ;
|
||||||
|
time_t now ;
|
||||||
|
int clock [8] ;
|
||||||
|
|
||||||
|
printf ("Setting the clock in the DS1302 from Linux time... ") ;
|
||||||
|
|
||||||
|
now = time (NULL) ;
|
||||||
|
gmtime_r (&now, &t) ;
|
||||||
|
|
||||||
|
clock [ 0] = dToBcd (t.tm_sec) ; // seconds
|
||||||
|
clock [ 1] = dToBcd (t.tm_min) ; // mins
|
||||||
|
clock [ 2] = dToBcd (t.tm_hour) ; // hours
|
||||||
|
clock [ 3] = dToBcd (t.tm_mday) ; // date
|
||||||
|
clock [ 4] = dToBcd (t.tm_mon + 1) ; // months 0-11 --> 1-12
|
||||||
|
clock [ 5] = dToBcd (t.tm_wday + 1) ; // weekdays (sun 0)
|
||||||
|
clock [ 6] = dToBcd (t.tm_year - 100) ; // years
|
||||||
|
clock [ 7] = 0 ; // W-Protect off
|
||||||
|
|
||||||
|
ds1302clockWrite (clock) ;
|
||||||
|
|
||||||
|
printf ("OK\n") ;
|
||||||
|
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main (int argc, char *argv [])
|
||||||
|
{
|
||||||
|
int i ;
|
||||||
|
int clock [8] ;
|
||||||
|
|
||||||
|
wiringPiSetup () ;
|
||||||
|
ds1302setup (0, 1, 2) ;
|
||||||
|
|
||||||
|
if (argc == 2)
|
||||||
|
{
|
||||||
|
/**/ if (strcmp (argv [1], "-slc") == 0)
|
||||||
|
return setLinuxClock () ;
|
||||||
|
else if (strcmp (argv [1], "-sdsc") == 0)
|
||||||
|
return setDSclock () ;
|
||||||
|
else if (strcmp (argv [1], "-rtest") == 0)
|
||||||
|
return ramTest () ;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf ("Usage: ds1302 [-slc | -sdsc | -rtest]\n") ;
|
||||||
|
return EXIT_FAILURE ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0 ;; ++i)
|
||||||
|
{
|
||||||
|
printf ("%5d: ", i) ;
|
||||||
|
|
||||||
|
ds1302clockRead (clock) ;
|
||||||
|
printf (" %2d:%02d:%02d",
|
||||||
|
bcdToD (clock [2], masks [2]), bcdToD (clock [1], masks [1]), bcdToD (clock [0], masks [0])) ;
|
||||||
|
|
||||||
|
printf (" %2d/%02d/%04d",
|
||||||
|
bcdToD (clock [3], masks [3]), bcdToD (clock [4], masks [4]), bcdToD (clock [6], masks [6]) + 2000) ;
|
||||||
|
|
||||||
|
printf ("\n") ;
|
||||||
|
|
||||||
|
delay (200) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0 ;
|
||||||
|
}
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* pins.c:
|
||||||
|
* Just display a handy Pi pinnout diagram.
|
||||||
|
* Copyright (c) 2012-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>
|
||||||
|
|
||||||
|
void doPins (void)
|
||||||
|
{
|
||||||
|
printf ("The pins command has been deprecated - sorry. Please use the\n") ;
|
||||||
|
printf (" gpio readall\n") ;
|
||||||
|
printf ("command to get a list of the pinnouts for your Pi.\n") ;
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,321 @@
|
|||||||
|
/*
|
||||||
|
* readall.c:
|
||||||
|
* The readall functions - getting a bit big, so split them out.
|
||||||
|
* Copyright (c) 2012-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 <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include <wiringPi.h>
|
||||||
|
|
||||||
|
extern int wpMode ;
|
||||||
|
|
||||||
|
#ifndef TRUE
|
||||||
|
# define TRUE (1==1)
|
||||||
|
# define FALSE (1==2)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* doReadallExternal:
|
||||||
|
* A relatively crude way to read the pins on an external device.
|
||||||
|
* We don't know the input/output mode of pins, but we can tell
|
||||||
|
* if it's an analog pin or a digital one...
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void doReadallExternal (void)
|
||||||
|
{
|
||||||
|
int pin ;
|
||||||
|
|
||||||
|
printf ("+------+---------+--------+\n") ;
|
||||||
|
printf ("| Pin | Digital | Analog |\n") ;
|
||||||
|
printf ("+------+---------+--------+\n") ;
|
||||||
|
|
||||||
|
for (pin = wiringPiNodes->pinBase ; pin <= wiringPiNodes->pinMax ; ++pin)
|
||||||
|
printf ("| %4d | %4d | %4d |\n", pin, digitalRead (pin), analogRead (pin)) ;
|
||||||
|
|
||||||
|
printf ("+------+---------+--------+\n") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* doReadall:
|
||||||
|
* Read all the GPIO pins
|
||||||
|
* We also want to use this to read the state of pins on an externally
|
||||||
|
* connected device, so we need to do some fiddling with the internal
|
||||||
|
* wiringPi node structures - since the gpio command can only use
|
||||||
|
* one external device at a time, we'll use that to our advantage...
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
static char *alts [] =
|
||||||
|
{
|
||||||
|
"IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3"
|
||||||
|
} ;
|
||||||
|
|
||||||
|
static int physToWpi [64] =
|
||||||
|
{
|
||||||
|
-1, // 0
|
||||||
|
-1, -1, // 1, 2
|
||||||
|
8, -1,
|
||||||
|
9, -1,
|
||||||
|
7, 15,
|
||||||
|
-1, 16,
|
||||||
|
0, 1,
|
||||||
|
2, -1,
|
||||||
|
3, 4,
|
||||||
|
-1, 5,
|
||||||
|
12, -1,
|
||||||
|
13, 6,
|
||||||
|
14, 10,
|
||||||
|
-1, 11, // 25, 26
|
||||||
|
30, 31, // Actually I2C, but not used
|
||||||
|
21, -1,
|
||||||
|
22, 26,
|
||||||
|
23, -1,
|
||||||
|
24, 27,
|
||||||
|
25, 28,
|
||||||
|
-1, 29,
|
||||||
|
-1, -1,
|
||||||
|
-1, -1,
|
||||||
|
-1, -1,
|
||||||
|
-1, -1,
|
||||||
|
-1, -1,
|
||||||
|
17, 18,
|
||||||
|
19, 20,
|
||||||
|
-1, -1, -1, -1, -1, -1, -1, -1, -1
|
||||||
|
} ;
|
||||||
|
|
||||||
|
static char *physNames [64] =
|
||||||
|
{
|
||||||
|
NULL,
|
||||||
|
|
||||||
|
" 3.3v", "5v ",
|
||||||
|
" SDA.1", "5V ",
|
||||||
|
" SCL.1", "0v ",
|
||||||
|
"GPIO. 7", "TxD ",
|
||||||
|
" 0v", "RxD ",
|
||||||
|
"GPIO. 0", "GPIO. 1",
|
||||||
|
"GPIO. 2", "0v ",
|
||||||
|
"GPIO. 3", "GPIO. 4",
|
||||||
|
" 3.3v", "GPIO. 5",
|
||||||
|
" MOSI", "0v ",
|
||||||
|
" MISO", "GPIO. 6",
|
||||||
|
" SCLK", "CE0 ",
|
||||||
|
" 0v", "CE1 ",
|
||||||
|
" SDA.0", "SCL.0 ",
|
||||||
|
"GPIO.21", "0v ",
|
||||||
|
"GPIO.22", "GPIO.26",
|
||||||
|
"GPIO.23", "0v ",
|
||||||
|
"GPIO.24", "GPIO.27",
|
||||||
|
"GPIO.25", "GPIO.28",
|
||||||
|
" 0v", "GPIO.29",
|
||||||
|
NULL, NULL,
|
||||||
|
NULL, NULL,
|
||||||
|
NULL, NULL,
|
||||||
|
NULL, NULL,
|
||||||
|
NULL, NULL,
|
||||||
|
"GPIO.17", "GPIO.18",
|
||||||
|
"GPIO.19", "GPIO.20",
|
||||||
|
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* readallPhys:
|
||||||
|
* Given a physical pin output the data on it and the next pin:
|
||||||
|
*| BCM | wPi | Name | Mode | Val| Physical |Val | Mode | Name | wPi | BCM |
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
static void readallPhys (int physPin)
|
||||||
|
{
|
||||||
|
int pin ;
|
||||||
|
|
||||||
|
if (physPinToGpio (physPin) == -1)
|
||||||
|
printf (" | | ") ;
|
||||||
|
else
|
||||||
|
printf (" | %3d | %3d", physPinToGpio (physPin), physToWpi [physPin]) ;
|
||||||
|
|
||||||
|
printf (" | %s", physNames [physPin]) ;
|
||||||
|
|
||||||
|
if (physToWpi [physPin] == -1)
|
||||||
|
printf (" | | ") ;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/**/ if (wpMode == WPI_MODE_GPIO)
|
||||||
|
pin = physPinToGpio (physPin) ;
|
||||||
|
else if (wpMode == WPI_MODE_PHYS)
|
||||||
|
pin = physPin ;
|
||||||
|
else
|
||||||
|
pin = physToWpi [physPin] ;
|
||||||
|
|
||||||
|
printf (" | %4s", alts [getAlt (pin)]) ;
|
||||||
|
printf (" | %d", digitalRead (pin)) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pin numbers:
|
||||||
|
|
||||||
|
printf (" | %2d", physPin) ;
|
||||||
|
++physPin ;
|
||||||
|
printf (" || %-2d", physPin) ;
|
||||||
|
|
||||||
|
// Same, reversed
|
||||||
|
|
||||||
|
if (physToWpi [physPin] == -1)
|
||||||
|
printf (" | | ") ;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/**/ if (wpMode == WPI_MODE_GPIO)
|
||||||
|
pin = physPinToGpio (physPin) ;
|
||||||
|
else if (wpMode == WPI_MODE_PHYS)
|
||||||
|
pin = physPin ;
|
||||||
|
else
|
||||||
|
pin = physToWpi [physPin] ;
|
||||||
|
|
||||||
|
printf (" | %d", digitalRead (pin)) ;
|
||||||
|
printf (" | %-4s", alts [getAlt (pin)]) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf (" | %-5s", physNames [physPin]) ;
|
||||||
|
|
||||||
|
if (physToWpi [physPin] == -1)
|
||||||
|
printf (" | | ") ;
|
||||||
|
else
|
||||||
|
printf (" | %-3d | %-3d", physToWpi [physPin], physPinToGpio (physPin)) ;
|
||||||
|
|
||||||
|
printf (" |\n") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void cmReadall (void)
|
||||||
|
{
|
||||||
|
int pin ;
|
||||||
|
|
||||||
|
printf ("+-----+------+-------+ +-----+------+-------+\n") ;
|
||||||
|
printf ("| Pin | Mode | Value | | Pin | Mode | Value |\n") ;
|
||||||
|
printf ("+-----+------+-------+ +-----+------+-------+\n") ;
|
||||||
|
|
||||||
|
for (pin = 0 ; pin < 28 ; ++pin)
|
||||||
|
{
|
||||||
|
printf ("| %3d ", pin) ;
|
||||||
|
printf ("| %-4s ", alts [getAlt (pin)]) ;
|
||||||
|
printf ("| %s ", digitalRead (pin) == HIGH ? "High" : "Low ") ;
|
||||||
|
printf ("| ") ;
|
||||||
|
printf ("| %3d ", pin + 28) ;
|
||||||
|
printf ("| %-4s ", alts [getAlt (pin + 28)]) ;
|
||||||
|
printf ("| %s ", digitalRead (pin + 28) == HIGH ? "High" : "Low ") ;
|
||||||
|
printf ("|\n") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf ("+-----+------+-------+ +-----+------+-------+\n") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* abReadall:
|
||||||
|
* Read all the pins on the model A or B.
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
void abReadall (int model, int rev)
|
||||||
|
{
|
||||||
|
int pin ;
|
||||||
|
char *type ;
|
||||||
|
|
||||||
|
if (model == PI_MODEL_A)
|
||||||
|
type = " A" ;
|
||||||
|
else
|
||||||
|
if (rev == PI_VERSION_2)
|
||||||
|
type = "B2" ;
|
||||||
|
else
|
||||||
|
type = "B1" ;
|
||||||
|
|
||||||
|
printf (" +-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type) ;
|
||||||
|
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
|
||||||
|
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
|
||||||
|
for (pin = 1 ; pin <= 26 ; pin += 2)
|
||||||
|
readallPhys (pin) ;
|
||||||
|
|
||||||
|
if (rev == PI_VERSION_2) // B version 2
|
||||||
|
{
|
||||||
|
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
|
||||||
|
for (pin = 51 ; pin <= 54 ; pin += 2)
|
||||||
|
readallPhys (pin) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
|
||||||
|
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
|
||||||
|
printf (" +-----+-----+---------+------+---+-Model %s-+---+------+---------+-----+-----+\n", type) ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* bPlusReadall:
|
||||||
|
* Read all the pins on the model B+
|
||||||
|
*********************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
void bPlusReadall (void)
|
||||||
|
{
|
||||||
|
int pin ;
|
||||||
|
|
||||||
|
printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
|
||||||
|
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
|
||||||
|
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
|
||||||
|
for (pin = 1 ; pin <= 40 ; pin += 2)
|
||||||
|
readallPhys (pin) ;
|
||||||
|
printf (" +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+\n") ;
|
||||||
|
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
|
||||||
|
printf (" +-----+-----+---------+------+---+--B Plus--+---+------+---------+-----+-----+\n") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void doReadall (void)
|
||||||
|
{
|
||||||
|
int model, rev, mem, maker, overVolted ;
|
||||||
|
|
||||||
|
if (wiringPiNodes != NULL) // External readall
|
||||||
|
{
|
||||||
|
doReadallExternal () ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
|
||||||
|
|
||||||
|
/**/ if ((model == PI_MODEL_A) || (model == PI_MODEL_B))
|
||||||
|
abReadall (model, rev) ;
|
||||||
|
else if (model == PI_MODEL_BP)
|
||||||
|
bPlusReadall () ;
|
||||||
|
else if (model == PI_MODEL_CM)
|
||||||
|
cmReadall () ;
|
||||||
|
else
|
||||||
|
printf ("Oops - unable to determine board type... model: %d\n", model) ;
|
||||||
|
}
|
||||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue