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_pb.c
iforce2d 0:972874f31c98 4
iforce2d 0:972874f31c98 5 common procedures for the page buffer
iforce2d 0:972874f31c98 6
iforce2d 0:972874f31c98 7 Universal 8bit Graphics Library
iforce2d 0:972874f31c98 8
iforce2d 0:972874f31c98 9 Copyright (c) 2011, olikraus@gmail.com
iforce2d 0:972874f31c98 10 All rights reserved.
iforce2d 0:972874f31c98 11
iforce2d 0:972874f31c98 12 Redistribution and use in source and binary forms, with or without modification,
iforce2d 0:972874f31c98 13 are permitted provided that the following conditions are met:
iforce2d 0:972874f31c98 14
iforce2d 0:972874f31c98 15 * Redistributions of source code must retain the above copyright notice, this list
iforce2d 0:972874f31c98 16 of conditions and the following disclaimer.
iforce2d 0:972874f31c98 17
iforce2d 0:972874f31c98 18 * Redistributions in binary form must reproduce the above copyright notice, this
iforce2d 0:972874f31c98 19 list of conditions and the following disclaimer in the documentation and/or other
iforce2d 0:972874f31c98 20 materials provided with the distribution.
iforce2d 0:972874f31c98 21
iforce2d 0:972874f31c98 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
iforce2d 0:972874f31c98 23 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
iforce2d 0:972874f31c98 24 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
iforce2d 0:972874f31c98 25 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
iforce2d 0:972874f31c98 26 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
iforce2d 0:972874f31c98 27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
iforce2d 0:972874f31c98 28 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
iforce2d 0:972874f31c98 29 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
iforce2d 0:972874f31c98 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
iforce2d 0:972874f31c98 31 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
iforce2d 0:972874f31c98 32 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
iforce2d 0:972874f31c98 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
iforce2d 0:972874f31c98 34 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
iforce2d 0:972874f31c98 35
iforce2d 0:972874f31c98 36
iforce2d 0:972874f31c98 37 */
iforce2d 0:972874f31c98 38
iforce2d 0:972874f31c98 39 #include "u8g.h"
iforce2d 0:972874f31c98 40
iforce2d 0:972874f31c98 41 void u8g_pb_Clear(u8g_pb_t *b)
iforce2d 0:972874f31c98 42 {
iforce2d 0:972874f31c98 43 uint8_t *ptr = (uint8_t *)b->buf;
iforce2d 0:972874f31c98 44 uint8_t *end_ptr = ptr;
iforce2d 0:972874f31c98 45 end_ptr += b->width;
iforce2d 0:972874f31c98 46 do
iforce2d 0:972874f31c98 47 {
iforce2d 0:972874f31c98 48 *ptr++ = 0;
iforce2d 0:972874f31c98 49 } while( ptr != end_ptr );
iforce2d 0:972874f31c98 50 }
iforce2d 0:972874f31c98 51
iforce2d 0:972874f31c98 52 /* the following procedure does not work. why? Can be checked with descpic */
iforce2d 0:972874f31c98 53 /*
iforce2d 0:972874f31c98 54 void u8g_pb_Clear(u8g_pb_t *b)
iforce2d 0:972874f31c98 55 {
iforce2d 0:972874f31c98 56 uint8_t *ptr = (uint8_t *)b->buf;
iforce2d 0:972874f31c98 57 uint8_t cnt = b->width;
iforce2d 0:972874f31c98 58 do
iforce2d 0:972874f31c98 59 {
iforce2d 0:972874f31c98 60 *ptr++ = 0;
iforce2d 0:972874f31c98 61 cnt--;
iforce2d 0:972874f31c98 62 } while( cnt != 0 );
iforce2d 0:972874f31c98 63 }
iforce2d 0:972874f31c98 64 */
iforce2d 0:972874f31c98 65
iforce2d 0:972874f31c98 66 /*
iforce2d 0:972874f31c98 67 intersection assumptions:
iforce2d 0:972874f31c98 68 a1 <= a2 is always true
iforce2d 0:972874f31c98 69 */
iforce2d 0:972874f31c98 70 /*
iforce2d 0:972874f31c98 71 minimized version
iforce2d 0:972874f31c98 72 ---1----0 1 b1 <= a2 && b1 > b2
iforce2d 0:972874f31c98 73 -----1--0 1 b2 >= a1 && b1 > b2
iforce2d 0:972874f31c98 74 ---1-1--- 1 b1 <= a2 && b2 >= a1
iforce2d 0:972874f31c98 75 */
iforce2d 0:972874f31c98 76 /*
iforce2d 0:972874f31c98 77 uint8_t u8g_pb8v1_IsYIntersection___Old(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1)
iforce2d 0:972874f31c98 78 {
iforce2d 0:972874f31c98 79 uint8_t c0, c1, c;
iforce2d 0:972874f31c98 80 c0 = v0 <= b->p.page_y1;
iforce2d 0:972874f31c98 81 c1 = v1 >= b->p.page_y0;
iforce2d 0:972874f31c98 82 c = v0 > v1;
iforce2d 0:972874f31c98 83 if ( c0 && c1 ) return 1;
iforce2d 0:972874f31c98 84 if ( c0 && c ) return 1;
iforce2d 0:972874f31c98 85 if ( c1 && c ) return 1;
iforce2d 0:972874f31c98 86 return 0;
iforce2d 0:972874f31c98 87 }
iforce2d 0:972874f31c98 88 */
iforce2d 0:972874f31c98 89
iforce2d 0:972874f31c98 90 uint8_t u8g_pb_IsYIntersection(u8g_pb_t *pb, u8g_uint_t v0, u8g_uint_t v1)
iforce2d 0:972874f31c98 91 {
iforce2d 0:972874f31c98 92 uint8_t c1, c2, c3, tmp;
iforce2d 0:972874f31c98 93 c1 = v0 <= pb->p.page_y1;
iforce2d 0:972874f31c98 94 c2 = v1 >= pb->p.page_y0;
iforce2d 0:972874f31c98 95 c3 = v0 > v1;
iforce2d 0:972874f31c98 96 /*
iforce2d 0:972874f31c98 97 if ( c1 && c2 )
iforce2d 0:972874f31c98 98 return 1;
iforce2d 0:972874f31c98 99 if ( c1 && c3 )
iforce2d 0:972874f31c98 100 return 1;
iforce2d 0:972874f31c98 101 if ( c2 && c3 )
iforce2d 0:972874f31c98 102 return 1;
iforce2d 0:972874f31c98 103 return 0;
iforce2d 0:972874f31c98 104 */
iforce2d 0:972874f31c98 105
iforce2d 0:972874f31c98 106 tmp = c1;
iforce2d 0:972874f31c98 107 c1 &= c2;
iforce2d 0:972874f31c98 108 c2 &= c3;
iforce2d 0:972874f31c98 109 c3 &= tmp;
iforce2d 0:972874f31c98 110 c1 |= c2;
iforce2d 0:972874f31c98 111 c1 |= c3;
iforce2d 0:972874f31c98 112 return c1 & 1;
iforce2d 0:972874f31c98 113 }
iforce2d 0:972874f31c98 114
iforce2d 0:972874f31c98 115
iforce2d 0:972874f31c98 116 uint8_t u8g_pb_IsXIntersection(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1)
iforce2d 0:972874f31c98 117 {
iforce2d 0:972874f31c98 118 uint8_t /*c0, c1, */ c2, c3;
iforce2d 0:972874f31c98 119 /*
iforce2d 0:972874f31c98 120 conditions: b->p.page_y0 < b->p.page_y1
iforce2d 0:972874f31c98 121 there are no restriction on v0 and v1. If v0 > v1, then warp around unsigned is assumed
iforce2d 0:972874f31c98 122 */
iforce2d 0:972874f31c98 123 /*
iforce2d 0:972874f31c98 124 c0 = v0 < 0;
iforce2d 0:972874f31c98 125 c1 = v1 < 0;
iforce2d 0:972874f31c98 126 */
iforce2d 0:972874f31c98 127 c2 = v0 > b->width;
iforce2d 0:972874f31c98 128 c3 = v1 > b->width;
iforce2d 0:972874f31c98 129 /*if ( c0 && c1 ) return 0;*/
iforce2d 0:972874f31c98 130 if ( c2 && c3 ) return 0;
iforce2d 0:972874f31c98 131 /*if ( c1 && c2 ) return 0;*/
iforce2d 0:972874f31c98 132 return 1;
iforce2d 0:972874f31c98 133 }
iforce2d 0:972874f31c98 134
iforce2d 0:972874f31c98 135 uint8_t u8g_pb_IsIntersection(u8g_pb_t *pb, u8g_dev_arg_bbx_t *bbx)
iforce2d 0:972874f31c98 136 {
iforce2d 0:972874f31c98 137 u8g_uint_t tmp;
iforce2d 0:972874f31c98 138
iforce2d 0:972874f31c98 139 tmp = bbx->y;
iforce2d 0:972874f31c98 140 tmp += bbx->h;
iforce2d 0:972874f31c98 141 tmp--;
iforce2d 0:972874f31c98 142
iforce2d 0:972874f31c98 143 if ( u8g_pb_IsYIntersection(pb, bbx->y, tmp) == 0 )
iforce2d 0:972874f31c98 144 return 0;
iforce2d 0:972874f31c98 145
iforce2d 0:972874f31c98 146 /* maybe this one can be skiped... probability is very high to have an intersection, so it would be ok to always return 1 */
iforce2d 0:972874f31c98 147 tmp = bbx->x;
iforce2d 0:972874f31c98 148 tmp += bbx->w;
iforce2d 0:972874f31c98 149 tmp--;
iforce2d 0:972874f31c98 150
iforce2d 0:972874f31c98 151 return u8g_pb_IsXIntersection(pb, bbx->x, tmp);
iforce2d 0:972874f31c98 152 }
iforce2d 0:972874f31c98 153
iforce2d 0:972874f31c98 154 void u8g_pb_GetPageBox(u8g_pb_t *pb, u8g_box_t *box)
iforce2d 0:972874f31c98 155 {
iforce2d 0:972874f31c98 156 box->x0 = 0;
iforce2d 0:972874f31c98 157 box->y0 = pb->p.page_y0;
iforce2d 0:972874f31c98 158 box->x1 = pb->width;
iforce2d 0:972874f31c98 159 box->x1--;
iforce2d 0:972874f31c98 160 box->y1 = pb->p.page_y1;
iforce2d 0:972874f31c98 161 }
iforce2d 0:972874f31c98 162
iforce2d 0:972874f31c98 163
iforce2d 0:972874f31c98 164 uint8_t u8g_pb_Is8PixelVisible(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
iforce2d 0:972874f31c98 165 {
iforce2d 0:972874f31c98 166 u8g_uint_t v0, v1;
iforce2d 0:972874f31c98 167 v0 = arg_pixel->y;
iforce2d 0:972874f31c98 168 v1 = v0;
iforce2d 0:972874f31c98 169 switch( arg_pixel->dir )
iforce2d 0:972874f31c98 170 {
iforce2d 0:972874f31c98 171 case 0:
iforce2d 0:972874f31c98 172 break;
iforce2d 0:972874f31c98 173 case 1:
iforce2d 0:972874f31c98 174 v1 += 8; /* this is independent from the page height */
iforce2d 0:972874f31c98 175 break;
iforce2d 0:972874f31c98 176 case 2:
iforce2d 0:972874f31c98 177 break;
iforce2d 0:972874f31c98 178 case 3:
iforce2d 0:972874f31c98 179 v0 -= 8;
iforce2d 0:972874f31c98 180 break;
iforce2d 0:972874f31c98 181 }
iforce2d 0:972874f31c98 182 return u8g_pb_IsYIntersection(b, v0, v1);
iforce2d 0:972874f31c98 183 }
iforce2d 0:972874f31c98 184
iforce2d 0:972874f31c98 185
iforce2d 0:972874f31c98 186
iforce2d 0:972874f31c98 187 uint8_t u8g_pb_WriteBuffer(u8g_pb_t *b, u8g_t *u8g, u8g_dev_t *dev)
iforce2d 0:972874f31c98 188 {
iforce2d 0:972874f31c98 189 return u8g_WriteSequence(u8g, dev, b->width, b->buf);
iforce2d 0:972874f31c98 190 }
iforce2d 0:972874f31c98 191
iforce2d 0:972874f31c98 192