Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Command server to clear screen, write bitmap (inste:ad of prior…

… string-only server).
  • Loading branch information...
commit 9a85dbff193bd9c9205e0bb8230bcbf2b392a822 1 parent 1b89de3
@AretCarlsen authored
Showing with 133 additions and 24 deletions.
  1. +29 −19 Philips_PCD8544.cpp
  2. +14 −2 Philips_PCD8544.hpp
  3. +90 −3 Philips_PCD8544_Server.hpp
View
48 Philips_PCD8544.cpp
@@ -471,29 +471,39 @@ template<typename SPI_bus_t, typename LCD_DC_pin_t, typename LCD_CE_pin_t, typen
}
return OK;
}
+
/*
- * Name : image
- * Description : Image mode display routine.
- * Argument(s) : Address of image in hexes
+ * Name : writeBitmap and writeBitmap_P
+ * Description : Bitmap write routine. Writes at any desired offset.
+ * Argument(s) : Address of image in hexes, Offset of first byte to be written (default 0), and Size of bitmap data to write.
+ _P version expects an imageData source address from Program memory (for the memcpy_P routine).
* Return value : None.
* Example : image(&sample_image_declared_as_array);
*/
-template<typename SPI_bus_t, typename LCD_DC_pin_t, typename LCD_CE_pin_t, typename LCD_RST_pin_t, int X_RES, int Y_RES> void Philips_PCD8544<SPI_bus_t, LCD_DC_pin_t, LCD_CE_pin_t, LCD_RST_pin_t, X_RES, Y_RES>::image ( const byte *imageData ) {
- /* Initialize screenCache index to 0 */
-// CacheIdx = 0;
-// /* While within screenCache range */
-// for ( CacheIdx = 0; CacheIdx < CACHE_SIZE; CacheIdx++ )
-// {
-// /* Copy data from pointer to screenCache buffer */
-// screenCache[CacheIdx] = pgm_read_byte( imageData++ );
-// }
- /* optimized by Jakub Lasinski, version 0.2.6, March 14, 2009 */
- memcpy_P(screenCache,imageData,CACHE_SIZE); //Same as aboeve - 6 bytes less and faster instruction
- /* Reset watermark pointers to be full */
- LoWaterMark = 0;
- HiWaterMark = CACHE_SIZE - 1;
+template<typename SPI_bus_t, typename LCD_DC_pin_t, typename LCD_CE_pin_t, typename LCD_RST_pin_t, int X_RES, int Y_RES> void Philips_PCD8544<SPI_bus_t, LCD_DC_pin_t, LCD_CE_pin_t, LCD_RST_pin_t, X_RES, Y_RES>::writeBitmap(const byte *imageData, const CacheIndex_t offset, CacheIndex_t size) {
+ // Sanity check
+ if(size > CACHE_SIZE) size = CACHE_SIZE;
- /* Set update flag to be true */
+ /* Initialize screenCache index to 0 */
+ memcpy(screenCache,imageData,size);
+
+ /* Expand watermark pointers, if necessary. */
+ setMinimumWaterMarks(offset, offset + size - 1);
+
+ /* Set update pending semaphore. */
+ updateActive = TRUE;
+}
+template<typename SPI_bus_t, typename LCD_DC_pin_t, typename LCD_CE_pin_t, typename LCD_RST_pin_t, int X_RES, int Y_RES> void Philips_PCD8544<SPI_bus_t, LCD_DC_pin_t, LCD_CE_pin_t, LCD_RST_pin_t, X_RES, Y_RES>::writeBitmap_P(const byte *imageData, const CacheIndex_t offset, CacheIndex_t size) {
+ // Sanity check
+ if(size > CACHE_SIZE) size = CACHE_SIZE;
+
+ /* Initialize screenCache index to 0 */
+ memcpy_P(screenCache,imageData,size);
+
+ /* Expand watermark pointers, if necessary. */
+ setMinimumWaterMarks(offset, offset + size - 1);
+
+ /* Set update pending semaphore. */
updateActive = TRUE;
}
@@ -505,7 +515,7 @@ template<typename SPI_bus_t, typename LCD_DC_pin_t, typename LCD_CE_pin_t, typen
*/
template<typename SPI_bus_t, typename LCD_DC_pin_t, typename LCD_CE_pin_t, typename LCD_RST_pin_t, int X_RES, int Y_RES> void Philips_PCD8544<SPI_bus_t, LCD_DC_pin_t, LCD_CE_pin_t, LCD_RST_pin_t, X_RES, Y_RES>::update ( void ) {
CacheIndex_t i;
-
+ // LoWaterMark is unsigned, so lower boundary of 0 is innately enforced.
if ( LoWaterMark >= CACHE_SIZE )
LoWaterMark = CACHE_SIZE - 1;
View
16 Philips_PCD8544.hpp
@@ -18,7 +18,7 @@ static const uint8_t BAR_Y = 38;
/* Type definition */
typedef uint8_t byte;
-// Modified by ANC 2010-04-24 (to eliminate signedness). (Was a signed int.)
+// Cache index.
typedef uint16_t CacheIndex_t;
/* Enumeration */
@@ -88,7 +88,19 @@ class Philips_PCD8544 {
void init ( void );
void clear ( void );
void update ( void );
- void image ( const byte *imageData );
+
+ void writeBitmap(const byte *imageData, const CacheIndex_t offset = 0, CacheIndex_t size = CACHE_SIZE);
+ // Program memory version.
+ void writeBitmap_P(const byte *imageData, const CacheIndex_t offset = 0, CacheIndex_t size = CACHE_SIZE);
+
+ // Expand watermark pointers to new minimums.
+ void setMinimumWaterMarks(const CacheIndex_t new_LoWaterMark, const CacheIndex_t new_HiWaterMark){
+ if(new_LoWaterMark < LoWaterMark) LoWaterMark = new_LoWaterMark;
+ if(new_HiWaterMark > HiWaterMark) HiWaterMark = new_HiWaterMark;
+ }
+ // Historical alias.
+ void image ( const byte *imageData ){ writeBitmap_P(imageData); }
+
void contrast ( byte contrast );
byte gotoXYFont ( byte x, byte y );
byte chr ( LcdFontSize size, byte ch );
View
93 Philips_PCD8544_Server.hpp
@@ -13,11 +13,11 @@
namespace Philips_PCD8544{
template <typename LCD_t>
-class StringLCDServer : public SimpleServer, public Process {
+class StringServer : public SimpleServer, public Process {
LCD_t *lcd;
public:
- StringLCDServer(LCD_t *new_lcd)
+ StringServer(LCD_t *new_lcd)
: lcd(new_lcd)
{ }
@@ -25,7 +25,7 @@ Status::Status_t process(){
// Packet to process?
if(! packetPending()) return Status::Status__Good;
- DEBUGprint_MISC("SLS: Prc pk\n");
+ DEBUGprint_MISC("SS: Prc pk\n");
// Data in packet?
MAP::Data_t *data_ptr = offsetPacket.packet->get_data(offsetPacket.headerOffset);
@@ -59,6 +59,93 @@ Status::Status_t process(){
}
};
+template <typename LCD_t>
+class CommandServer : public SimpleServer, public Process {
+ LCD_t *lcd;
+
+public:
+
+ typedef uint8_t Command_t;
+ static const Command_t Command__ClearScreen = 0;
+ static const Command_t Command__WriteBitmap = 1;
+ static const Command_t Command__ReadBitmap = 2;
+ static const Command_t Command__SetContrast = 3;
+ static const Command_t Command__WriteString = 4;
+
+ CommandServer(LCD_t *new_lcd)
+ : lcd(new_lcd)
+ { }
+
+Status::Status_t process(){
+ // Packet to process?
+ if(! packetPending()) return Status::Status__Good;
+
+ DEBUGprint_MISC("BmS: Prc pk\n");
+
+ // Data in packet?
+ MAP::Data_t *data_ptr = offsetPacket.packet->get_data(offsetPacket.headerOffset);
+ if(data_ptr == NULL) return finishedWithPacket();
+
+ // Command 0: Clear screen
+ switch(*data_ptr){
+ // Clear screen
+ case Command__ClearScreen:
+ lcd->clear();
+ break;
+ // Write bitmap
+ case Command__WriteBitmap: {
+ // First byte is offset. Remaining data is actual image data.
+ // Assumes no more than 254 bitmap bytes per packet.
+ uint8_t packet_size = offsetPacket.packet->back() - data_ptr;
+ // Only proceed if at least one byte is to be written.
+ if(packet_size <= 1) break;
+ lcd->writeBitmap(data_ptr + 1, *data_ptr, packet_size - 1);
+ break;
+ }
+ // Read bitmap
+// case Command__ReadBitmap:
+// break;
+ // Set contrast
+ case Command__SetContrast: {
+ // First byte is new contrast.
+ uint8_t packet_size = offsetPacket.packet->back() - data_ptr;
+ if(packet_size > 0)
+ lcd->contrast(*data_ptr);
+ break;
+ }
+ // Write string
+// case Command__WriteString:
+// break;
+ // Unrecognized commands are ignored.
+// default:
+ }
+
+ // Write packet contents out to screen, beginning at first row and performing a linefeed
+ // when the right edge of the screen is encountered.
+ for(uint8_t Y = 1; Y <= LCD_t::MAX_Y_FONT; Y++){
+ // Start at leftmost edge of screen
+ lcd->gotoXYFont(1,Y);
+ while(data_ptr < offsetPacket.packet->back()){
+ uint8_t response = lcd->chr(FONT_1X, *data_ptr);
+ if(response != OK){
+ // If wrapped, the character has actually been written.
+ if(response == OK_WITH_WRAP) data_ptr++;
+ // Move to next line
+ break;
+ }
+ // Move to next character
+ data_ptr++;
+ }
+ }
+
+ // Update screen
+ lcd->update();
+
+ return finishedWithPacket();
+}
+};
+
+
/*
class GalvLCDServer : public SimpleServer {
process(){
Please sign in to comment.
Something went wrong with that request. Please try again.