Displays distance to start location on OLED screen.

Dependencies:   mbed

Committer:
iforce2d
Date:
Wed Mar 07 12:49:14 2018 +0000
Revision:
0:972874f31c98
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
iforce2d 0:972874f31c98 1 /*
iforce2d 0:972874f31c98 2
iforce2d 0:972874f31c98 3 u8g_com_api_16gr.c
iforce2d 0:972874f31c98 4
iforce2d 0:972874f31c98 5 Extension of the com api for devices with 16 graylevels (4 bit per pixel).
iforce2d 0:972874f31c98 6 This should fit to the 8h and 16h architectures (pb8v1, pb8v2, pb16v1, pb16v2),
iforce2d 0:972874f31c98 7 mainly intended for SSD OLEDs
iforce2d 0:972874f31c98 8
iforce2d 0:972874f31c98 9 Universal 8bit Graphics Library
iforce2d 0:972874f31c98 10
iforce2d 0:972874f31c98 11 Copyright (c) 2011, olikraus@gmail.com
iforce2d 0:972874f31c98 12 All rights reserved.
iforce2d 0:972874f31c98 13
iforce2d 0:972874f31c98 14 Redistribution and use in source and binary forms, with or without modification,
iforce2d 0:972874f31c98 15 are permitted provided that the following conditions are met:
iforce2d 0:972874f31c98 16
iforce2d 0:972874f31c98 17 * Redistributions of source code must retain the above copyright notice, this list
iforce2d 0:972874f31c98 18 of conditions and the following disclaimer.
iforce2d 0:972874f31c98 19
iforce2d 0:972874f31c98 20 * Redistributions in binary form must reproduce the above copyright notice, this
iforce2d 0:972874f31c98 21 list of conditions and the following disclaimer in the documentation and/or other
iforce2d 0:972874f31c98 22 materials provided with the distribution.
iforce2d 0:972874f31c98 23
iforce2d 0:972874f31c98 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
iforce2d 0:972874f31c98 25 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
iforce2d 0:972874f31c98 26 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
iforce2d 0:972874f31c98 27 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
iforce2d 0:972874f31c98 28 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
iforce2d 0:972874f31c98 29 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
iforce2d 0:972874f31c98 30 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
iforce2d 0:972874f31c98 31 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
iforce2d 0:972874f31c98 32 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
iforce2d 0:972874f31c98 33 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
iforce2d 0:972874f31c98 34 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
iforce2d 0:972874f31c98 35 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
iforce2d 0:972874f31c98 36 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
iforce2d 0:972874f31c98 37
iforce2d 0:972874f31c98 38
iforce2d 0:972874f31c98 39 */
iforce2d 0:972874f31c98 40
iforce2d 0:972874f31c98 41 #include "u8g.h"
iforce2d 0:972874f31c98 42
iforce2d 0:972874f31c98 43 /* interpret b as a monochrome bit pattern, write value 15 for high bit and value 0 for a low bit */
iforce2d 0:972874f31c98 44 /* topbit (msb) is sent last */
iforce2d 0:972874f31c98 45 /* example: b = 0x083 will send 0xff, 0x00, 0x00, 0xf0 */
iforce2d 0:972874f31c98 46 uint8_t u8g_WriteByteBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b)
iforce2d 0:972874f31c98 47 {
iforce2d 0:972874f31c98 48 static uint8_t buf[4];
iforce2d 0:972874f31c98 49 static uint8_t map[4] = { 0, 0x00f, 0x0f0, 0x0ff };
iforce2d 0:972874f31c98 50 buf [3] = map[b & 3];
iforce2d 0:972874f31c98 51 b>>=2;
iforce2d 0:972874f31c98 52 buf [2] = map[b & 3];
iforce2d 0:972874f31c98 53 b>>=2;
iforce2d 0:972874f31c98 54 buf [1] = map[b & 3];
iforce2d 0:972874f31c98 55 b>>=2;
iforce2d 0:972874f31c98 56 buf [0] = map[b & 3];
iforce2d 0:972874f31c98 57 return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, 4, buf);
iforce2d 0:972874f31c98 58 }
iforce2d 0:972874f31c98 59
iforce2d 0:972874f31c98 60 uint8_t u8g_WriteSequenceBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr)
iforce2d 0:972874f31c98 61 {
iforce2d 0:972874f31c98 62 do
iforce2d 0:972874f31c98 63 {
iforce2d 0:972874f31c98 64 if ( u8g_WriteByteBWTo16GrDevice(u8g, dev, *ptr++) == 0 )
iforce2d 0:972874f31c98 65 return 0;
iforce2d 0:972874f31c98 66 cnt--;
iforce2d 0:972874f31c98 67 } while( cnt != 0 );
iforce2d 0:972874f31c98 68 return 1;
iforce2d 0:972874f31c98 69 }
iforce2d 0:972874f31c98 70
iforce2d 0:972874f31c98 71 /* interpret b as a 4L bit pattern, write values 0x000, 0x004, 0x008, 0x00c */
iforce2d 0:972874f31c98 72 uint8_t u8g_WriteByte4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b)
iforce2d 0:972874f31c98 73 {
iforce2d 0:972874f31c98 74 //static uint8_t map[16] = { 0x000, 0x004, 0x008, 0x00c, 0x040, 0x044, 0x048, 0x04c, 0x080, 0x084, 0x088, 0x08c, 0x0c0, 0x0c4, 0x0c8, 0x0cc};
iforce2d 0:972874f31c98 75 //static uint8_t map[16] = { 0x000, 0x004, 0x00a, 0x00f, 0x040, 0x044, 0x04a, 0x04f, 0x0a0, 0x0a4, 0x0aa, 0x0af, 0x0f0, 0x0f4, 0x0fa, 0x0ff};
iforce2d 0:972874f31c98 76 static uint8_t map[16] = { 0x000, 0x040, 0x0a0, 0x0f0, 0x004, 0x044, 0x0a4, 0x0f4, 0x00a, 0x04a, 0x0aa, 0x0fa, 0x00f, 0x04f, 0x0af, 0x0ff};
iforce2d 0:972874f31c98 77 uint8_t bb;
iforce2d 0:972874f31c98 78 bb = b;
iforce2d 0:972874f31c98 79 bb &= 15;
iforce2d 0:972874f31c98 80 b>>=4;
iforce2d 0:972874f31c98 81 dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[bb], NULL);
iforce2d 0:972874f31c98 82 return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[b], NULL);
iforce2d 0:972874f31c98 83 }
iforce2d 0:972874f31c98 84
iforce2d 0:972874f31c98 85 uint8_t u8g_WriteSequence4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr)
iforce2d 0:972874f31c98 86 {
iforce2d 0:972874f31c98 87 do
iforce2d 0:972874f31c98 88 {
iforce2d 0:972874f31c98 89 if ( u8g_WriteByte4LTo16GrDevice(u8g, dev, *ptr++) == 0 )
iforce2d 0:972874f31c98 90 return 0;
iforce2d 0:972874f31c98 91 cnt--;
iforce2d 0:972874f31c98 92 } while( cnt != 0 );
iforce2d 0:972874f31c98 93 return 1;
iforce2d 0:972874f31c98 94 }
iforce2d 0:972874f31c98 95