Marc Bax / Mbed 2 deprecated Flexbook180111a

Dependencies:   SDFileSystem app epson mbed msp430 pl tests

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pageoled.cpp Source File

pageoled.cpp

00001 //
00002 // Filename: pageoled.cpp
00003 //
00004 // Flexbook page for page A3.
00005 //
00006 
00007 #include "pageoled.h"
00008 #include "pagesensor.h"
00009 
00010 #include "log.h"
00011 
00012 #include <iostream>
00013 
00014 namespace Flexbook {
00015 
00016 PageOLED::PageOLED()
00017 : data(p9), clock(p10), strobe(p11), enable(p12)
00018 {
00019     Log("Creating PageOLED");
00020 
00021     data = 0;
00022     clock = 0;
00023     strobe = 0;
00024     enable = 1;
00025     
00026     Write(0xffffffffffff);
00027     wait(1.0);
00028     
00029     // test case follows
00030     //Write(Translate(0,0,1,2,3,10));
00031     //wait(2.0);
00032     
00033    /*
00034     for (int i=0; i<200; i++) {
00035         Write(Translate(0,0,0,0,0,i % 6));
00036         if (i<120) wait_ms(30);
00037             else wait_ms(i);
00038         }
00039 
00040         
00041     for (int i=0; i<600; i++) {
00042         Write(Translate(i%6,i%6,0,0,i*7%6,i%10));
00043         wait(0.5);
00044         }    
00045         
00046     uint64_t oledpixels = 63;
00047     for(int i=0; i<43; i++) {
00048         Write(oledpixels);
00049         oledpixels = 1 + (oledpixels * 2);
00050         wait(0.5);
00051         }
00052         
00053     wait(5.0);
00054     */
00055     // test case ends
00056     
00057     Write(0x000000000000);
00058 }
00059 
00060 PageOLED::~PageOLED()
00061 {
00062     Log("Deleting PageOLED");
00063 }
00064 
00065 // Write data to OLED.
00066 void PageOLED::Write(uint64_t writedata)
00067 {
00068     strobe = 1;
00069     enable = 1;
00070 
00071     for(int bit = 0; bit < 48; bit++)
00072     {
00073         data = writedata & 1;
00074         clock = 1;
00075         writedata = writedata >> 1;
00076         clock = 0;
00077     }
00078 
00079     strobe = 0;
00080     enable = 0;
00081 }
00082 
00083 uint64_t PageOLED::Translate(char b1, char b2, char b3, char b4, char b5, char d1)
00084 // b1..b5 should be a number 0..6 - the number of bars lit in each of the five bar graphs
00085 // d1 should be a number 0..9 - and is displayed as a single digit
00086 {
00087     uint64_t result = 0; //start with 0, each addition only changes a single bit
00088     
00089     //create bit pattern for leftmost bar graph (No. 1)
00090     if (b1>6) result = result + (0x010000000000); //bit 40 - not connected on new OLEDS
00091     if (b1>5) result = result + (0x020000000000); //bit 41
00092     if (b1>4) result = result + (0x040000000000); //bit 42
00093     if (b1>3) result = result + (0x080000000000); //bit 43
00094     if (b1>2) result = result + (0x000800000000); //bit 35
00095     if (b1>1) result = result + (0x000400000000); //bit 34
00096     if (b1>0) result = result + (0x000200000000); //bit 33
00097     
00098     //create bit pattern for second bar graph
00099     if (b2>6) result = result + (0x000100000000); //bit 32 - not connected on new OLEDS
00100     if (b2>5) result = result + (0x800000000000); //bit 47
00101     if (b2>4) result = result + (0x400000000000); //bit 46
00102     if (b2>3) result = result + (0x200000000000); //bit 45
00103     if (b2>2) result = result + (0x100000000000); //bit 44
00104     if (b2>1) result = result + (0x001000000000); //bit 36
00105     if (b2>0) result = result + (0x002000000000); //bit 37
00106     
00107     //create bit pattern for third bar graph
00108     if (b3>6) result = result + (0x004000000000); //bit 38 - not connected on new OLEDS
00109     if (b3>5) result = result + (0x008000000000); //bit 39
00110     if (b3>4) result = result + (0x000001000000); //bit 24
00111     if (b3>3) result = result + (0x000002000000); //bit 25
00112     if (b3>2) result = result + (0x000004000000); //bit 26
00113     if (b3>1) result = result + (0x000008000000); //bit 27
00114     if (b3>0) result = result + (0x000000080000); //bit 19
00115     
00116     //create bit pattern for fourth bar graph
00117     if (b4>6) result = result + (0x000000040000); //bit 18 - not connected on new OLEDS
00118     if (b4>5) result = result + (0x000000020000); //bit 17
00119     if (b4>4) result = result + (0x000000010000); //bit 16
00120     if (b4>3) result = result + (0x000080000000); //bit 31
00121     if (b4>2) result = result + (0x000040000000); //bit 30
00122     if (b4>1) result = result + (0x000020000000); //bit 29
00123     if (b4>0) result = result + (0x000010000000); //bit 28
00124     
00125     //create bit pattern for fifth (rightmost) bar graph
00126     if (b5>6) result = result + (0x000000100000); //bit 20 - not connected on new OLEDS
00127     if (b5>5) result = result + (0x000000200000); //bit 21
00128     if (b5>4) result = result + (0x000000400000); //bit 22
00129     if (b5>3) result = result + (0x000000800000); //bit 23
00130     if (b5>2) result = result + (0x000000000100); //bit 8
00131     if (b5>1) result = result + (0x000000000200); //bit 9
00132     if (b5>0) result = result + (0x000000000400); //bit 10
00133     
00134     //create bit pattern for digit - each digit needs multiple segments to be lit
00135     //7 segments use bits 6, 7, 11, 12, 13, 14 and 15
00136     switch (d1) {
00137         case 0: result = result + (0x01E3 << 6); break; //0001 1110 0011
00138         case 1: result = result + (0x0042 << 6); break; //0000 0100 0010
00139         case 2: result = result + (0x0383 << 6); break; //0011 1000 0011
00140         case 3: result = result + (0x02C3 << 6); break; //0010 1100 0011
00141         case 4: result = result + (0x0262 << 6); break; //0010 0110 0010
00142         case 5: result = result + (0x02E1 << 6); break; //0010 1110 0001
00143         case 6: result = result + (0x03E1 << 6); break; //0011 1110 0001
00144         case 7: result = result + (0x0043 << 6); break; //0000 0100 0011
00145         case 8: result = result + (0x03E3 << 6); break; //0011 1110 0011
00146         case 9: result = result + (0x02E3 << 6); break; //0010 1110 0011
00147         }
00148     //Note least significant 6 bits (0..5) are not used
00149           
00150     return(result);
00151 }
00152 
00153 void PageOLED::SensorPoll(const SensorData &sensordata)
00154 {
00155     Write(Translate(3,sensordata.temperature,4,sensordata.pressure,2,sensordata.pressure));
00156     //printf("%i \n", sensordata.temperature);
00157     
00158 }
00159 
00160 void PageOLED::DiceRoll(const int dicenr)
00161 {
00162     
00163 }
00164 
00165 void PageOLED::HandlePageActions ()
00166 {
00167     //Write(Translate(0,sensordata.temperature,0,sensordata.pressure,0,3));
00168     Log("OLED updated");
00169 }
00170 
00171 } // End Flexbook namespace.
00172 
00173 
00174 
00175 
00176 
00177