Dependents:   NOKIA_KOMBAT

Files at this revision

API Documentation at this revision

Comitter:
bengisuakyurek
Date:
Mon May 27 14:53:21 2019 +0000
Parent:
0:9cfce382e741
Commit message:
I added draw_bitmap method

Changed in this revision

NOKIA_5110.cpp Show annotated file Show diff for this revision Revisions of this file
NOKIA_5110.h Show annotated file Show diff for this revision Revisions of this file
diff -r 9cfce382e741 -r 73f226b84b70 NOKIA_5110.cpp
--- a/NOKIA_5110.cpp	Mon Jan 13 23:09:26 2014 +0000
+++ b/NOKIA_5110.cpp	Mon May 27 14:53:21 2019 +0000
@@ -14,19 +14,19 @@
     LcdSpi = new SPI(pinout.mosi, pinout.miso, pinout.sclk);
     LcdSpi->format(LCD_SPI_BITS, LCD_SPI_MODE);
     LcdSpi->frequency(LCD_FREQ);
-    
+
     // Control Pins
     Pins = new DigitalOut*[3];
     Pins[PIN_RST]   = new DigitalOut(pinout.rst);
     Pins[PIN_SCE]   = new DigitalOut(pinout.sce);
     Pins[PIN_DC]    = new DigitalOut(pinout.dc);
-    
+
     // Initial Command Instructions, note the initial command mode
     FunctionSet.V   = CMD_FS_HORIZONTAL_MODE;
     FunctionSet.H   = CMD_FS_EXTENDED_MODE;
     FunctionSet.PD  = CMD_FS_ACTIVE_MODE;
     FunctionChar    = CreateFunctionChar();
-    
+
     TempControlChar = CMD_TC_TEMP_2;
     DispControlChar = CMD_DC_NORMAL_MODE;
     BiasChar        = CMD_BI_MUX_48;
@@ -58,7 +58,7 @@
 {
     ResetLcd();
     Pins[PIN_SCE]->write(0);     // Chip Select goes low
-    
+
     // Redefine the FunctionChar in case it has changed
     FunctionSet.V   = CMD_FS_HORIZONTAL_MODE;
     FunctionSet.H   = CMD_FS_EXTENDED_MODE;
@@ -71,7 +71,7 @@
     FunctionSet.H   = CMD_FS_BASIC_MODE;
     SendFunction( CreateFunctionChar() );   // Basic CMD set
     SendFunction( DispControlChar );        // | Display Mode
-    
+
     ClearLcdMem();
     Pins[PIN_DC]->write(1);     // Data/CMD goes back to Data mode
 }
@@ -101,8 +101,7 @@
 void NokiaLcd::DrawString(char* s)
 {
     char len = strlen(s);
-    for( int idx = 0; idx < len; idx++ )
-    {
+    for( int idx = 0; idx < len; idx++ ) {
         for( int i = 0; i < 6; i++)
             SendDrawData( FONT_6x6[ ((s[idx] - 32)*6) + i] );
     }
@@ -129,20 +128,18 @@
     int tlen = 0;
     int temp = 1;
     char c;
-    
+
     // Get number of digits
-    while( temp <= num )
-    {
+    while( temp <= num ) {
         temp *= 10;
         length++;
     }
     tlen = length;
     char* numString = new char[tlen+1];
-    
+
     // Convert each place in number to a stand-alone representative number
     temp = 0;
-    for(int idx = pow(10, length); idx>1; idx = (idx/10))
-    {
+    for(int idx = pow(10, length); idx>1; idx = (idx/10)) {
         c = (char)( ((num % idx)-(num % (idx/10)))/(idx/10) + 48);
         numString[temp] = c;
         temp++;
@@ -167,7 +164,31 @@
     Pins[PIN_DC]->write(1);     // Data/CMD goes back to Data mode
 }
 
+
+//------------------------------------------------------------------------------
+/*
+    int x: x coordinate of printing [0,83]
+    int y: y coordinate of printing [0,5] be careful here, you can only select the portion, adjust your byte codes accordingly
+    char bitmap: idk what * asterisk stands for, but it is the bitmap array you are going to print
+    int w: with of the image in actual pixel size
+    int h: height of the image in actual pixels, meanin that starting pixel is 1 e.g. 48 pixels in y column of the lcd 
+*/
+void NokiaLcd::DrawBitmap(int x, int y, char *bitmap, int w, int h)
+{ 
+    int h_adjusted; //this is for addressing y between 0 to 5
+    h_adjusted = h / 8; //this address is in range of 1-6 but in for loop, it is compensated with usage of < instead of <=
+
+    for( int j = 0; j < h_adjusted; j++) {
+        for( int i = 0 ; i < w ; i++ ) {
+            SetXY( x + i, y + j);
+            SendDrawData( bitmap[(j*w) + i]);
+        }
+    }
+}
+//------------------------------------------------------------------------------
+
 NokiaLcd::~NokiaLcd()
 {
     ShutdownLcd();
 }
+
diff -r 9cfce382e741 -r 73f226b84b70 NOKIA_5110.h
--- a/NOKIA_5110.h	Mon Jan 13 23:09:26 2014 +0000
+++ b/NOKIA_5110.h	Mon May 27 14:53:21 2019 +0000
@@ -73,6 +73,8 @@
 #define PIN_SCE  0x01
 #define PIN_DC   0x02
 
+
+
 #include "mbed.h"
 
 struct LcdPins
@@ -119,6 +121,7 @@
         void DrawFrameChar(char character);
         void DrawNegFrameChar(char character);
         char* NumToStr(int num);
+        void DrawBitmap(int x, int y, char *bitmap, int w, int h); //new
         
     private:
         char CreateFunctionChar();