Updated from git.drogon.net
This commit is contained in:
@@ -48,11 +48,13 @@ LIBS =
|
||||
SRC = ds1302.c maxdetect.c piNes.c \
|
||||
gertboard.c piFace.c \
|
||||
lcd128x64.c lcd.c \
|
||||
scrollPhat.c \
|
||||
piGlow.c
|
||||
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
HEADERS = ds1302.h gertboard.h lcd128x64.h lcd.h maxdetect.h piFace.h piGlow.h piNes.h
|
||||
HEADERS = ds1302.h gertboard.h lcd128x64.h lcd.h maxdetect.h piFace.h piGlow.h piNes.h\
|
||||
scrollPhat.h
|
||||
|
||||
all: $(DYNAMIC)
|
||||
|
||||
@@ -134,4 +136,5 @@ gertboard.o: gertboard.h
|
||||
piFace.o: piFace.h
|
||||
lcd128x64.o: font.h lcd128x64.h
|
||||
lcd.o: lcd.h
|
||||
scrollPhat.o: scrollPhatFont.h scrollPhat.h
|
||||
piGlow.o: piGlow.h
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
//#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdio.h>
|
||||
//#include <stdlib.h>
|
||||
//#include <unistd.h>
|
||||
|
||||
@@ -38,21 +39,43 @@
|
||||
|
||||
/*
|
||||
* maxDetectLowHighWait:
|
||||
* Wait for a transition from high to low on the bus
|
||||
* Wait for a transition from low to high on the bus
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
static void maxDetectLowHighWait (const int pin)
|
||||
static int maxDetectLowHighWait (const int pin)
|
||||
{
|
||||
unsigned int timeOut = millis () + 2000 ;
|
||||
struct timeval now, timeOut, timeUp ;
|
||||
|
||||
// If already high then wait for pin to go low
|
||||
|
||||
gettimeofday (&now, NULL) ;
|
||||
timerclear (&timeOut) ;
|
||||
timeOut.tv_usec = 1000 ;
|
||||
timeradd (&now, &timeOut, &timeUp) ;
|
||||
|
||||
while (digitalRead (pin) == HIGH)
|
||||
if (millis () > timeOut)
|
||||
return ;
|
||||
{
|
||||
gettimeofday (&now, NULL) ;
|
||||
if (timercmp (&now, &timeUp, >))
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
// Wait for it to go HIGH
|
||||
|
||||
gettimeofday (&now, NULL) ;
|
||||
timerclear (&timeOut) ;
|
||||
timeOut.tv_usec = 1000 ;
|
||||
timeradd (&now, &timeOut, &timeUp) ;
|
||||
|
||||
while (digitalRead (pin) == LOW)
|
||||
if (millis () > timeOut)
|
||||
return ;
|
||||
{
|
||||
gettimeofday (&now, NULL) ;
|
||||
if (timercmp (&now, &timeUp, >))
|
||||
return FALSE ;
|
||||
}
|
||||
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +92,8 @@ static unsigned int maxDetectClockByte (const int pin)
|
||||
|
||||
for (bit = 0 ; bit < 8 ; ++bit)
|
||||
{
|
||||
maxDetectLowHighWait (pin) ;
|
||||
if (!maxDetectLowHighWait (pin))
|
||||
return 0 ;
|
||||
|
||||
// bit starting now - we need to time it.
|
||||
|
||||
@@ -95,6 +119,11 @@ int maxDetectRead (const int pin, unsigned char buffer [4])
|
||||
int i ;
|
||||
unsigned int checksum ;
|
||||
unsigned char localBuf [5] ;
|
||||
struct timeval now, then, took ;
|
||||
|
||||
// See how long we took
|
||||
|
||||
gettimeofday (&then, NULL) ;
|
||||
|
||||
// Wake up the RHT03 by pulling the data line low, then high
|
||||
// Low for 10mS, high for 40uS.
|
||||
@@ -106,7 +135,8 @@ int maxDetectRead (const int pin, unsigned char buffer [4])
|
||||
|
||||
// Now wait for sensor to pull pin low
|
||||
|
||||
maxDetectLowHighWait (pin) ;
|
||||
if (!maxDetectLowHighWait (pin))
|
||||
return FALSE ;
|
||||
|
||||
// and read in 5 bytes (40 bits)
|
||||
|
||||
@@ -121,6 +151,22 @@ int maxDetectRead (const int pin, unsigned char buffer [4])
|
||||
}
|
||||
checksum &= 0xFF ;
|
||||
|
||||
// See how long we took
|
||||
|
||||
gettimeofday (&now, NULL) ;
|
||||
timersub (&now, &then, &took) ;
|
||||
|
||||
// Total time to do this should be:
|
||||
// 10mS + 40µS - reset
|
||||
// + 80µS + 80µS - sensor doing its low -> high thing
|
||||
// + 40 * (50µS + 27µS (0) or 70µS (1) )
|
||||
// = 15010µS
|
||||
// so if we take more than that, we've had a scheduling interruption and the
|
||||
// reading is probably bogus.
|
||||
|
||||
if ((took.tv_sec != 0) || (took.tv_usec > 16000))
|
||||
return FALSE ;
|
||||
|
||||
return checksum == localBuf [4] ;
|
||||
}
|
||||
|
||||
@@ -128,38 +174,65 @@ int maxDetectRead (const int pin, unsigned char buffer [4])
|
||||
/*
|
||||
* readRHT03:
|
||||
* Read the Temperature & Humidity from an RHT03 sensor
|
||||
* Values returned are *10, so 123 is 12.3.
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
int readRHT03 (const int pin, int *temp, int *rh)
|
||||
{
|
||||
static unsigned int nextTime = 0 ;
|
||||
static int lastTemp = 0 ;
|
||||
static int lastRh = 0 ;
|
||||
static int lastResult = TRUE ;
|
||||
static struct timeval then ; // will initialise to zero
|
||||
static int lastTemp = 0 ;
|
||||
static int lastRh = 0 ;
|
||||
|
||||
int result ;
|
||||
struct timeval now, timeOut ;
|
||||
unsigned char buffer [4] ;
|
||||
|
||||
// Don't read more than once a second
|
||||
// The data sheets say to not read more than once every 2 seconds, so you
|
||||
// get the last good reading
|
||||
|
||||
if (millis () < nextTime)
|
||||
gettimeofday (&now, NULL) ;
|
||||
if (timercmp (&now, &then, <))
|
||||
{
|
||||
*temp = lastTemp ;
|
||||
*rh = lastRh ;
|
||||
return lastResult ;
|
||||
}
|
||||
|
||||
lastResult = maxDetectRead (pin, buffer) ;
|
||||
|
||||
if (lastResult)
|
||||
{
|
||||
*temp = lastTemp = (buffer [2] * 256 + buffer [3]) ;
|
||||
*rh = lastRh = (buffer [0] * 256 + buffer [1]) ;
|
||||
nextTime = millis () + 2000 ;
|
||||
*temp = lastTemp ;
|
||||
return TRUE ;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// Set timeout for next read
|
||||
|
||||
gettimeofday (&now, NULL) ;
|
||||
timerclear (&timeOut) ;
|
||||
timeOut.tv_sec = 2 ;
|
||||
timeradd (&now, &timeOut, &then) ;
|
||||
|
||||
// Read ...
|
||||
|
||||
result = maxDetectRead (pin, buffer) ;
|
||||
|
||||
if (!result) // Try again, but just once
|
||||
result = maxDetectRead (pin, buffer) ;
|
||||
|
||||
if (!result)
|
||||
return FALSE ;
|
||||
|
||||
*rh = (buffer [0] * 256 + buffer [1]) ;
|
||||
*temp = (buffer [2] * 256 + buffer [3]) ;
|
||||
|
||||
if ((*temp & 0x8000) != 0) // Negative
|
||||
{
|
||||
*temp &= 0x7FFF ;
|
||||
*temp = -*temp ;
|
||||
}
|
||||
|
||||
// Discard obviously bogus readings - the checksum can't detect a 2-bit error
|
||||
// (which does seem to happen - no realtime here)
|
||||
|
||||
if ((*rh > 999) || (*temp > 800) || (*temp < -400))
|
||||
return FALSE ;
|
||||
|
||||
lastRh = *rh ;
|
||||
lastTemp = *temp ;
|
||||
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
178
devLib/piFaceOld.c
Normal file
178
devLib/piFaceOld.c
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* piFace.:
|
||||
* Arduino compatable (ish) Wiring library for the Raspberry Pi
|
||||
* Copyright (c) 2012-2013 Gordon Henderson
|
||||
*
|
||||
* This file to interface with the PiFace peripheral device which
|
||||
* has an MCP23S17 GPIO device connected via the SPI bus.
|
||||
***********************************************************************
|
||||
* 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 <stdint.h>
|
||||
|
||||
#include <wiringPi.h>
|
||||
#include <wiringPiSPI.h>
|
||||
|
||||
#include "../wiringPi/mcp23x0817.h"
|
||||
|
||||
#include "piFace.h"
|
||||
|
||||
#define PIFACE_SPEED 4000000
|
||||
#define PIFACE_DEVNO 0
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* writeByte:
|
||||
* Write a byte to a register on the MCP23S17 on the SPI bus.
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
static void writeByte (uint8_t reg, uint8_t data)
|
||||
{
|
||||
uint8_t spiData [4] ;
|
||||
|
||||
spiData [0] = CMD_WRITE ;
|
||||
spiData [1] = reg ;
|
||||
spiData [2] = data ;
|
||||
|
||||
wiringPiSPIDataRW (PIFACE_DEVNO, spiData, 3) ;
|
||||
}
|
||||
|
||||
/*
|
||||
* readByte:
|
||||
* Read a byte from a register on the MCP23S17 on the SPI bus.
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
static uint8_t readByte (uint8_t reg)
|
||||
{
|
||||
uint8_t spiData [4] ;
|
||||
|
||||
spiData [0] = CMD_READ ;
|
||||
spiData [1] = reg ;
|
||||
|
||||
wiringPiSPIDataRW (PIFACE_DEVNO, spiData, 3) ;
|
||||
|
||||
return spiData [2] ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* myDigitalWrite:
|
||||
* Perform the digitalWrite function on the PiFace board
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
|
||||
{
|
||||
uint8_t mask, old ;
|
||||
|
||||
pin -= node->pinBase ;
|
||||
mask = 1 << pin ;
|
||||
old = readByte (MCP23x17_GPIOA) ;
|
||||
|
||||
if (value == 0)
|
||||
old &= (~mask) ;
|
||||
else
|
||||
old |= mask ;
|
||||
|
||||
writeByte (MCP23x17_GPIOA, old) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* myDigitalRead:
|
||||
* Perform the digitalRead function on the PiFace board
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
|
||||
{
|
||||
uint8_t mask, reg ;
|
||||
|
||||
mask = 1 << ((pin - node->pinBase) & 7) ;
|
||||
|
||||
if (pin < 8)
|
||||
reg = MCP23x17_GPIOB ; // Input regsiter
|
||||
else
|
||||
reg = MCP23x17_OLATA ; // Output latch regsiter
|
||||
|
||||
if ((readByte (reg) & mask) != 0)
|
||||
return HIGH ;
|
||||
else
|
||||
return LOW ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* myPullUpDnControl:
|
||||
* Perform the pullUpDnControl function on the PiFace board
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int pud)
|
||||
{
|
||||
uint8_t mask, old ;
|
||||
|
||||
mask = 1 << (pin - node->pinBase) ;
|
||||
old = readByte (MCP23x17_GPPUB) ;
|
||||
|
||||
if (pud == 0)
|
||||
old &= (~mask) ;
|
||||
else
|
||||
old |= mask ;
|
||||
|
||||
writeByte (MCP23x17_GPPUB, old) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* piFaceSetup
|
||||
* Setup the SPI interface and initialise the MCP23S17 chip
|
||||
* We create one node with 16 pins - each if the first 8 pins being read
|
||||
* and write - although the operations actually go to different
|
||||
* hardware ports. The top 8 let you read the state of the output register.
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
int piFaceSetup (const int pinBase)
|
||||
{
|
||||
int x ;
|
||||
struct wiringPiNodeStruct *node ;
|
||||
|
||||
if ((x = wiringPiSPISetup (PIFACE_DEVNO, PIFACE_SPEED)) < 0)
|
||||
return x ;
|
||||
|
||||
// Setup the MCP23S17
|
||||
|
||||
writeByte (MCP23x17_IOCON, IOCON_INIT) ;
|
||||
writeByte (MCP23x17_IODIRA, 0x00) ; // Port A -> Outputs
|
||||
writeByte (MCP23x17_IODIRB, 0xFF) ; // Port B -> Inputs
|
||||
|
||||
node = wiringPiNewNode (pinBase, 16) ;
|
||||
node->digitalRead = myDigitalRead ;
|
||||
node->digitalWrite = myDigitalWrite ;
|
||||
node->pullUpDnControl = myPullUpDnControl ;
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
430
devLib/scrollPhat.c
Normal file
430
devLib/scrollPhat.c
Normal file
@@ -0,0 +1,430 @@
|
||||
/*
|
||||
* scrollPhat.c:
|
||||
* Simple driver for the Pimoroni Scroll Phat device
|
||||
*
|
||||
* Copyright (c) 2015 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 <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <wiringPiI2C.h>
|
||||
|
||||
#include "scrollPhatFont.h"
|
||||
#include "scrollPhat.h"
|
||||
|
||||
// Size
|
||||
|
||||
#define SP_WIDTH 11
|
||||
#define SP_HEIGHT 5
|
||||
|
||||
// I2C
|
||||
|
||||
#define PHAT_I2C_ADDR 0x60
|
||||
|
||||
// Software copy of the framebuffer
|
||||
// it's 8-bit deep although the display itself is only 1-bit deep.
|
||||
|
||||
static unsigned char frameBuffer [SP_WIDTH * SP_HEIGHT] ;
|
||||
|
||||
static int lastX, lastY ;
|
||||
static int printDelayFactor ;
|
||||
static int scrollPhatFd ;
|
||||
|
||||
static int putcharX ;
|
||||
|
||||
#undef DEBUG
|
||||
|
||||
|
||||
/*
|
||||
* delay:
|
||||
* Wait for some number of milliseconds.
|
||||
* This taken from wiringPi as there is no-need to include the whole of
|
||||
* wiringPi just for the delay function.
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
static void delay (unsigned int howLong)
|
||||
{
|
||||
struct timespec sleeper, dummy ;
|
||||
|
||||
sleeper.tv_sec = (time_t)(howLong / 1000) ;
|
||||
sleeper.tv_nsec = (long)(howLong % 1000) * 1000000 ;
|
||||
|
||||
nanosleep (&sleeper, &dummy) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* scrollPhatUpdate:
|
||||
* Copy our software version to the real display
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void scrollPhatUpdate (void)
|
||||
{
|
||||
register int x, y ;
|
||||
register unsigned char data, pixel ;
|
||||
unsigned char pixels [SP_WIDTH] ;
|
||||
|
||||
#ifdef DEBUG
|
||||
printf ("+-----------+\n") ;
|
||||
for (y = 0 ; y < SP_HEIGHT ; ++y)
|
||||
{
|
||||
putchar ('|') ;
|
||||
for (x = 0 ; x < SP_WIDTH ; ++x)
|
||||
{
|
||||
pixel = frameBuffer [x + y * SP_WIDTH] ;
|
||||
putchar (pixel == 0 ? ' ' : '*') ;
|
||||
}
|
||||
printf ("|\n") ;
|
||||
}
|
||||
printf ("+-----------+\n") ;
|
||||
#endif
|
||||
|
||||
for (x = 0 ; x < SP_WIDTH ; ++x)
|
||||
{
|
||||
data = 0 ;
|
||||
for (y = 0 ; y < SP_HEIGHT ; ++y)
|
||||
{
|
||||
pixel = frameBuffer [x + y * SP_WIDTH] ;
|
||||
data = (data << 1) | ((pixel == 0) ? 0 : 1) ;
|
||||
}
|
||||
pixels [x] = data ;
|
||||
}
|
||||
|
||||
for (x = 0 ; x < SP_WIDTH ; ++x)
|
||||
wiringPiI2CWriteReg8 (scrollPhatFd, 1 + x, pixels [x]) ;
|
||||
|
||||
wiringPiI2CWriteReg8 (scrollPhatFd, 0x0C, 0) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*********************************************************************************
|
||||
* Standard Graphical Functions
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* scrollPhatPoint:
|
||||
* Plot a pixel. Crude clipping - speed is not the essence here.
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void scrollPhatPoint (int x, int y, int colour)
|
||||
{
|
||||
lastX = x ;
|
||||
lastY = y ;
|
||||
|
||||
if ((x < 0) || (x >= SP_WIDTH) || (y < 0) || (y >= SP_HEIGHT))
|
||||
return ;
|
||||
|
||||
frameBuffer [x + y * SP_WIDTH] = colour ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* scrollPhatLine: scrollPhatLineTo:
|
||||
* Classic Bressenham Line code - rely on the point function to do the
|
||||
* clipping for us here.
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void scrollPhatLine (int x0, int y0, int x1, int y1, int colour)
|
||||
{
|
||||
int dx, dy ;
|
||||
int sx, sy ;
|
||||
int err, e2 ;
|
||||
|
||||
lastX = x1 ;
|
||||
lastY = y1 ;
|
||||
|
||||
dx = abs (x1 - x0) ;
|
||||
dy = abs (y1 - y0) ;
|
||||
|
||||
sx = (x0 < x1) ? 1 : -1 ;
|
||||
sy = (y0 < y1) ? 1 : -1 ;
|
||||
|
||||
err = dx - dy ;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
scrollPhatPoint (x0, y0, colour) ;
|
||||
|
||||
if ((x0 == x1) && (y0 == y1))
|
||||
break ;
|
||||
|
||||
e2 = 2 * err ;
|
||||
|
||||
if (e2 > -dy)
|
||||
{
|
||||
err -= dy ;
|
||||
x0 += sx ;
|
||||
}
|
||||
|
||||
if (e2 < dx)
|
||||
{
|
||||
err += dx ;
|
||||
y0 += sy ;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void scrollPhatLineTo (int x, int y, int colour)
|
||||
{
|
||||
scrollPhatLine (lastX, lastY, x, y, colour) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* scrollPhatRectangle:
|
||||
* A rectangle is a spoilt days fishing
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void scrollPhatRectangle (int x1, int y1, int x2, int y2, int colour, int filled)
|
||||
{
|
||||
register int x ;
|
||||
|
||||
if (filled)
|
||||
{
|
||||
/**/ if (x1 == x2)
|
||||
scrollPhatLine (x1, y1, x2, y2, colour) ;
|
||||
else if (x1 < x2)
|
||||
for (x = x1 ; x <= x2 ; ++x)
|
||||
scrollPhatLine (x, y1, x, y2, colour) ;
|
||||
else
|
||||
for (x = x2 ; x <= x1 ; ++x)
|
||||
scrollPhatLine (x, y1, x, y2, colour) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
scrollPhatLine (x1, y1, x2, y1, colour) ;
|
||||
scrollPhatLineTo (x2, y2, colour) ;
|
||||
scrollPhatLineTo (x1, y2, colour) ;
|
||||
scrollPhatLineTo (x1, y1, colour) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* scrollPhatPutchar:
|
||||
* Print a single character to the screen then advance the pointer by an
|
||||
* appropriate ammount (variable width font).
|
||||
* We rely on the clipping done by the pixel plot function to keep us
|
||||
* out of trouble.
|
||||
* Return the width + space
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
int scrollPhatPutchar (int c)
|
||||
{
|
||||
register int x, y ;
|
||||
|
||||
unsigned char line ;
|
||||
unsigned char *fontPtr ;
|
||||
unsigned char *p2 ;
|
||||
int lineWidth, width, mask ;
|
||||
|
||||
// The font is printable characters, uppercase only...
|
||||
// and somewhat varaible width...
|
||||
|
||||
c &= 0x7F ;
|
||||
if (c > 0x60)
|
||||
c -= 64 ;
|
||||
else
|
||||
c -= 32 ;
|
||||
|
||||
fontPtr = scrollPhatFont + c * fontHeight ;
|
||||
|
||||
// Work out width of this character
|
||||
// There probably is a more efficient way to do this, but...
|
||||
|
||||
p2 = fontPtr ;
|
||||
width = 0 ;
|
||||
for (y = 0 ; y < fontHeight ; ++y)
|
||||
{
|
||||
mask = 0x80 ;
|
||||
for (lineWidth = 8 ; lineWidth > 0 ; --lineWidth)
|
||||
{
|
||||
if ((*p2 & mask) != 0)
|
||||
break ;
|
||||
mask >>= 1 ;
|
||||
}
|
||||
if (lineWidth > width)
|
||||
width = lineWidth ;
|
||||
|
||||
++p2 ;
|
||||
}
|
||||
|
||||
if (width == 0) // Likely to be a blank or space character
|
||||
width = 3 ;
|
||||
|
||||
for (y = fontHeight - 1 ; y >= 0 ; --y)
|
||||
{
|
||||
x = 0 ;
|
||||
line = *fontPtr++ ;
|
||||
for (mask = 1 << (width - 1) ; mask != 0 ; mask >>= 1)
|
||||
{
|
||||
scrollPhatPoint (putcharX + x, y, (line & mask)) ;
|
||||
++x ;
|
||||
}
|
||||
}
|
||||
|
||||
// make a line of space
|
||||
|
||||
for (y = fontHeight - 1 ; y >= 0 ; --y)
|
||||
scrollPhatPoint (putcharX + width, y, 0) ;
|
||||
|
||||
putcharX = putcharX + width + 1 ;
|
||||
|
||||
return width + 1 ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* scrollPhatPuts:
|
||||
* Send a string to the display - and scroll it across.
|
||||
* This is somewhat of a hack in that we print the entire string to the
|
||||
* display and let the point clipping take care of what's off-screen...
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void scrollPhatPuts (const char *str)
|
||||
{
|
||||
int i ;
|
||||
int movingX = 0 ;
|
||||
const char *s ;
|
||||
int pixelLen ;
|
||||
|
||||
// Print it once, then we know the width in pixels...
|
||||
|
||||
putcharX = 0 ;
|
||||
s = str ;
|
||||
while (*s)
|
||||
scrollPhatPutchar (*s++) ;
|
||||
|
||||
pixelLen = putcharX ;
|
||||
|
||||
// Now scroll it by printing it and moving left one pixel
|
||||
|
||||
movingX = 0 ;
|
||||
for (i = 0 ; i < pixelLen ; ++i)
|
||||
{
|
||||
putcharX = movingX ;
|
||||
s = str ;
|
||||
while (*s)
|
||||
scrollPhatPutchar (*s++) ;
|
||||
--movingX ;
|
||||
scrollPhatUpdate () ;
|
||||
delay (printDelayFactor) ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* scrollPhatPrintf:
|
||||
* Does what it says
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void scrollPhatPrintf (const char *message, ...)
|
||||
{
|
||||
va_list argp ;
|
||||
char buffer [1024] ;
|
||||
|
||||
va_start (argp, message) ;
|
||||
vsnprintf (buffer, 1023, message, argp) ;
|
||||
va_end (argp) ;
|
||||
|
||||
scrollPhatPuts (buffer) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* scrollPhatPrintSpeed:
|
||||
* Change the print speed - mS per shift by 1 pixel
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void scrollPhatPrintSpeed (const int pps)
|
||||
{
|
||||
if (pps < 0)
|
||||
printDelayFactor = 0 ;
|
||||
else
|
||||
printDelayFactor = pps ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* scrollPhatClear:
|
||||
* Clear the display
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void scrollPhatClear (void)
|
||||
{
|
||||
register int i ;
|
||||
register unsigned char *ptr = frameBuffer ;
|
||||
|
||||
for (i = 0 ; i < (SP_WIDTH * SP_HEIGHT) ; ++i)
|
||||
*ptr++ = 0 ;
|
||||
|
||||
scrollPhatUpdate () ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* scrollPhatIntensity:
|
||||
* Set the display brightness - percentage
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
void scrollPhatIntensity (const int percent)
|
||||
{
|
||||
wiringPiI2CWriteReg8 (scrollPhatFd, 0x19, (127 * percent) / 100) ;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* scrollPhatSetup:
|
||||
* Initialise the Scroll Phat display
|
||||
*********************************************************************************
|
||||
*/
|
||||
|
||||
int scrollPhatSetup (void)
|
||||
{
|
||||
if ((scrollPhatFd = wiringPiI2CSetup (PHAT_I2C_ADDR)) < 0)
|
||||
return scrollPhatFd ;
|
||||
|
||||
wiringPiI2CWriteReg8 (scrollPhatFd, 0x00, 0x03) ; // Enable display, set to 5x11 mode
|
||||
scrollPhatIntensity (10) ;
|
||||
scrollPhatClear () ;
|
||||
scrollPhatPrintSpeed (100) ;
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
39
devLib/scrollPhat.h
Normal file
39
devLib/scrollPhat.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* scrollPhat.h:
|
||||
* Simple driver for the Pimoroni Scroll Phat device
|
||||
*
|
||||
* Copyright (c) 2015 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/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
extern void scrollPhatPoint (int x, int y, int colour) ;
|
||||
extern void scrollPhatLine (int x0, int y0, int x1, int y1, int colour) ;
|
||||
extern void scrollPhatLineTo (int x, int y, int colour) ;
|
||||
extern void scrollPhatRectangle (int x1, int y1, int x2, int y2, int colour, int filled) ;
|
||||
extern void scrollPhatUpdate (void) ;
|
||||
extern void scrollPhatClear (void) ;
|
||||
|
||||
extern int scrollPhatPutchar (int c) ;
|
||||
//extern void scrollPhatPutchar (int c) ;
|
||||
extern void scrollPhatPuts (const char *str) ;
|
||||
extern void scrollPhatPrintf (const char *message, ...) ;
|
||||
extern void scrollPhatPrintSpeed (const int cps10) ;
|
||||
|
||||
extern void scrollPhatIntensity (const int percent) ;
|
||||
extern int scrollPhatSetup (void) ;
|
||||
544
devLib/scrollPhatFont.h
Normal file
544
devLib/scrollPhatFont.h
Normal file
@@ -0,0 +1,544 @@
|
||||
/*
|
||||
* scrollPhatFont.h:
|
||||
* Simple font for the Pimoroni Scroll Phat.
|
||||
* Note: this is a very much reduced font - 5 pixels high and
|
||||
* mostly 4 pixels wide - sometimes 5. Also only
|
||||
* printable characters from space to _ uppercase only.
|
||||
*
|
||||
* Copyright (c) 2015-2016 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/>.
|
||||
***********************************************************************
|
||||
*/
|
||||
|
||||
static const int fontHeight = 5 ;
|
||||
|
||||
static unsigned char scrollPhatFont [] =
|
||||
{
|
||||
|
||||
// 0x20, Space. Handeled as a special case in the code.
|
||||
|
||||
0x0, // ....
|
||||
0x0, // ....
|
||||
0x0, // ....
|
||||
0x0, // ....
|
||||
0x0, // ....
|
||||
|
||||
// 0x21, !
|
||||
|
||||
0x1, // *
|
||||
0x1, // *
|
||||
0x1, // *
|
||||
0x0, // .
|
||||
0x1, // *
|
||||
|
||||
// 0x22, "
|
||||
|
||||
0x5, // *..*
|
||||
0x5, // *..*
|
||||
0x0, // ....
|
||||
0x0, // ....
|
||||
0x0, // ....
|
||||
|
||||
// 0x23, #
|
||||
|
||||
0x9, // *..*
|
||||
0xF, // ****
|
||||
0x9, // *..*
|
||||
0xF, // ****
|
||||
0x9, // *..*
|
||||
|
||||
// 0x24, $
|
||||
|
||||
0x1, // ..*.
|
||||
0x7, // .***
|
||||
0x2, // ..*.
|
||||
0xE, // ***.
|
||||
0x8, // ..*.
|
||||
|
||||
// 0x25, %
|
||||
|
||||
0x9, // *..*
|
||||
0x1, // ...*
|
||||
0x6, // .**.
|
||||
0x8, // *...
|
||||
0x9, // *..*
|
||||
|
||||
// 0x26, &
|
||||
|
||||
0x6, // .**.
|
||||
0x8, // *...
|
||||
0x4, // .*..
|
||||
0xA, // *.*.
|
||||
0x5, // .*.*
|
||||
|
||||
// 0x27, '
|
||||
|
||||
0x1, // .*
|
||||
0x2, // *.
|
||||
0x0, // ..
|
||||
0x0, // ..
|
||||
0x0, // ..
|
||||
|
||||
// 0x28, (
|
||||
|
||||
0x3, // ..**
|
||||
0x4, // .*..
|
||||
0x8, // *...
|
||||
0x4, // .*..
|
||||
0x3, // ..**
|
||||
|
||||
// 0x29, )
|
||||
|
||||
0xC, // **..
|
||||
0x2, // ..*.
|
||||
0x1, // ...*
|
||||
0x2, // ..*.
|
||||
0xC, // **..
|
||||
|
||||
// 0x2A, *
|
||||
|
||||
0x9, // *..*
|
||||
0x6, // .**.
|
||||
0xF, // ****
|
||||
0x6, // .**.
|
||||
0x9, // *..*
|
||||
|
||||
// 0x2B, +
|
||||
|
||||
0x6, // .**.
|
||||
0x6, // .**.
|
||||
0xF, // ****
|
||||
0x6, // .**.
|
||||
0x6, // .**.
|
||||
|
||||
// 0x2C, ,
|
||||
|
||||
0x0, // ..
|
||||
0x0, // ..
|
||||
0x0, // ..
|
||||
0x1, // .*
|
||||
0x2, // *.
|
||||
|
||||
// 0x2D, -
|
||||
|
||||
0x0, // ....
|
||||
0x0, // ....
|
||||
0xF, // ****
|
||||
0x0, // ....
|
||||
0x0, // ....
|
||||
|
||||
// 0x2E, .
|
||||
|
||||
0x0, // .
|
||||
0x0, // .
|
||||
0x0, // .
|
||||
0x0, // .
|
||||
0x1, // *
|
||||
|
||||
// 0x2F, /
|
||||
|
||||
0x1, // ...*
|
||||
0x3, // ..**
|
||||
0x4, // ..*.
|
||||
0xC, // **..
|
||||
0x8, // *...
|
||||
|
||||
// 0x30, 0
|
||||
|
||||
0x6, // .**.
|
||||
0x9, // *..*
|
||||
0x9, // *..*
|
||||
0x9, // *..*
|
||||
0x6, // .**.
|
||||
|
||||
// 0x31, 1
|
||||
|
||||
0x2, // ..*.
|
||||
0x6, // .**.
|
||||
0x2, // ..*.
|
||||
0x2, // ..*.
|
||||
0x7, // .***
|
||||
|
||||
// 0x32, 2
|
||||
|
||||
0x6, // .**.
|
||||
0x1, // ...*
|
||||
0x6, // .**.
|
||||
0x8, // *...
|
||||
0xF, // ****
|
||||
|
||||
// 0x33, 3
|
||||
|
||||
0xE, // ***.
|
||||
0x1, // ...*
|
||||
0xE, // ***.
|
||||
0x1, // ...*
|
||||
0xE, // ***.
|
||||
|
||||
// 0x34, 4
|
||||
|
||||
0x6, // .**.
|
||||
0xA, // *.*.
|
||||
0xF, // ****
|
||||
0x2, // ..*.
|
||||
0x2, // ..*.
|
||||
|
||||
// 0x35, 5
|
||||
|
||||
0xF, // ****
|
||||
0x8, // *...
|
||||
0xF, // ****
|
||||
0x1, // ...*
|
||||
0xE, // ***.
|
||||
|
||||
// 0x36, 6
|
||||
|
||||
0x2, // ..*.
|
||||
0x4, // .*..
|
||||
0xA, // *.*.
|
||||
0x9, // *..*
|
||||
0x6, // .**.
|
||||
|
||||
// 0x37, 7
|
||||
|
||||
0xF, // ****
|
||||
0x1, // ...*
|
||||
0x2, // ..*.
|
||||
0x4, // .*..
|
||||
0x8, // *...
|
||||
|
||||
// 0x38, 8
|
||||
|
||||
0x6, // .**.
|
||||
0x9, // *..*
|
||||
0x6, // .**.
|
||||
0x9, // *..*
|
||||
0x6, // .**.
|
||||
|
||||
// 0x39, 9
|
||||
|
||||
0x6, // .**.
|
||||
0x9, // *..*
|
||||
0x7, // .*.*
|
||||
0x1, // ..*.
|
||||
0x2, // .*..
|
||||
|
||||
// 0x3A, :
|
||||
|
||||
0x0, // .
|
||||
0x1, // *
|
||||
0x0, // .
|
||||
0x1, // *
|
||||
0x0, // .
|
||||
|
||||
// 0x3B, ;
|
||||
|
||||
0x0, // ..
|
||||
0x1, // .*
|
||||
0x0, // ..
|
||||
0x1, // .*
|
||||
0x2, // *.
|
||||
|
||||
// 0x3C, <
|
||||
|
||||
0x2, // ..*.
|
||||
0x4, // .*..
|
||||
0x8, // *...
|
||||
0x4, // .*..
|
||||
0x2, // ..*.
|
||||
|
||||
// 0x3D, =
|
||||
|
||||
0x0, // ....
|
||||
0xF, // ****
|
||||
0x0, // ....
|
||||
0xF, // ****
|
||||
0x0, // ....
|
||||
|
||||
// 0x3E, >
|
||||
|
||||
0x0, // .*..
|
||||
0x0, // ..*.
|
||||
0x0, // ...*
|
||||
0x0, // ..*.
|
||||
0x0, // .*..
|
||||
|
||||
// 0x3F, ?
|
||||
|
||||
0x6, // .**.
|
||||
0x1, // ...*
|
||||
0x2, // ..*.
|
||||
0x0, // ....
|
||||
0x2, // ..*.
|
||||
|
||||
// 0x40, @
|
||||
|
||||
0x6, // .**.
|
||||
0xD, // **.*
|
||||
0x8, // *...
|
||||
0x4, // .*..
|
||||
0x3, // ..**
|
||||
|
||||
// 0x41, A
|
||||
|
||||
0x6, // .**.
|
||||
0x9, // *..*
|
||||
0xF, // ****
|
||||
0x9, // *..*
|
||||
0x9, // *..*
|
||||
|
||||
// 0x42, B
|
||||
|
||||
0xE, // ***.
|
||||
0x9, // *..*
|
||||
0xE, // ***.
|
||||
0x9, // *..*
|
||||
0xE, // ***.
|
||||
|
||||
// 0x43, C
|
||||
|
||||
0x6, // .**.
|
||||
0x9, // *..*
|
||||
0x8, // *...
|
||||
0x9, // *..*
|
||||
0x6, // .**.
|
||||
|
||||
// 0x44, D
|
||||
|
||||
0xE, // ***.
|
||||
0x9, // *..*
|
||||
0x9, // *..*
|
||||
0x9, // *..*
|
||||
0xE, // ***.
|
||||
|
||||
// 0x45, E
|
||||
|
||||
0xF, // ****
|
||||
0x8, // *...
|
||||
0xE, // ***.
|
||||
0x8, // *...
|
||||
0xF, // ****
|
||||
|
||||
// 0x46, F
|
||||
|
||||
0xF, // ****
|
||||
0x8, // *...
|
||||
0xE, // ***.
|
||||
0x8, // *...
|
||||
0x8, // *...
|
||||
|
||||
// 0x47, G
|
||||
|
||||
0x6, // .**.
|
||||
0x9, // *..*
|
||||
0x8, // *...
|
||||
0xB, // *.**
|
||||
0x6, // .**.
|
||||
|
||||
// 0x48, H
|
||||
|
||||
0x9, // *..*
|
||||
0x9, // *..*
|
||||
0xF, // ****
|
||||
0x9, // *..*
|
||||
0x9, // *..*
|
||||
|
||||
// 0x49, I
|
||||
|
||||
0x7, // ***
|
||||
0x2, // .*.
|
||||
0x2, // .*.
|
||||
0x2, // .*.
|
||||
0x7, // ***
|
||||
|
||||
// 0x4A, J
|
||||
|
||||
0x7, // .***
|
||||
0x2, // ..*.
|
||||
0x2, // ..*.
|
||||
0xA, // *.*.
|
||||
0x4, // .*..
|
||||
|
||||
// 0x4B, K
|
||||
|
||||
0x9, // *..*
|
||||
0xA, // *.*.
|
||||
0xC, // **..
|
||||
0xA, // *.*.
|
||||
0x9, // *..*
|
||||
|
||||
// 0x4C, L
|
||||
|
||||
0x4, // *..
|
||||
0x4, // *..
|
||||
0x4, // *..
|
||||
0x4, // *..
|
||||
0x7, // ***
|
||||
|
||||
// 0x4D, M
|
||||
|
||||
0x11, // *...*
|
||||
0x1B, // **.**
|
||||
0x15, // *.*.*
|
||||
0x11, // *...*
|
||||
0x11, // *...*
|
||||
|
||||
// 0x4E, N
|
||||
|
||||
0x9, // *..*
|
||||
0xD, // **.*
|
||||
0xB, // *.**
|
||||
0x9, // *..*
|
||||
0x9, // *..*
|
||||
|
||||
// 0x4F, O
|
||||
|
||||
0x6, // .**.
|
||||
0x9, // *..*
|
||||
0x9, // *..*
|
||||
0x9, // *..*
|
||||
0x6, // .**.
|
||||
|
||||
// 0x50, P
|
||||
|
||||
0xE, // ***.
|
||||
0x9, // *..*
|
||||
0xE, // ***.
|
||||
0x8, // *...
|
||||
0x8, // *...
|
||||
|
||||
// 0x51, Q
|
||||
|
||||
0x6, // .**.
|
||||
0x9, // *..*
|
||||
0x9, // *..*
|
||||
0xA, // *.*.
|
||||
0x5, // .*.*
|
||||
|
||||
// 0x52, R
|
||||
|
||||
0xE, // ***.
|
||||
0x9, // *..*
|
||||
0xF, // ***.
|
||||
0xA, // *.*.
|
||||
0x9, // *..*
|
||||
|
||||
// 0x53, S
|
||||
|
||||
0x6, // .**.
|
||||
0x8, // *...
|
||||
0x6, // .**.
|
||||
0x1, // ...*
|
||||
0x6, // .**.
|
||||
|
||||
// 0x54, T
|
||||
|
||||
0x7, // .***
|
||||
0x2, // ..*.
|
||||
0x2, // ..*.
|
||||
0x2, // ..*.
|
||||
0x2, // ..*.
|
||||
|
||||
// 0x55, U
|
||||
|
||||
0x9, // *..*
|
||||
0x9, // *..*
|
||||
0x9, // *..*
|
||||
0x9, // *..*
|
||||
0x6, // .**.
|
||||
|
||||
// 0x56, V
|
||||
|
||||
0x11, // *...*
|
||||
0x11, // *...*
|
||||
0x11, // *...*
|
||||
0x0A, // .*.*.
|
||||
0x04, // ..*..
|
||||
|
||||
// 0x57, W
|
||||
|
||||
0x11, // *...*
|
||||
0x11, // *...*
|
||||
0x11, // *...*
|
||||
0x15, // *.*.*
|
||||
0x1B, // **.**
|
||||
|
||||
// 0x58, X
|
||||
|
||||
0x9, // *..*
|
||||
0x9, // *..*
|
||||
0x6, // .**.
|
||||
0x9, // *..*
|
||||
0x9, // *..*
|
||||
|
||||
// 0x59, Y
|
||||
|
||||
0x11, // *...*
|
||||
0x0A, // .*.*.
|
||||
0x04, // ..*..
|
||||
0x04, // ..*..
|
||||
0x04, // ..*..
|
||||
|
||||
// 0x5A, Z
|
||||
|
||||
0xF, // ****
|
||||
0x1, // ...*
|
||||
0x6, // .**.
|
||||
0x8, // *...
|
||||
0xF, // ****
|
||||
|
||||
// 0x5B, [
|
||||
|
||||
0xE, // ***.
|
||||
0x8, // *...
|
||||
0x8, // *...
|
||||
0x8, // *...
|
||||
0xE, // ***.
|
||||
|
||||
// 0x5C, Backslash
|
||||
|
||||
0x8, // *...
|
||||
0xC, // **..
|
||||
0x6, // .**.
|
||||
0x3, // ..**
|
||||
0x1, // ...*
|
||||
|
||||
// 0x5D, ]
|
||||
|
||||
0x7, // .***
|
||||
0x1, // ...*
|
||||
0x1, // ...*
|
||||
0x1, // ...*
|
||||
0x7, // .***
|
||||
|
||||
// 0x5E, ^
|
||||
|
||||
0x6, // .**.
|
||||
0x9, // *..*
|
||||
0x0, // ....
|
||||
0x0, // ....
|
||||
0x0, // ....
|
||||
|
||||
// 0x5F, _
|
||||
|
||||
0x0, // ....
|
||||
0x0, // ....
|
||||
0x0, // ....
|
||||
0x0, // ....
|
||||
0xF, // ****
|
||||
} ;
|
||||
Reference in New Issue
Block a user