initial cleanup and mapping

This commit is contained in:
unknown
2016-08-18 21:52:18 +03:00
parent 1d89a05234
commit faf062af8b
155 changed files with 23233 additions and 0 deletions

79
examples/PiGlow/Makefile Normal file
View File

@ -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

51
examples/PiGlow/piGlow0.c Normal file
View File

@ -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) ;
}
}

258
examples/PiGlow/piGlow1.c Normal file
View File

@ -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 ;
}

176
examples/PiGlow/piglow.c Normal file
View 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 ;
}