LCD implementation of our project.

Dependencies:   mbed mbed-rtos MLX90614

Files at this revision

API Documentation at this revision

Comitter:
ovidiup13
Date:
Fri Mar 20 23:22:41 2015 +0000
Child:
1:0ea18607f944
Commit message:
initial menu mock-up st7565

Changed in this revision

Header.cpp Show annotated file Show diff for this revision Revisions of this file
Header.h Show annotated file Show diff for this revision Revisions of this file
Item.cpp Show annotated file Show diff for this revision Revisions of this file
Item.h Show annotated file Show diff for this revision Revisions of this file
Menu.cpp Show annotated file Show diff for this revision Revisions of this file
Menu.h Show annotated file Show diff for this revision Revisions of this file
Screen.h Show annotated file Show diff for this revision Revisions of this file
UserInterface.cpp Show annotated file Show diff for this revision Revisions of this file
UserInterface.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
st7565LCD.cpp Show annotated file Show diff for this revision Revisions of this file
st7565LCD.h Show annotated file Show diff for this revision Revisions of this file
st7565LCDfont.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Header.cpp	Fri Mar 20 23:22:41 2015 +0000
@@ -0,0 +1,29 @@
+#include "Header.h"
+
+Header::Header(float lvl, float dg, char s, ST7565 * lcd){
+    battery_level = lvl;
+    degrees = dg;
+    scale = s;
+    st7565 = lcd;
+}
+
+void Header::display(void){    
+    //create strings
+    char temp[7], level[5];
+    char sign = ' ';
+    //set sign
+    if(temp > 0) sign = 43;
+    else if(temp < 0) sign = 45;
+    
+    //strcat(temp, sign);
+    
+    //convert to char array
+    sprintf(temp, " %c%.1f%c", sign, degrees, scale);
+    sprintf(level, "%d%%", battery_level);
+    
+    //add to header
+    st7565->drawstring(LEFT_MARGIN, 0, temp);
+    st7565->drawstring(LCDWIDTH - LEFT_MARGIN*4, 0, level);
+    
+    st7565->display();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Header.h	Fri Mar 20 23:22:41 2015 +0000
@@ -0,0 +1,28 @@
+#ifndef _HEADER_H_
+#define _HEADER_H_
+
+#include<stdio.h>
+#include <stdlib.h>
+#include "st7565LCD.h"
+
+#define LEFT_MARGIN 5
+
+using namespace std;
+
+class Header{
+    public:
+        //variables
+        uint8_t battery_level;
+        float degrees;
+        char scale; //celsius
+        ST7565 * st7565;
+        
+        //functions
+        void setScale(char c);
+        void setTemperature(float t);
+        void setBatteryLevel(float d);
+        void display(void);
+        Header(float dg, float lvl, char s, ST7565 * lcd);
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Item.h	Fri Mar 20 23:22:41 2015 +0000
@@ -0,0 +1,37 @@
+#ifndef _ITEM_H
+#define _ITEM_H
+
+#include "st7565LCD.h"
+#include "UserInterface.h"
+
+#define LEFT_MARGIN 5
+#define DEFAULT_COLOR 20
+
+class UI;
+
+class Item {
+    public:
+        //name
+        char * title;
+        ST7565 * st7565;
+        UI * ui;
+        bool isSelectable;
+        
+        //declare pure virtual functions
+        virtual void display(void) = 0;
+        virtual void update(char c) = 0;
+        virtual char * getTitle(void) = 0;
+        
+        //constructors
+        Item(char *title, ST7565 * lcd, UI * ui){
+            this->title = title;
+            this->st7565 = lcd;
+        }
+        Item(void){
+            title = NULL;
+            st7565 = NULL;
+            ui = NULL;
+        }
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Menu.cpp	Fri Mar 20 23:22:41 2015 +0000
@@ -0,0 +1,125 @@
+#include "Menu.h"
+
+void Menu::display(void){
+    ui->setCurrent(this);
+    //if it is a menu item, go to referenced screen
+    if(isScreen){
+        items[0]->display();
+        return;
+    }
+    //otherwise it's a menu, display items
+    current_line = FIRST_ITEM_LINE; //set first item on screen as selected
+    selected = 0;
+    display_items(0); //display items starting from index 0
+}
+
+void Menu::update(char c){
+    //case down
+    if(c == DOWN){
+        //if last item already selected, do nothing
+        if(selected + 1 == size)
+            return; //do nothing
+            
+        //if we are at the bottom of the screen
+        if(current_line % LAST_ITEM_LINE == 0){
+            // more items left => clear screen and add items
+            selected++;
+            //display items from the next selected item
+            current_line = FIRST_ITEM_LINE; //current selected line will be top of screen
+            printf("got down, selected is: %d; current line is: %d\n", selected, current_line);
+        }
+        //it is not last on the screen
+        else{
+            //clear the screen
+            current_line++;
+            selected++;
+            printf("selected is: %d; current line is: %d\n", selected, current_line);
+        }
+        st7565->clear();
+        display_items(selected/6 * 6);
+        return;
+    }
+    //case up
+    else if(c == UP){
+        //we are at top of items
+        if(selected == 0)
+            return; //do nothing
+        
+        //if we are at the top of the screen => there are more items to show
+        if(current_line == FIRST_ITEM_LINE){
+            selected--;
+            //display items from the next selected item
+            current_line = LAST_ITEM_LINE; //current selected line will be top of screen
+            printf("got up, selected is: %d; current line is: %d\n", selected, current_line);
+        }
+        //it is not first on the screen
+        else{
+            current_line--;
+            selected--;
+            printf("selected is: %d; current line is: %d\n", selected, current_line);
+        }
+        st7565->clear();
+        display_items(selected/6 * 6);
+        return;
+    }
+    else if(c == NL && items[selected]->isSelectable){
+        //switch to other screen
+        ui->setCurrent(items[selected]);
+        ui->display();
+    }
+}
+
+void Menu::addItem(Item * i){
+    //if there are many items, ignore
+    if(size == MAX_ITEMS)
+        return;
+    //add pointer to item
+    items[size] = i;
+    size++;
+    isSelectable = true;
+}
+
+/*
+    Function that displays items on a new screen starting from an index.
+*/
+void Menu::display_items(int index){
+    //draw title of menu
+    st7565->drawstring(LEFT_MARGIN, TITLE_LINE, title);
+    //display 1 or more items on the screen
+    int i = FIRST_ITEM_LINE, j;
+    //draw the first items
+    for(j = index; j < size && i <= LAST_ITEM_LINE; j++)
+        st7565->drawstring(LEFT_MARGIN * 4, i++, items[j]->getTitle());
+    
+    //up arrow
+    if(index != 0){
+        st7565->drawline(119, 15, 125, 15,DEFAULT_COLOR);
+        st7565->drawline(119, 15, 122, 12,DEFAULT_COLOR);
+        st7565->drawline(125, 15, 122, 12,DEFAULT_COLOR);
+    }
+    //down arrow
+    if(j < size){
+        st7565->drawline(119, 60, 125, 60,DEFAULT_COLOR);
+        st7565->drawline(119, 60, 122, 63,DEFAULT_COLOR);
+        st7565->drawline(125, 60, 122, 63,DEFAULT_COLOR);
+    }
+    //set selected as first
+    draw_selected();
+    st7565->display();
+}
+
+/*
+    Function that draws a circle near the selected item.
+*/
+void Menu::draw_selected(void){
+    st7565->drawcircle(LEFT_MARGIN*2, (current_line * 8) + 3, 2, 20);
+}
+
+/*
+    Function that draws the arrows indicating whether there are more items
+    in the menu if the user scrolls up or down.
+*/
+void Menu::draw_arrows(int line, char c){
+    
+    //to be implemented
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Menu.h	Fri Mar 20 23:22:41 2015 +0000
@@ -0,0 +1,86 @@
+
+#ifndef _MENU_H_
+#define _MENU_H_
+
+#include<stdio.h>
+#include <stdlib.h>
+#include "st7565LCD.h"
+#include "Item.h"
+
+//define control keys
+#define NL    121 //newline char
+#define BS     8 //backspace
+#define UP   119  
+#define DOWN 115
+
+int const MAX_ITEMS = 16;
+int const TITLE_LINE = 1;
+int const FIRST_ITEM_LINE = 2;
+int const LAST_ITEM_LINE = 7;
+
+class Menu: public Item {
+    public:
+        //Menu will have a limited number of items
+        Item ** items;
+        int size;
+        bool isScreen;
+        //selected items variables
+        int selected, current_line;
+        
+        //menu constructor
+        Menu(char * t, ST7565 *lcd, UI * ui){
+            title = t;
+            st7565 = lcd;
+            items = new Item*[MAX_ITEMS];
+            selected = 0;
+            size = 0;
+            current_line = FIRST_ITEM_LINE;
+            isScreen = false;
+            isSelectable = false;
+            this->ui = ui;
+        }
+        
+        //menu item constructor - go to a screen
+        Menu(char * t, Item *screen, UI *ui){
+            title = t;
+            st7565 = NULL;
+            items = new Item*[1];
+            items[0] = screen;
+            selected = 0;
+            size = 1;
+            current_line = FIRST_ITEM_LINE;
+            isScreen = true;
+            isSelectable = true;
+            this->ui = ui;
+        }
+        
+        //display the menu
+        virtual void display(void);
+        
+        //update current selection
+        virtual void update(char c);
+        
+        //get the title of the menu
+        virtual char * getTitle(void){
+            return title;
+        }
+        
+        //set the title
+        void setTitle(char * t){
+            title = t;
+        }
+        
+         //highlights the current selection
+        void addItem(Item * i);
+        
+        private:
+             //display items on a new screen starting with a specific index
+             void display_items(int index);
+             //draw arrows on right side to indicate there are more items up or down
+             void draw_arrows(int line, char c);
+             //draw the circle indicating which item is selected
+             void draw_selected(void);
+};
+
+#endif
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Screen.h	Fri Mar 20 23:22:41 2015 +0000
@@ -0,0 +1,15 @@
+#ifndef _SCREEN_H
+#define _SCREEN_H
+
+#include "Item.h"
+
+class Screen: public Item {
+    
+    public:
+        
+        //inherited functions
+        void display(void);
+        void update(char *c);    
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UserInterface.cpp	Fri Mar 20 23:22:41 2015 +0000
@@ -0,0 +1,49 @@
+#include "UserInterface.h"
+
+//colors
+PwmOut red(p21);
+PwmOut green(p22);
+PwmOut blue(p23);
+PwmOut a(p24);
+
+void UI::set_colors(float r, float g, float b, float aa){ //red, green, blue, a+
+    //check that colors are between 0.0 and 1.0
+    assert(r >=0 && r <= 1);
+    assert(g >=0 && g <= 1);
+    assert(b >=0 && b <= 1);
+    assert(aa >=0 && aa <= 1);
+    
+    //define colors
+    red = r;
+    green = g;
+    blue = b;
+    a = aa;
+}
+
+void UI::init(void){
+    //initialize variables
+    int brightness = _DEFAULT_BRIGHTNESS;
+    
+    //start LCD and display logo
+    st7565->begin(_DEFAULT_CONTRAST);
+    st7565->st7565_set_brightness(brightness);
+    //set colors
+    set_colors(0, 1, 1, 1);
+    //display logo
+    st7565->display();
+    wait(2.0);
+    
+    st7565->clear();
+}
+
+void UI::display(void){
+    st7565->clear();
+    header->display();
+    current->display();
+}
+
+void UI::update(char c){
+    current->update(c);
+    //display header after update
+    header->display();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UserInterface.h	Fri Mar 20 23:22:41 2015 +0000
@@ -0,0 +1,62 @@
+#ifndef _UI_H_
+#define _UI_H_
+
+#include <string.h>
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "st7565LCD.h"
+#include "Header.h"
+#include "Item.h"
+#include "Menu.h"
+
+//define brightness and contrast
+#define _DEFAULT_BRIGHTNESS 25
+#define _DEFAULT_CONTRAST 20
+#define _MAX_BRIGHTNESS 200
+#define _MIN_BRIGHTNESS 10
+
+//define default color
+#define _DEFAULT_COLOR 20
+
+using namespace std;
+
+class Item;
+
+class UI {
+    public:
+    //variables
+        //current selected menu
+        Item * current;
+        //header object
+        Header * header;
+        //display pointer
+        ST7565 * st7565;
+        
+    //functions
+    //initialize display
+    
+    void init(void);
+    //set colors
+    void set_colors(float r, float g, float b, float aa);
+    //update all screen
+    void update(char c);
+    //update header only
+    void display(void);
+    //update current menu
+    void setCurrent(Item * item){
+        current = item;
+    }
+    //set header
+    void setHeader(Header * h){
+        header = h;
+    }
+    
+    UI(ST7565 *lcd){
+        current = NULL;
+        header = NULL;
+        st7565 = lcd;
+    }
+};
+
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Mar 20 23:22:41 2015 +0000
@@ -0,0 +1,85 @@
+#include "UserInterface.h"
+#include "st7565LCD.h"
+
+//define mbed pins
+#define _MOSI p11
+#define _MISO p12 
+#define _SCLK p13
+#define _RST p8
+#define _A0 p25
+#define _CS p26
+
+ST7565 st7565(_MOSI, _SCLK, _CS, _RST, _A0); // mosi, sclk, cs, rst, a0
+Serial pc(USBTX, USBRX); //rx, tx
+
+int main(){
+    
+    Header * header = new Header(70, 12, 'C', &st7565);
+    UI * ui = new UI(&st7565);
+    
+    //create main menu
+    Menu * main_menu = new Menu(" Main Menu", &st7565, ui);
+    
+    //create measure menu
+    Menu *measure = new Menu(" Measurement", &st7565, ui);
+    measure->addItem(new Menu(" Distance", &st7565, ui));
+    measure->addItem(new Menu(" Area", &st7565, ui));
+    measure->addItem(new Menu(" Volume", &st7565, ui));
+    measure->addItem(new Menu(" Back", main_menu, ui));
+    
+    //create compass menu
+    Menu *compass = new Menu(" Compass", &st7565, ui);
+    compass->addItem(new Menu("Back", main_menu, ui));
+    
+    //create level meter menu
+    Menu *lvlm = new Menu(" Level meter", &st7565, ui);
+    lvlm->addItem(new Menu(" Back", main_menu, ui));
+    
+    //settings menu
+    Menu *settings = new Menu(" Settings", &st7565, ui);
+    Menu *b_settings = new Menu(" Brightness", &st7565, ui);
+    Menu *s_settings = new Menu(" Screen Colour", &st7565, ui);
+    Menu *m_settings = new Menu(" Measure settings", &st7565, ui);
+    settings->addItem(m_settings);
+    settings->addItem(s_settings);
+    settings->addItem(b_settings);
+    settings->addItem(new Menu(" Back", main_menu, ui));
+    
+    //test menus
+    Menu *s1 = new Menu(" s2", &st7565, ui);
+    Menu *s2 = new Menu(" s3", &st7565, ui);
+    Menu *s3 = new Menu(" s4", &st7565, ui);
+    Menu *s4 = new Menu(" s5", &st7565, ui);
+    Menu *s5 = new Menu(" s6", &st7565, ui);
+    Menu *s7 = new Menu(" s7", &st7565, ui);
+    Menu *s8 = new Menu(" s8", &st7565, ui);
+    Menu *s9 = new Menu(" s9", &st7565, ui);
+    Menu *s10 = new Menu(" s10", &st7565, ui);
+    
+    //add menus to main menu
+    main_menu->addItem(measure);
+    main_menu->addItem(compass);
+    main_menu->addItem(lvlm);
+    main_menu->addItem(settings);
+    main_menu->addItem(s1);
+    main_menu->addItem(s2);
+    main_menu->addItem(s3);
+    
+    main_menu->addItem(s4);
+    main_menu->addItem(s5);
+    main_menu->addItem(s7);
+    main_menu->addItem(s8);
+    main_menu->addItem(s9);
+    main_menu->addItem(s10);
+    
+    ui->setHeader(header);
+    ui->setCurrent(main_menu);
+    
+    ui->init();
+    ui->display();
+    while(1) {
+        char c = pc.getc();
+        pc.putc(c);
+        ui->update(c);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Mar 20 23:22:41 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/st7565LCD.cpp	Fri Mar 20 23:22:41 2015 +0000
@@ -0,0 +1,561 @@
+/*
+$Id:$
+ 
+ST7565 LCD library!
+ 
+Copyright (C) 2010 Limor Fried, Adafruit Industries
+ 
+This library 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 2.1 of the License, or (at your option) any later version.
+ 
+This library 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 this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ 
+// some of this code was written by <cstone@pobox.com> originally; it is in the public domain.
+ 
+ 
+******the library is modified for mbed**********
+    http://www.adafruit.com/products/250
+    
+    *!function drawbitmap(); is left undone!*
+    
+                    2014/03/18     by imachooon
+                    mailto: imachooon@gmail.com
+************************************************
+*/
+ 
+#include "st7565LCD.h"
+#include "st7565LCDfont.h"
+ 
+#define ST7565_STARTBYTES 1
+ 
+uint8_t is_reversed = 0;
+ 
+// a handy reference to where the pages are on the screen
+const uint8_t pagemap[] = { 3, 2, 1, 0, 7, 6, 5, 4 };
+ 
+// a 5x7 font table
+extern const uint8_t font[];
+ 
+// the memory buffer for the LCD
+uint8_t st7565_buffer[1024] = {
+    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+    0x0, 0x0, 0x0, 0x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, 0x0, 0x0, 0x0,
+    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+};
+ 
+ 
+ 
+ 
+// reduces how much is refreshed, which speeds it up!
+// originally derived from Steve Evans/JCW's mod but cleaned up and
+// optimized
+#define enablePartialUpdate
+ 
+#ifdef enablePartialUpdate
+static uint8_t xUpdateMin, xUpdateMax, yUpdateMin, yUpdateMax;
+#endif
+ 
+ 
+ 
+static void updateBoundingBox(uint8_t xmin, uint8_t ymin, uint8_t xmax, uint8_t ymax)
+{
+#ifdef enablePartialUpdate
+    if (xmin < xUpdateMin) xUpdateMin = xmin;
+    if (xmax > xUpdateMax) xUpdateMax = xmax;
+    if (ymin < yUpdateMin) yUpdateMin = ymin;
+    if (ymax > yUpdateMax) yUpdateMax = ymax;
+#endif
+}
+ 
+/*
+void ST7565::drawbitmap(uint8_t x, uint8_t y,
+            const uint8_t *bitmap, uint8_t w, uint8_t h,
+            uint8_t color) {
+  for (uint8_t i=0; i<h; i++) {
+    for (uint8_t j=0; j<w; j++ ) {
+      if (pgm_read_byte(bitmap + j + (j/8)*w) & _BV(j%8)) {
+    my_setpixel(x+j, y+i, color);
+      }
+    }
+  }
+ 
+  updateBoundingBox(x, y, x+w, y+h);
+}
+*/
+ 
+void ST7565::drawstring(uint8_t x, uint8_t line, char *c)
+{
+    while (*c != '\0') {
+        drawchar(x, line, *c);
+        *c++;
+        x += 6; // 6 pixels wide
+        if (x + 6 >= LCDWIDTH) {
+            x = 0;    // ran out of this line
+            line++;
+        }
+        if (line >= (LCDHEIGHT/8))
+            return;        // ran out of space :(
+    }
+}
+ 
+ 
+void  ST7565::drawchar(uint8_t x, uint8_t line, char c)
+{
+    for (uint8_t i =0; i<5; i++ ) {
+        *(st7565_buffer + x + line*128) = *(font + (c*5) + i);
+        x++;
+    }
+    updateBoundingBox(x, line*8, x+5, line*8+8);    //only updates relevant area of LCD
+}
+ 
+ 
+// bresenham's algorithm - thx wikpedia
+void ST7565::drawline(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1,
+                      uint8_t color)
+{
+    uint8_t steep = abs(y1 - y0) > abs(x1 - x0);
+    if (steep) {
+        swap(x0, y0);
+        swap(x1, y1);
+    }
+ 
+    if (x0 > x1) {
+        swap(x0, x1);
+        swap(y0, y1);
+    }
+ 
+    // much faster to put the test here, since we've already sorted the points
+    updateBoundingBox(x0, y0, x1, y1);
+ 
+    uint8_t dx, dy;
+    dx = x1 - x0;
+    dy = abs(y1 - y0);
+ 
+    int8_t err = dx / 2;
+    int8_t ystep;
+ 
+    if (y0 < y1) {
+        ystep = 1;
+    } else {
+        ystep = -1;
+    }
+ 
+    for (; x0<=x1; x0++) {
+        if (steep) {
+            my_setpixel(y0, x0, color);
+        } else {
+            my_setpixel(x0, y0, color);
+        }
+        err -= dy;
+        if (err < 0) {
+            y0 += ystep;
+            err += dx;
+        }
+    }
+}
+ 
+// filled rectangle
+void ST7565::fillrect(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
+                      uint8_t color)
+{
+ 
+    // stupidest version - just pixels - but fast with internal buffer!
+    for (uint8_t i=x; i<x+w; i++) {
+        for (uint8_t j=y; j<y+h; j++) {
+            my_setpixel(i, j, color);
+        }
+    }
+ 
+    updateBoundingBox(x, y, x+w, y+h);
+}
+ 
+// draw a rectangle
+void ST7565::drawrect(uint8_t x, uint8_t y, uint8_t w, uint8_t h,
+                      uint8_t color)
+{
+    // stupidest version - just pixels - but fast with internal buffer!
+    for (uint8_t i=x; i<x+w; i++) {
+        my_setpixel(i, y, color);
+        my_setpixel(i, y+h-1, color);
+    }
+    for (uint8_t i=y; i<y+h; i++) {
+        my_setpixel(x, i, color);
+        my_setpixel(x+w-1, i, color);
+    }
+ 
+    updateBoundingBox(x, y, x+w, y+h);
+}
+ 
+// draw a circle outline
+void ST7565::drawcircle(uint8_t x0, uint8_t y0, uint8_t r,
+                        uint8_t color)
+{
+    updateBoundingBox(x0-r, y0-r, x0+r, y0+r);
+ 
+    int8_t f = 1 - r;
+    int8_t ddF_x = 1;
+    int8_t ddF_y = -2 * r;
+    int8_t x = 0;
+    int8_t y = r;
+ 
+    my_setpixel(x0, y0+r, color);
+    my_setpixel(x0, y0-r, color);
+    my_setpixel(x0+r, y0, color);
+    my_setpixel(x0-r, y0, color);
+ 
+    while (x<y) {
+        if (f >= 0) {
+            y--;
+            ddF_y += 2;
+            f += ddF_y;
+        }
+        x++;
+        ddF_x += 2;
+        f += ddF_x;
+ 
+        my_setpixel(x0 + x, y0 + y, color);
+        my_setpixel(x0 - x, y0 + y, color);
+        my_setpixel(x0 + x, y0 - y, color);
+        my_setpixel(x0 - x, y0 - y, color);
+ 
+        my_setpixel(x0 + y, y0 + x, color);
+        my_setpixel(x0 - y, y0 + x, color);
+        my_setpixel(x0 + y, y0 - x, color);
+        my_setpixel(x0 - y, y0 - x, color);
+ 
+    }
+}
+ 
+void ST7565::fillcircle(uint8_t x0, uint8_t y0, uint8_t r,
+                        uint8_t color)
+{
+    updateBoundingBox(x0-r, y0-r, x0+r, y0+r);
+ 
+    int8_t f = 1 - r;
+    int8_t ddF_x = 1;
+    int8_t ddF_y = -2 * r;
+    int8_t x = 0;
+    int8_t y = r;
+ 
+    for (uint8_t i=y0-r; i<=y0+r; i++) {
+        my_setpixel(x0, i, color);
+    }
+ 
+    while (x<y) {
+        if (f >= 0) {
+            y--;
+            ddF_y += 2;
+            f += ddF_y;
+        }
+        x++;
+        ddF_x += 2;
+        f += ddF_x;
+ 
+        for (uint8_t i=y0-y; i<=y0+y; i++) {
+            my_setpixel(x0+x, i, color);
+            my_setpixel(x0-x, i, color);
+        }
+        for (uint8_t i=y0-x; i<=y0+x; i++) {
+            my_setpixel(x0+y, i, color);
+            my_setpixel(x0-y, i, color);
+        }
+    }
+}
+ 
+void ST7565::my_setpixel(uint8_t x, uint8_t y, uint8_t color)
+{
+    if ((x >= LCDWIDTH) || (y >= LCDHEIGHT))
+        return;
+ 
+    // x is which column
+    if (color)
+        st7565_buffer[x+ (y/8)*128] |= _BV(7-(y%8));
+    else
+        st7565_buffer[x+ (y/8)*128] &= _nBV(7-(y%8));
+}
+ 
+// the most basic function, set a single pixel
+void ST7565::setpixel(uint8_t x, uint8_t y, uint8_t color)
+{
+    if ((x >= LCDWIDTH) || (y >= LCDHEIGHT))
+        return;
+    // x is which column
+    if (color)
+        st7565_buffer[x+ (y/8)*128] |= _BV(7-(y%8));
+    else
+        st7565_buffer[x+ (y/8)*128] &= _nBV(7-(y%8));
+ 
+    updateBoundingBox(x,y,x,y);
+}
+ 
+ 
+// the most basic function, get a single pixel
+uint8_t ST7565::getpixel(uint8_t x, uint8_t y)
+{
+    if ((x >= LCDWIDTH) || (y >= LCDHEIGHT))
+        return 0;
+ 
+    return (st7565_buffer[x+ (y/8)*128] >> (7-(y%8))) & 0x1;
+}
+ 
+ 
+ST7565::ST7565(PinName mosi, PinName sclk, PinName cs, PinName rst, PinName a0)
+// set pin directions
+    : _spi(mosi, NC, sclk), _cs(cs), _rst(rst), _a0(a0)
+ 
+{
+    _spi.format(8, 0);
+    _spi.frequency(1000000);
+}
+ 
+ 
+ 
+void ST7565::st7565_init(void)
+{
+    wait_ms(100); 
+    _rst = 0;
+    wait_ms(100);
+    _rst = 1;
+    
+ 
+    // LCD bias select
+    st7565_command(CMD_SET_BIAS_7);
+    // ADC select
+    st7565_command(CMD_SET_ADC_NORMAL);
+    // SHL select
+    st7565_command(CMD_SET_COM_NORMAL);
+ 
+    // turn on voltage converter (VC=1, VR=0, VF=0)
+    st7565_command(CMD_SET_POWER_CONTROL | 0x4);
+    // wait for 50% rising
+    wait_ms(50);
+ 
+    // turn on voltage regulator (VC=1, VR=1, VF=0)
+    st7565_command(CMD_SET_POWER_CONTROL | 0x6);
+    // wait >=50ms
+    wait_ms(20);
+ 
+    // turn on voltage follower (VC=1, VR=1, VF=1)
+    st7565_command(CMD_SET_POWER_CONTROL | 0x7);
+    // wait
+    wait_ms(10);
+    
+    // set lcd operating voltage (regulator resistor, ref voltage resistor)
+    st7565_command(CMD_SET_RESISTOR_RATIO | 0x4);
+    wait_ms(10);
+ 
+ 
+//    st7565_set_brightness(INITIAL_CONTRAST);
+    // set up a bounding box for screen updates
+    updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1);
+ 
+ 
+    st7565_command(CMD_DISPLAY_ON);
+    st7565_command(CMD_SET_ALLPTS_NORMAL);
+    
+    
+    // reference voltage resistor    
+    st7565_command(CMD_SET_VOLUME_FIRST);
+    wait_ms(10);
+    st7565_command(CMD_SET_VOLUME_SECOND);
+    wait_ms(10);
+ 
+ 
+ 
+    // Initial display line ( = 0)
+    st7565_command(CMD_SET_DISP_START_LINE);
+    // Initial page address ( = 0)
+    st7565_command(CMD_SET_PAGE);    
+    st7565_command(CMD_SET_COLUMN_UPPER);
+    st7565_command(CMD_SET_COLUMN_LOWER);
+    
+}
+ 
+inline void ST7565::spiwrite(uint8_t c)
+{
+    _spi.write(c);
+}
+ 
+void ST7565::st7565_command(uint8_t c)
+{
+    _cs = 0;
+    _a0 = 0;
+    _spi.write(c);
+    _cs = 1;
+}
+ 
+void ST7565::st7565_data(uint8_t c)
+{
+    _cs = 0;
+    _a0 = 1;
+    _spi.write(c);
+    _cs = 1;
+}
+ 
+void ST7565::st7565_set_brightness(uint8_t val)
+{
+    st7565_command(CMD_SET_VOLUME_FIRST);
+    st7565_command(CMD_SET_VOLUME_SECOND | (val & 0x3f));
+}
+ 
+void ST7565::begin(uint8_t contrast){
+    st7565_init();
+  st7565_command(CMD_DISPLAY_ON);
+  st7565_command(CMD_SET_ALLPTS_NORMAL);
+  st7565_set_brightness(contrast);
+}
+    
+ 
+void ST7565::display(void)
+{
+    uint8_t col, maxcol, p;
+ 
+    for(p = 0; p < 8; p++) {
+#ifdef enablePartialUpdate
+        // check if this page is part of update
+        if ( yUpdateMin >= ((p+1)*8) ) {
+            continue;   // nope, skip it!
+        }
+        if (yUpdateMax < p*8) {
+            break;
+        }
+#endif
+        st7565_command(CMD_SET_PAGE | pagemap[p]);
+ 
+#ifdef enablePartialUpdate
+        col = xUpdateMin;
+        maxcol = xUpdateMax;
+#else
+        // start at the beginning of the row
+        col = 0;
+        maxcol = LCDWIDTH-1;
+#endif
+ 
+        st7565_command(CMD_SET_COLUMN_LOWER | ((col+ST7565_STARTBYTES) & 0xf));
+        st7565_command(CMD_SET_COLUMN_UPPER | (((col+ST7565_STARTBYTES) >> 4) & 0x0F));
+        st7565_command(CMD_RMW);
+ 
+        for(; col <= maxcol; col++) {
+            st7565_data(st7565_buffer[(128*p)+col]);
+        }
+    }
+ 
+#ifdef enablePartialUpdate
+    xUpdateMin = LCDWIDTH - 1;
+    xUpdateMax = 0;
+    yUpdateMin = LCDHEIGHT-1;
+    yUpdateMax = 0;
+#endif
+}
+ 
+// clear everything
+void ST7565::clear(void)
+{
+    memset(st7565_buffer, 0, 1024);
+    updateBoundingBox(0, 0, LCDWIDTH-1, LCDHEIGHT-1);
+}
+ 
+ 
+// this doesnt touch the buffer, just clears the display RAM - might be handy
+void ST7565::clear_display(void)
+{
+    uint8_t p, c;
+ 
+    for(p = 0; p < 8; p++) {
+ 
+        st7565_command(CMD_SET_PAGE | p);
+        for(c = 0; c < 129; c++) {
+            st7565_command(CMD_SET_COLUMN_LOWER | (c & 0xf));
+            st7565_command(CMD_SET_COLUMN_UPPER | ((c >> 4) & 0xf));
+            st7565_data(0x0);
+        }
+    }
+}
+ 
+//additional function to set a bit
+uint8_t ST7565::_BV(uint8_t bit)
+{
+    return 1 << bit;
+}
+ 
+uint8_t ST7565::_nBV(uint8_t bit)
+{
+    return 0 << bit;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/st7565LCD.h	Fri Mar 20 23:22:41 2015 +0000
@@ -0,0 +1,125 @@
+/*
+$Id:$
+ 
+ST7565 LCD library!
+ 
+Copyright (C) 2010 Limor Fried, Adafruit Industries
+ 
+This library 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 2.1 of the License, or (at your option) any later version.
+ 
+This library 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 this library; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ 
+// some of this code was written by <cstone@pobox.com> originally; it is in the public domain.
+*/
+ 
+ 
+#ifndef _st7565LCD_H_
+#define _st7565LCD_H_
+ 
+#include "mbed.h"
+ 
+#define swap(a, b) { uint8_t t = a; a = b; b = t; }
+ 
+#define BLACK 1
+#define WHITE 0
+ 
+#define LCDWIDTH 128
+#define LCDHEIGHT 64
+ 
+#define INITIAL_CONTRAST 0x18
+ 
+#define CMD_DISPLAY_OFF   0xAE
+#define CMD_DISPLAY_ON    0xAF
+ 
+#define CMD_SET_DISP_START_LINE  0x40
+#define CMD_SET_PAGE  0xB0
+ 
+#define CMD_SET_COLUMN_UPPER  0x10
+#define CMD_SET_COLUMN_LOWER  0x00
+ 
+#define CMD_SET_ADC_NORMAL  0xA0
+#define CMD_SET_ADC_REVERSE 0xA1
+ 
+#define CMD_SET_DISP_NORMAL 0xA6
+#define CMD_SET_DISP_REVERSE 0xA7
+ 
+#define CMD_SET_ALLPTS_NORMAL 0xA4
+#define CMD_SET_ALLPTS_ON  0xA5
+#define CMD_SET_BIAS_9 0xA2 
+#define CMD_SET_BIAS_7 0xA3
+ 
+#define CMD_RMW  0xE0
+#define CMD_RMW_CLEAR 0xEE
+#define CMD_INTERNAL_RESET  0xE2
+#define CMD_SET_COM_NORMAL  0xC0
+#define CMD_SET_COM_REVERSE  0xC8
+#define CMD_SET_POWER_CONTROL  0x28
+#define CMD_SET_RESISTOR_RATIO  0x20
+#define CMD_SET_VOLUME_FIRST  0x81
+#define  CMD_SET_VOLUME_SECOND  0x00
+#define CMD_SET_STATIC_OFF  0xAC
+#define  CMD_SET_STATIC_ON  0xAD
+#define CMD_SET_STATIC_REG  0x0
+#define CMD_SET_BOOSTER_FIRST  0xF8
+#define CMD_SET_BOOSTER_234  0
+#define  CMD_SET_BOOSTER_5  1
+#define  CMD_SET_BOOSTER_6  3
+#define CMD_NOP  0xE3
+#define CMD_TEST  0xF0
+ 
+class ST7565 {
+     
+ private:
+  SPI _spi;
+  DigitalOut _cs;
+  DigitalOut _rst;
+  DigitalOut _a0;
+  void spiwrite(uint8_t c);
+  void my_setpixel(uint8_t x, uint8_t y, uint8_t color);
+ 
+  //uint8_t buffer[128*64/8]; 
+ public:
+  ST7565(PinName mosi, PinName sclk, PinName cs, PinName rst, PinName a0);
+  ~ST7565() {};
+  void st7565_init(void);
+  void begin(uint8_t contrast);
+  void st7565_command(uint8_t c);
+  void st7565_data(uint8_t c);
+  void st7565_set_brightness(uint8_t val);
+  void clear_display(void);
+  void clear();
+  void display();
+ 
+  void setpixel(uint8_t x, uint8_t y, uint8_t color);
+  uint8_t getpixel(uint8_t x, uint8_t y);
+  void fillcircle(uint8_t x0, uint8_t y0, uint8_t r, 
+          uint8_t color);
+  void drawcircle(uint8_t x0, uint8_t y0, uint8_t r, 
+          uint8_t color);
+  void drawrect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, 
+        uint8_t color);
+  void fillrect(uint8_t x, uint8_t y, uint8_t w, uint8_t h, 
+        uint8_t color);
+  void drawline(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1, 
+        uint8_t color);
+  void drawchar(uint8_t x, uint8_t line, char c);
+  void drawstring(uint8_t x, uint8_t line, char *c);
+  /*void drawbitmap(uint8_t x, uint8_t y, 
+          const uint8_t *bitmap, uint8_t w, uint8_t h,
+          uint8_t color);*/
+  uint8_t _BV(uint8_t bit);
+  uint8_t _nBV(uint8_t bit);
+ 
+};
+ 
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/st7565LCDfont.h	Fri Mar 20 23:22:41 2015 +0000
@@ -0,0 +1,259 @@
+ 
+ 
+// 5x7 LCD font 'flipped' for the ST7565 - public domain
+static const uint8_t font[] = { 
+  0x0, 0x0, 0x0, 0x0, 0x0,       // Ascii 0
+  0x7C, 0xDA, 0xF2, 0xDA, 0x7C,  //ASC(01)
+  0x7C, 0xD6, 0xF2, 0xD6, 0x7C,  //ASC(02)
+  0x38, 0x7C, 0x3E, 0x7C, 0x38, 
+  0x18, 0x3C, 0x7E, 0x3C, 0x18, 
+  0x38, 0xEA, 0xBE, 0xEA, 0x38, 
+  0x38, 0x7A, 0xFE, 0x7A, 0x38, 
+  0x0, 0x18, 0x3C, 0x18, 0x0, 
+  0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 
+  0x0, 0x18, 0x24, 0x18, 0x0, 
+  0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 
+  0xC, 0x12, 0x5C, 0x60, 0x70, 
+  0x64, 0x94, 0x9E, 0x94, 0x64, 
+  0x2, 0xFE, 0xA0, 0xA0, 0xE0, 
+  0x2, 0xFE, 0xA0, 0xA4, 0xFC, 
+  0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 
+  0xFE, 0x7C, 0x38, 0x38, 0x10, 
+  0x10, 0x38, 0x38, 0x7C, 0xFE, 
+  0x28, 0x44, 0xFE, 0x44, 0x28, 
+  0xFA, 0xFA, 0x0, 0xFA, 0xFA, 
+  0x60, 0x90, 0xFE, 0x80, 0xFE, 
+  0x0, 0x66, 0x91, 0xA9, 0x56, 
+  0x6, 0x6, 0x6, 0x6, 0x6,
+  0x29, 0x45, 0xFF, 0x45, 0x29, 
+  0x10, 0x20, 0x7E, 0x20, 0x10, 
+  0x8, 0x4, 0x7E, 0x4, 0x8, 
+  0x10, 0x10, 0x54, 0x38, 0x10, 
+  0x10, 0x38, 0x54, 0x10, 0x10, 
+  0x78, 0x8, 0x8, 0x8, 0x8, 
+  0x30, 0x78, 0x30, 0x78, 0x30, 
+  0xC, 0x1C, 0x7C, 0x1C, 0xC, 
+  0x60, 0x70, 0x7C, 0x70, 0x60, 
+  0x0, 0x0, 0x0, 0x0, 0x0, 
+  0x0, 0x0, 0xFA, 0x0, 0x0, 
+  0x0, 0xE0, 0x0, 0xE0, 0x0, 
+  0x28, 0xFE, 0x28, 0xFE, 0x28, 
+  0x24, 0x54, 0xFE, 0x54, 0x48, 
+  0xC4, 0xC8, 0x10, 0x26, 0x46, 
+  0x6C, 0x92, 0x6A, 0x4, 0xA, 
+  0x0, 0x10, 0xE0, 0xC0, 0x0, 
+  0x0, 0x38, 0x44, 0x82, 0x0, 
+  0x0, 0x82, 0x44, 0x38, 0x0, 
+  0x54, 0x38, 0xFE, 0x38, 0x54, 
+  0x10, 0x10, 0x7C, 0x10, 0x10, 
+  0x0, 0x1, 0xE, 0xC, 0x0, 
+  0x10, 0x10, 0x10, 0x10, 0x10, 
+  0x0, 0x0, 0x6, 0x6, 0x0, 
+  0x4, 0x8, 0x10, 0x20, 0x40, 
+  0x7C, 0x8A, 0x92, 0xA2, 0x7C, 
+  0x0, 0x42, 0xFE, 0x2, 0x0, 
+  0x4E, 0x92, 0x92, 0x92, 0x62, 
+  0x84, 0x82, 0x92, 0xB2, 0xCC, 
+  0x18, 0x28, 0x48, 0xFE, 0x8, 
+  0xE4, 0xA2, 0xA2, 0xA2, 0x9C, 
+  0x3C, 0x52, 0x92, 0x92, 0x8C, 
+  0x82, 0x84, 0x88, 0x90, 0xE0, 
+  0x6C, 0x92, 0x92, 0x92, 0x6C, 
+  0x62, 0x92, 0x92, 0x94, 0x78, 
+  0x0, 0x0, 0x28, 0x0, 0x0, 
+  0x0, 0x2, 0x2C, 0x0, 0x0, 
+  0x0, 0x10, 0x28, 0x44, 0x82, 
+  0x28, 0x28, 0x28, 0x28, 0x28, 
+  0x0, 0x82, 0x44, 0x28, 0x10, 
+  0x40, 0x80, 0x9A, 0x90, 0x60, 
+  0x7C, 0x82, 0xBA, 0x9A, 0x72, 
+  0x3E, 0x48, 0x88, 0x48, 0x3E, 
+  0xFE, 0x92, 0x92, 0x92, 0x6C, 
+  0x7C, 0x82, 0x82, 0x82, 0x44, 
+  0xFE, 0x82, 0x82, 0x82, 0x7C, 
+  0xFE, 0x92, 0x92, 0x92, 0x82, 
+  0xFE, 0x90, 0x90, 0x90, 0x80, 
+  0x7C, 0x82, 0x82, 0x8A, 0xCE, 
+  0xFE, 0x10, 0x10, 0x10, 0xFE, 
+  0x0, 0x82, 0xFE, 0x82, 0x0, 
+  0x4, 0x2, 0x82, 0xFC, 0x80, 
+  0xFE, 0x10, 0x28, 0x44, 0x82, 
+  0xFE, 0x2, 0x2, 0x2, 0x2, 
+  0xFE, 0x40, 0x38, 0x40, 0xFE, 
+  0xFE, 0x20, 0x10, 0x8, 0xFE, 
+  0x7C, 0x82, 0x82, 0x82, 0x7C, 
+  0xFE, 0x90, 0x90, 0x90, 0x60, 
+  0x7C, 0x82, 0x8A, 0x84, 0x7A, 
+  0xFE, 0x90, 0x98, 0x94, 0x62, 
+  0x64, 0x92, 0x92, 0x92, 0x4C, 
+  0xC0, 0x80, 0xFE, 0x80, 0xC0, 
+  0xFC, 0x2, 0x2, 0x2, 0xFC, 
+  0xF8, 0x4, 0x2, 0x4, 0xF8, 
+  0xFC, 0x2, 0x1C, 0x2, 0xFC, 
+  0xC6, 0x28, 0x10, 0x28, 0xC6, 
+  0xC0, 0x20, 0x1E, 0x20, 0xC0, 
+  0x86, 0x9A, 0x92, 0xB2, 0xC2, 
+  0x0, 0xFE, 0x82, 0x82, 0x82, 
+  0x40, 0x20, 0x10, 0x8, 0x4, 
+  0x0, 0x82, 0x82, 0x82, 0xFE, 
+  0x20, 0x40, 0x80, 0x40, 0x20, 
+  0x2, 0x2, 0x2, 0x2, 0x2, 
+  0x0, 0xC0, 0xE0, 0x10, 0x0, 
+  0x4, 0x2A, 0x2A, 0x1E, 0x2, 
+  0xFE, 0x14, 0x22, 0x22, 0x1C, 
+  0x1C, 0x22, 0x22, 0x22, 0x14, 
+  0x1C, 0x22, 0x22, 0x14, 0xFE, 
+  0x1C, 0x2A, 0x2A, 0x2A, 0x18, 
+  0x0, 0x10, 0x7E, 0x90, 0x40, 
+  0x18, 0x25, 0x25, 0x39, 0x1E, 
+  0xFE, 0x10, 0x20, 0x20, 0x1E, 
+  0x0, 0x22, 0xBE, 0x2, 0x0, 
+  0x4, 0x2, 0x2, 0xBC, 0x0, 
+  0xFE, 0x8, 0x14, 0x22, 0x0, 
+  0x0, 0x82, 0xFE, 0x2, 0x0, 
+  0x3E, 0x20, 0x1E, 0x20, 0x1E, 
+  0x3E, 0x10, 0x20, 0x20, 0x1E, 
+  0x1C, 0x22, 0x22, 0x22, 0x1C, 
+  0x3F, 0x18, 0x24, 0x24, 0x18, 
+  0x18, 0x24, 0x24, 0x18, 0x3F, 
+  0x3E, 0x10, 0x20, 0x20, 0x10, 
+  0x12, 0x2A, 0x2A, 0x2A, 0x24, 
+  0x20, 0x20, 0xFC, 0x22, 0x24, 
+  0x3C, 0x2, 0x2, 0x4, 0x3E, 
+  0x38, 0x4, 0x2, 0x4, 0x38, 
+  0x3C, 0x2, 0xC, 0x2, 0x3C, 
+  0x22, 0x14, 0x8, 0x14, 0x22, 
+  0x32, 0x9, 0x9, 0x9, 0x3E, 
+  0x22, 0x26, 0x2A, 0x32, 0x22, 
+  0x0, 0x10, 0x6C, 0x82, 0x0, 
+  0x0, 0x0, 0xEE, 0x0, 0x0, 
+  0x0, 0x82, 0x6C, 0x10,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 
+  0x2, 0x7E, 0x4, 0x78, 0x4, 
+  0x60, 0x40, 0x7E, 0x40, 0x40, 
+  0x99, 0xA5, 0xE7, 0xA5, 0x99, 
+  0x38, 0x54, 0x92, 0x54, 0x38, 
+  0x32, 0x4E, 0x80, 0x4E, 0x32, 
+  0xC, 0x52, 0xB2, 0xB2, 0xC, 
+  0xC, 0x12, 0x1E, 0x12, 0xC, 
+  0x3D, 0x46, 0x5A, 0x62, 0xBC, 
+  0x7C, 0x92, 0x92, 0x92, 0x0, 
+  0x7E, 0x80, 0x80, 0x80, 0x7E, 
+  0x54, 0x54, 0x54, 0x54, 0x54, 
+  0x22, 0x22, 0xFA, 0x22, 0x22, 
+  0x2, 0x8A, 0x52, 0x22, 0x2, 
+  0x2, 0x22, 0x52, 0x8A, 0x2, 
+  0x0, 0x0, 0xFF, 0x80, 0xC0, 
+  0x7, 0x1, 0xFF, 0x0, 0x0, 
+  0x10, 0x10, 0xD6, 0xD6, 0x10,
+  0x6C, 0x48, 0x6C, 0x24, 0x6C, 
+  0x60, 0xF0, 0x90, 0xF0, 0x60, 
+  0x0, 0x0, 0x18, 0x18, 0x0, 
+  0x0, 0x0, 0x8, 0x8, 0x0, 
+  0xC, 0x2, 0xFF, 0x80, 0x80, 
+  0x0, 0xF8, 0x80, 0x80, 0x78, 
+  0x0, 0x98, 0xB8, 0xE8, 0x48, 
+  0x0, 0x3C, 0x3C, 0x3C, 0x3C,};
\ No newline at end of file