first commit

This commit is contained in:
liuls2002
2023-08-11 15:53:17 +08:00
commit 2fe3003e20
213 changed files with 37226 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
#
# Makefile:
# wiringPi - A "wiring" library for the Raspberry Pi
# https://projects.drogon.net/wiring-pi
#
# Copyright (c) 2012-2015 Gordon Henderson
#################################################################################
# This file is part of wiringPi:
# A "wiring" 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/>.
#################################################################################
ifneq ($V,1)
Q ?= @
endif
#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 = scphat.c test.c
OBJ = $(SRC:.c=.o)
BINS = $(SRC:.c=)
all: $(BINS)
test: test.o
$Q echo [link]
$Q $(CC) -o $@ test.o $(LDFLAGS) $(LDLIBS)
scphat: scphat.o
$Q echo [link]
$Q $(CC) -o $@ scphat.o $(LDFLAGS) $(LDLIBS)
.c.o:
$Q echo [CC] $<
$Q $(CC) -c $(CFLAGS) $< -o $@
clean:
$Q echo "[Clean]"
$Q rm -f $(OBJ) *~ core tags $(BINS)
tags: $(SRC)
$Q echo [ctags]
$Q ctags $(SRC)
install: scphat
$Q echo Installing scphat into /usr/local/bin
$Q cp -a scphat /usr/local/bin/scphat
$Q chmod 755 /usr/local/bin/scphat
$Q echo Done. Remember to load the I2C drivers if needed.
depend:
makedepend -Y $(SRC)
# DO NOT DELETE

View File

@@ -0,0 +1,230 @@
/*
* scphat.c:
* Little program to allow use of the Pimoroni Sctoll Phat
* from the command-line.
*
* Copyright (c) 2015-2016 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 <stdlib.h>
#include <errno.h>
#include <string.h>
#include <wiringPi.h>
#include <scrollPhat.h>
static char *progName ;
/*
* checkArgs:
* Count the arguments for each little function
*********************************************************************************
*/
static void checkArgs (char *command, int num, int arg, int argc)
{
if ((arg + num) < argc)
return ;
fprintf (stderr, "%s: Not enough data for %s command.\n", progName, command) ;
exit (EXIT_FAILURE) ;
}
/*
* doClear:
* Clear the display
*********************************************************************************
*/
static int doClear (void)
{
scrollPhatClear () ;
return 1 ;
}
/*
* doBright
*********************************************************************************
*/
static int doBright (int arg, int argc, char *argv [])
{
checkArgs ("bright", 1, arg, argc) ;
scrollPhatIntensity (atoi (argv [arg+1])) ;
return 2 ;
}
/*
* doPlot
*********************************************************************************
*/
static int doPlot (int arg, int argc, char *argv [])
{
checkArgs ("plot", 2, arg, argc) ;
scrollPhatPoint (atoi (argv [arg+1]), atoi (argv [arg+2]), 1) ;
scrollPhatUpdate () ;
return 3 ;
}
/*
* doLine
*********************************************************************************
*/
static int doLine (int arg, int argc, char *argv [])
{
checkArgs ("line", 4, arg, argc) ;
scrollPhatLine (atoi (argv [arg+1]), atoi (argv [arg+2]),
atoi (argv [arg+3]), atoi (argv [arg+4]), 1) ;
scrollPhatUpdate () ;
return 5 ;
}
/*
* doLineTo
*********************************************************************************
*/
static int doLineTo (int arg, int argc, char *argv [])
{
checkArgs ("lineto", 2, arg, argc) ;
scrollPhatLineTo (atoi (argv [arg+1]), atoi (argv [arg+2]), 1) ;
scrollPhatUpdate () ;
return 3 ;
}
/*
* doWait
*********************************************************************************
*/
static int doWait (int arg, int argc, char *argv [])
{
checkArgs ("wait", 1, arg, argc) ;
delay (atoi (argv [arg+1]) * 100) ;
scrollPhatUpdate () ;
return 2 ;
}
/*
* doSpeed
*********************************************************************************
*/
static int doSpeed (int arg, int argc, char *argv [])
{
checkArgs ("speed", 1, arg, argc) ;
scrollPhatPrintSpeed (atoi (argv [arg+1])) ;
return 2 ;
}
/*
* doScroll
*********************************************************************************
*/
static int doScroll (int arg, int argc, char *argv [])
{
checkArgs ("scroll", 1, arg, argc) ;
scrollPhatPuts (argv [arg+1]) ;
return 2 ;
}
static void failUsage (void)
{
fprintf (stderr, "Usage: %s command [paremters] ...\n", progName) ;
fprintf (stderr, " commands:\n") ;
fprintf (stderr, " clear/cls - Clear the display\n") ;
fprintf (stderr, " bright N - Set display brightness; 1-100\n") ;
fprintf (stderr, " plot X Y - Set a single pixel at location X Y; 0-10, 0-4\n") ;
fprintf (stderr, " line X1 Y1 X2 Y2 - Draw a line from the 2 points\n") ;
fprintf (stderr, " lineto X2 Y2 - Draw a line from the last point to the new one\n") ;
fprintf (stderr, " wait/delay N - Wait for N 10ths seconds\n") ;
fprintf (stderr, " speed N - Set scrolling speed (cps)\n") ;
fprintf (stderr, " scroll S - Scroll the given string\n") ;
fprintf (stderr, "\n") ;
fprintf (stderr, " Example: %s plot 0 0 wait 50 scroll \" Hello \"\n", progName) ;
exit (EXIT_FAILURE) ;
}
/*
* the works
*********************************************************************************
*/
int main (int argc, char *argv [])
{
int arg = 1 ;
char *command ;
progName = argv [0] ;
wiringPiSetupSys () ;
if (scrollPhatSetup () != 0)
{
fprintf (stderr, "%s: Unable to initialise the scrollPhat: %s\n", progName, strerror (errno)) ;
exit (EXIT_FAILURE) ;
}
progName = argv [0] ;
if (argc < 2)
{
fprintf (stderr, "%s: Nothing to do...\n", argv [0]) ;
failUsage () ;
}
while (arg != argc)
{
command = argv [arg] ;
/**/ if (strcasecmp (command, "clear") == 0) arg += doClear () ;
else if (strcasecmp (command, "cls") == 0) arg += doClear () ;
else if (strcasecmp (command, "bright") == 0) arg += doBright (arg, argc, argv) ;
else if (strcasecmp (command, "plot") == 0) arg += doPlot (arg, argc, argv) ;
else if (strcasecmp (command, "line") == 0) arg += doLine (arg, argc, argv) ;
else if (strcasecmp (command, "lineto") == 0) arg += doLineTo (arg, argc, argv) ;
else if (strcasecmp (command, "wait") == 0) arg += doWait (arg, argc, argv) ;
else if (strcasecmp (command, "delay") == 0) arg += doWait (arg, argc, argv) ;
else if (strcasecmp (command, "speed") == 0) arg += doSpeed (arg, argc, argv) ;
else if (strcasecmp (command, "scroll") == 0) arg += doScroll (arg, argc, argv) ;
else
{
fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [arg]) ;
failUsage () ;
}
}
return 0 ;
}

115
examples/scrollPhat/test.c Normal file
View File

@@ -0,0 +1,115 @@
/*
* test.c:
* Little test program forthe Pimoroni Scroll Phat.
*
* Copyright (c) 2015-2016 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 <stdlib.h>
#include <errno.h>
#include <string.h>
#include <scrollPhat.h>
/*
* prompt:
* Simple prompt & wait
*********************************************************************************
*/
static void prompt (const char *p)
{
printf (" %s. Press ENTER: ", p) ;
(void)getchar () ;
}
/*
* the works
*********************************************************************************
*/
int main (void)
{
int x, y ;
printf ("\n") ;
printf ("Scroll Phat Test program\n") ;
printf ("========================\n") ;
if (scrollPhatSetup () != 0)
{
printf ("Unable to initialise the scrollPhat: %s\n", strerror (errno)) ;
exit (1) ;
}
printf ("-> Scroll Phat initialised OK\n") ;
printf ("... Basic display tests.\n\n") ;
prompt ("Display ought to be blank") ;
// Light all pixels using one point at a time
for (y = 0 ; y < 5 ; ++y)
for (x = 0 ; x < 12 ; ++x)
scrollPhatPoint (x, y, 1) ;
scrollPhatUpdate () ;
prompt ("Display ought to be all lit-up") ;
// Big rectangle
scrollPhatClear () ;
scrollPhatRectangle (0,0, 10, 4, 1, 0) ;
scrollPhatUpdate () ;
prompt ("There should now be a rectangle round the outside") ;
scrollPhatLine (0,0, 10,4, 1) ;
scrollPhatLine (0,4, 10,0, 1) ;
scrollPhatUpdate () ;
prompt ("Diagonal lines") ;
scrollPhatIntensity (1) ;
prompt ("Minimum brightness") ;
scrollPhatIntensity (100) ;
prompt ("Maximum brightness") ;
scrollPhatIntensity (10) ;
prompt ("Default brightness") ;
scrollPhatClear () ;
printf (" Message Test...Press Ctrl-C to exit: ") ;
fflush (stdout) ;
scrollPhatPrintSpeed (75) ;
for (;;)
scrollPhatPuts (" Welcome to the scroll phat from Pimoroni ") ;
return 0 ;
}