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_rect.c
iforce2d 0:972874f31c98 4
iforce2d 0:972874f31c98 5 U8G high level interface for horizontal and vertical things
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_draw_hline(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w)
iforce2d 0:972874f31c98 42 {
iforce2d 0:972874f31c98 43 uint8_t pixel = 0x0ff;
iforce2d 0:972874f31c98 44 while( w >= 8 )
iforce2d 0:972874f31c98 45 {
iforce2d 0:972874f31c98 46 u8g_Draw8Pixel(u8g, x, y, 0, pixel);
iforce2d 0:972874f31c98 47 w-=8;
iforce2d 0:972874f31c98 48 x+=8;
iforce2d 0:972874f31c98 49 }
iforce2d 0:972874f31c98 50 if ( w != 0 )
iforce2d 0:972874f31c98 51 {
iforce2d 0:972874f31c98 52 w ^=7;
iforce2d 0:972874f31c98 53 w++;
iforce2d 0:972874f31c98 54 pixel <<= w&7;
iforce2d 0:972874f31c98 55 u8g_Draw8Pixel(u8g, x, y, 0, pixel);
iforce2d 0:972874f31c98 56 }
iforce2d 0:972874f31c98 57 }
iforce2d 0:972874f31c98 58
iforce2d 0:972874f31c98 59 void u8g_draw_vline(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t h)
iforce2d 0:972874f31c98 60 {
iforce2d 0:972874f31c98 61 uint8_t pixel = 0x0ff;
iforce2d 0:972874f31c98 62 while( h >= 8 )
iforce2d 0:972874f31c98 63 {
iforce2d 0:972874f31c98 64 u8g_Draw8Pixel(u8g, x, y, 1, pixel);
iforce2d 0:972874f31c98 65 h-=8;
iforce2d 0:972874f31c98 66 y+=8;
iforce2d 0:972874f31c98 67 }
iforce2d 0:972874f31c98 68 if ( h != 0 )
iforce2d 0:972874f31c98 69 {
iforce2d 0:972874f31c98 70 h ^=7;
iforce2d 0:972874f31c98 71 h++;
iforce2d 0:972874f31c98 72 pixel <<= h&7;
iforce2d 0:972874f31c98 73 u8g_Draw8Pixel(u8g, x, y, 1, pixel);
iforce2d 0:972874f31c98 74 }
iforce2d 0:972874f31c98 75 }
iforce2d 0:972874f31c98 76
iforce2d 0:972874f31c98 77 void u8g_DrawHLine(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w)
iforce2d 0:972874f31c98 78 {
iforce2d 0:972874f31c98 79 if ( u8g_IsBBXIntersection(u8g, x, y, w, 1) == 0 )
iforce2d 0:972874f31c98 80 return;
iforce2d 0:972874f31c98 81 u8g_draw_hline(u8g, x, y, w);
iforce2d 0:972874f31c98 82 }
iforce2d 0:972874f31c98 83
iforce2d 0:972874f31c98 84 void u8g_DrawVLine(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w)
iforce2d 0:972874f31c98 85 {
iforce2d 0:972874f31c98 86 if ( u8g_IsBBXIntersection(u8g, x, y, 1, w) == 0 )
iforce2d 0:972874f31c98 87 return;
iforce2d 0:972874f31c98 88 u8g_draw_vline(u8g, x, y, w);
iforce2d 0:972874f31c98 89 }
iforce2d 0:972874f31c98 90
iforce2d 0:972874f31c98 91 /* restrictions: w > 0 && h > 0 */
iforce2d 0:972874f31c98 92 void u8g_DrawFrame(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
iforce2d 0:972874f31c98 93 {
iforce2d 0:972874f31c98 94 u8g_uint_t xtmp = x;
iforce2d 0:972874f31c98 95
iforce2d 0:972874f31c98 96 if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
iforce2d 0:972874f31c98 97 return;
iforce2d 0:972874f31c98 98
iforce2d 0:972874f31c98 99
iforce2d 0:972874f31c98 100 u8g_draw_hline(u8g, x, y, w);
iforce2d 0:972874f31c98 101 u8g_draw_vline(u8g, x, y, h);
iforce2d 0:972874f31c98 102 x+=w;
iforce2d 0:972874f31c98 103 x--;
iforce2d 0:972874f31c98 104 u8g_draw_vline(u8g, x, y, h);
iforce2d 0:972874f31c98 105 y+=h;
iforce2d 0:972874f31c98 106 y--;
iforce2d 0:972874f31c98 107 u8g_draw_hline(u8g, xtmp, y, w);
iforce2d 0:972874f31c98 108 }
iforce2d 0:972874f31c98 109
iforce2d 0:972874f31c98 110 void u8g_draw_box(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
iforce2d 0:972874f31c98 111 {
iforce2d 0:972874f31c98 112 do
iforce2d 0:972874f31c98 113 {
iforce2d 0:972874f31c98 114 u8g_draw_hline(u8g, x, y, w);
iforce2d 0:972874f31c98 115 y++;
iforce2d 0:972874f31c98 116 h--;
iforce2d 0:972874f31c98 117 } while( h != 0 );
iforce2d 0:972874f31c98 118 }
iforce2d 0:972874f31c98 119
iforce2d 0:972874f31c98 120 /* restrictions: h > 0 */
iforce2d 0:972874f31c98 121 void u8g_DrawBox(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
iforce2d 0:972874f31c98 122 {
iforce2d 0:972874f31c98 123 if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
iforce2d 0:972874f31c98 124 return;
iforce2d 0:972874f31c98 125 u8g_draw_box(u8g, x, y, w, h);
iforce2d 0:972874f31c98 126 }
iforce2d 0:972874f31c98 127
iforce2d 0:972874f31c98 128
iforce2d 0:972874f31c98 129 void u8g_DrawRFrame(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, u8g_uint_t r)
iforce2d 0:972874f31c98 130 {
iforce2d 0:972874f31c98 131 u8g_uint_t xl, yu;
iforce2d 0:972874f31c98 132
iforce2d 0:972874f31c98 133 if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
iforce2d 0:972874f31c98 134 return;
iforce2d 0:972874f31c98 135
iforce2d 0:972874f31c98 136 xl = x;
iforce2d 0:972874f31c98 137 xl += r;
iforce2d 0:972874f31c98 138 yu = y;
iforce2d 0:972874f31c98 139 yu += r;
iforce2d 0:972874f31c98 140
iforce2d 0:972874f31c98 141 {
iforce2d 0:972874f31c98 142 u8g_uint_t yl, xr;
iforce2d 0:972874f31c98 143
iforce2d 0:972874f31c98 144 xr = x;
iforce2d 0:972874f31c98 145 xr += w;
iforce2d 0:972874f31c98 146 xr -= r;
iforce2d 0:972874f31c98 147 xr -= 1;
iforce2d 0:972874f31c98 148
iforce2d 0:972874f31c98 149 yl = y;
iforce2d 0:972874f31c98 150 yl += h;
iforce2d 0:972874f31c98 151 yl -= r;
iforce2d 0:972874f31c98 152 yl -= 1;
iforce2d 0:972874f31c98 153
iforce2d 0:972874f31c98 154 u8g_draw_circle(u8g, xl, yu, r, U8G_DRAW_UPPER_LEFT);
iforce2d 0:972874f31c98 155 u8g_draw_circle(u8g, xr, yu, r, U8G_DRAW_UPPER_RIGHT);
iforce2d 0:972874f31c98 156 u8g_draw_circle(u8g, xl, yl, r, U8G_DRAW_LOWER_LEFT);
iforce2d 0:972874f31c98 157 u8g_draw_circle(u8g, xr, yl, r, U8G_DRAW_LOWER_RIGHT);
iforce2d 0:972874f31c98 158 }
iforce2d 0:972874f31c98 159
iforce2d 0:972874f31c98 160 {
iforce2d 0:972874f31c98 161 u8g_uint_t ww, hh;
iforce2d 0:972874f31c98 162
iforce2d 0:972874f31c98 163 ww = w;
iforce2d 0:972874f31c98 164 ww -= r;
iforce2d 0:972874f31c98 165 ww -= r;
iforce2d 0:972874f31c98 166 ww -= 2;
iforce2d 0:972874f31c98 167 hh = h;
iforce2d 0:972874f31c98 168 hh -= r;
iforce2d 0:972874f31c98 169 hh -= r;
iforce2d 0:972874f31c98 170 hh -= 2;
iforce2d 0:972874f31c98 171
iforce2d 0:972874f31c98 172 xl++;
iforce2d 0:972874f31c98 173 yu++;
iforce2d 0:972874f31c98 174 h--;
iforce2d 0:972874f31c98 175 w--;
iforce2d 0:972874f31c98 176 u8g_draw_hline(u8g, xl, y, ww);
iforce2d 0:972874f31c98 177 u8g_draw_hline(u8g, xl, y+h, ww);
iforce2d 0:972874f31c98 178 u8g_draw_vline(u8g, x, yu, hh);
iforce2d 0:972874f31c98 179 u8g_draw_vline(u8g, x+w, yu, hh);
iforce2d 0:972874f31c98 180 }
iforce2d 0:972874f31c98 181 }
iforce2d 0:972874f31c98 182
iforce2d 0:972874f31c98 183 void u8g_DrawRBox(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, u8g_uint_t r)
iforce2d 0:972874f31c98 184 {
iforce2d 0:972874f31c98 185 u8g_uint_t xl, yu;
iforce2d 0:972874f31c98 186 u8g_uint_t yl, xr;
iforce2d 0:972874f31c98 187
iforce2d 0:972874f31c98 188 if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 )
iforce2d 0:972874f31c98 189 return;
iforce2d 0:972874f31c98 190
iforce2d 0:972874f31c98 191 xl = x;
iforce2d 0:972874f31c98 192 xl += r;
iforce2d 0:972874f31c98 193 yu = y;
iforce2d 0:972874f31c98 194 yu += r;
iforce2d 0:972874f31c98 195
iforce2d 0:972874f31c98 196 xr = x;
iforce2d 0:972874f31c98 197 xr += w;
iforce2d 0:972874f31c98 198 xr -= r;
iforce2d 0:972874f31c98 199 xr -= 1;
iforce2d 0:972874f31c98 200
iforce2d 0:972874f31c98 201 yl = y;
iforce2d 0:972874f31c98 202 yl += h;
iforce2d 0:972874f31c98 203 yl -= r;
iforce2d 0:972874f31c98 204 yl -= 1;
iforce2d 0:972874f31c98 205
iforce2d 0:972874f31c98 206 u8g_draw_disc(u8g, xl, yu, r, U8G_DRAW_UPPER_LEFT);
iforce2d 0:972874f31c98 207 u8g_draw_disc(u8g, xr, yu, r, U8G_DRAW_UPPER_RIGHT);
iforce2d 0:972874f31c98 208 u8g_draw_disc(u8g, xl, yl, r, U8G_DRAW_LOWER_LEFT);
iforce2d 0:972874f31c98 209 u8g_draw_disc(u8g, xr, yl, r, U8G_DRAW_LOWER_RIGHT);
iforce2d 0:972874f31c98 210
iforce2d 0:972874f31c98 211 {
iforce2d 0:972874f31c98 212 u8g_uint_t ww, hh;
iforce2d 0:972874f31c98 213
iforce2d 0:972874f31c98 214 ww = w;
iforce2d 0:972874f31c98 215 ww -= r;
iforce2d 0:972874f31c98 216 ww -= r;
iforce2d 0:972874f31c98 217 ww -= 2;
iforce2d 0:972874f31c98 218 hh = h;
iforce2d 0:972874f31c98 219 hh -= r;
iforce2d 0:972874f31c98 220 hh -= r;
iforce2d 0:972874f31c98 221 hh -= 2;
iforce2d 0:972874f31c98 222
iforce2d 0:972874f31c98 223 xl++;
iforce2d 0:972874f31c98 224 yu++;
iforce2d 0:972874f31c98 225 h--;
iforce2d 0:972874f31c98 226 u8g_draw_box(u8g, xl, y, ww, r+1);
iforce2d 0:972874f31c98 227 u8g_draw_box(u8g, xl, yl, ww, r+1);
iforce2d 0:972874f31c98 228 //u8g_draw_hline(u8g, xl, y+h, ww);
iforce2d 0:972874f31c98 229 u8g_draw_box(u8g, x, yu, w, hh);
iforce2d 0:972874f31c98 230 //u8g_draw_vline(u8g, x+w, yu, hh);
iforce2d 0:972874f31c98 231 }
iforce2d 0:972874f31c98 232 }
iforce2d 0:972874f31c98 233