ELEC2645 (2018/19) / Mbed 2 deprecated el17ajf

Dependencies:   mbed

Fork of el17ajf by Angus Findlay

Committer:
el17ajf
Date:
Fri Mar 15 20:30:01 2019 +0000
Revision:
9:3a7776a29a11
Parent:
8:5066ce13a430
Child:
10:5762d7fae033
added more graphics methods

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17ajf 5:3efbdcb3efaf 1 #include "Graphics.h"
el17ajf 5:3efbdcb3efaf 2
el17ajf 8:5066ce13a430 3 void Graphics::init() {
el17ajf 8:5066ce13a430 4 lcd = new N5110(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
el17ajf 9:3a7776a29a11 5 lcd->init();
el17ajf 9:3a7776a29a11 6 lcd->setContrast(0.4);
el17ajf 8:5066ce13a430 7 }
el17ajf 8:5066ce13a430 8
el17ajf 8:5066ce13a430 9 void Graphics::deinit() {
el17ajf 8:5066ce13a430 10 delete lcd;
el17ajf 8:5066ce13a430 11 }
el17ajf 8:5066ce13a430 12
el17ajf 5:3efbdcb3efaf 13 void Graphics::update() {
el17ajf 9:3a7776a29a11 14 // TODO (needed?)
el17ajf 5:3efbdcb3efaf 15 }
el17ajf 5:3efbdcb3efaf 16
el17ajf 5:3efbdcb3efaf 17 void Graphics::clear() {
el17ajf 9:3a7776a29a11 18 lcd->clear();
el17ajf 5:3efbdcb3efaf 19 }
el17ajf 5:3efbdcb3efaf 20
el17ajf 5:3efbdcb3efaf 21 void Graphics::render() {
el17ajf 9:3a7776a29a11 22 lcd->refresh();
el17ajf 8:5066ce13a430 23 }
el17ajf 8:5066ce13a430 24
el17ajf 8:5066ce13a430 25 void Graphics::drawPoint(int x, int y) {
el17ajf 8:5066ce13a430 26 lcd->setPixel(x, y, true);
el17ajf 8:5066ce13a430 27 }
el17ajf 8:5066ce13a430 28
el17ajf 8:5066ce13a430 29 void Graphics::drawLine(int x1, int y1, int x2, int y2) {
el17ajf 8:5066ce13a430 30 lcd->drawLine(x1, y1, x2, y2, 1);
el17ajf 8:5066ce13a430 31 }
el17ajf 8:5066ce13a430 32
el17ajf 8:5066ce13a430 33 void Graphics::drawDottedLine(int x1, int y1, int x2, int y2) {
el17ajf 8:5066ce13a430 34 lcd->drawLine(x1, y1, x2, y2, 2);
el17ajf 8:5066ce13a430 35 }
el17ajf 8:5066ce13a430 36
el17ajf 8:5066ce13a430 37 void Graphics::drawBox(int x1, int y1, int x2, int y2) {
el17ajf 8:5066ce13a430 38 Graphics::drawLine(x1, y1, x2, y1);
el17ajf 8:5066ce13a430 39 Graphics::drawLine(x2, y1, x2, y2);
el17ajf 8:5066ce13a430 40 Graphics::drawLine(x2, y2, x1, y2);
el17ajf 8:5066ce13a430 41 Graphics::drawLine(x1, y2, x1, y1);
el17ajf 8:5066ce13a430 42 }
el17ajf 8:5066ce13a430 43
el17ajf 8:5066ce13a430 44 void Graphics::drawBlock(int grid_x, int grid_y) {
el17ajf 8:5066ce13a430 45 // TODO
el17ajf 8:5066ce13a430 46 int x = grid_x;
el17ajf 9:3a7776a29a11 47 int y = grid_y;
el17ajf 8:5066ce13a430 48 Graphics::drawBox(x, y, x + 3, y + 3);
el17ajf 8:5066ce13a430 49 Graphics::drawPoint(x + 2, y + 2);
el17ajf 8:5066ce13a430 50 }
el17ajf 8:5066ce13a430 51
el17ajf 8:5066ce13a430 52 void Graphics::drawBorder() {
el17ajf 8:5066ce13a430 53 Graphics::drawDottedLine(0, 0, 0, HEIGHT - 1);
el17ajf 8:5066ce13a430 54 Graphics::drawDottedLine(1, 1, 1, HEIGHT - 2);
el17ajf 5:3efbdcb3efaf 55
el17ajf 8:5066ce13a430 56 Graphics::drawDottedLine(0, HEIGHT - 1, WIDTH - 1, HEIGHT - 1);
el17ajf 8:5066ce13a430 57 Graphics::drawDottedLine(1, HEIGHT - 2, WIDTH - 2, HEIGHT - 2);
el17ajf 8:5066ce13a430 58
el17ajf 8:5066ce13a430 59 Graphics::drawDottedLine(WIDTH - 1, HEIGHT - 1, WIDTH - 1, 0);
el17ajf 8:5066ce13a430 60 Graphics::drawDottedLine(WIDTH - 2, HEIGHT - 2, WIDTH - 2, 1);
el17ajf 5:3efbdcb3efaf 61 }