iforce2d Chris
/
ubxDistanceMeter
Displays distance to start location on OLED screen.
u8g_pb16h1.c@0:972874f31c98, 2018-03-07 (annotated)
- Committer:
- iforce2d
- Date:
- Wed Mar 07 12:49:14 2018 +0000
- Revision:
- 0:972874f31c98
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iforce2d | 0:972874f31c98 | 1 | /* |
iforce2d | 0:972874f31c98 | 2 | |
iforce2d | 0:972874f31c98 | 3 | u8g_pb16h1.c |
iforce2d | 0:972874f31c98 | 4 | |
iforce2d | 0:972874f31c98 | 5 | 2x 8bit height monochrom (1 bit) page buffer |
iforce2d | 0:972874f31c98 | 6 | byte has horizontal orientation |
iforce2d | 0:972874f31c98 | 7 | |
iforce2d | 0:972874f31c98 | 8 | Universal 8bit Graphics Library |
iforce2d | 0:972874f31c98 | 9 | |
iforce2d | 0:972874f31c98 | 10 | Copyright (c) 2012, olikraus@gmail.com |
iforce2d | 0:972874f31c98 | 11 | All rights reserved. |
iforce2d | 0:972874f31c98 | 12 | |
iforce2d | 0:972874f31c98 | 13 | Redistribution and use in source and binary forms, with or without modification, |
iforce2d | 0:972874f31c98 | 14 | are permitted provided that the following conditions are met: |
iforce2d | 0:972874f31c98 | 15 | |
iforce2d | 0:972874f31c98 | 16 | * Redistributions of source code must retain the above copyright notice, this list |
iforce2d | 0:972874f31c98 | 17 | of conditions and the following disclaimer. |
iforce2d | 0:972874f31c98 | 18 | |
iforce2d | 0:972874f31c98 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this |
iforce2d | 0:972874f31c98 | 20 | list of conditions and the following disclaimer in the documentation and/or other |
iforce2d | 0:972874f31c98 | 21 | materials provided with the distribution. |
iforce2d | 0:972874f31c98 | 22 | |
iforce2d | 0:972874f31c98 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
iforce2d | 0:972874f31c98 | 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
iforce2d | 0:972874f31c98 | 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
iforce2d | 0:972874f31c98 | 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
iforce2d | 0:972874f31c98 | 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
iforce2d | 0:972874f31c98 | 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
iforce2d | 0:972874f31c98 | 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
iforce2d | 0:972874f31c98 | 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
iforce2d | 0:972874f31c98 | 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
iforce2d | 0:972874f31c98 | 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
iforce2d | 0:972874f31c98 | 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
iforce2d | 0:972874f31c98 | 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
iforce2d | 0:972874f31c98 | 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
iforce2d | 0:972874f31c98 | 36 | |
iforce2d | 0:972874f31c98 | 37 | |
iforce2d | 0:972874f31c98 | 38 | total buffer size is limited to 2*256 bytes because of the calculation inside the set pixel procedure |
iforce2d | 0:972874f31c98 | 39 | |
iforce2d | 0:972874f31c98 | 40 | |
iforce2d | 0:972874f31c98 | 41 | */ |
iforce2d | 0:972874f31c98 | 42 | |
iforce2d | 0:972874f31c98 | 43 | #include "u8g.h" |
iforce2d | 0:972874f31c98 | 44 | #include <string.h> |
iforce2d | 0:972874f31c98 | 45 | |
iforce2d | 0:972874f31c98 | 46 | |
iforce2d | 0:972874f31c98 | 47 | void u8g_pb16h1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 48 | void u8g_pb16h1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 49 | void u8g_pb16h1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) U8G_NOINLINE ; |
iforce2d | 0:972874f31c98 | 50 | void u8g_pb16h1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) U8G_NOINLINE; |
iforce2d | 0:972874f31c98 | 51 | uint8_t u8g_dev_pb8h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); |
iforce2d | 0:972874f31c98 | 52 | |
iforce2d | 0:972874f31c98 | 53 | void u8g_pb16h1_Clear(u8g_pb_t *b) |
iforce2d | 0:972874f31c98 | 54 | { |
iforce2d | 0:972874f31c98 | 55 | uint8_t *ptr = (uint8_t *)b->buf; |
iforce2d | 0:972874f31c98 | 56 | uint8_t *end_ptr = ptr; |
iforce2d | 0:972874f31c98 | 57 | end_ptr += b->width*2; |
iforce2d | 0:972874f31c98 | 58 | do |
iforce2d | 0:972874f31c98 | 59 | { |
iforce2d | 0:972874f31c98 | 60 | *ptr++ = 0; |
iforce2d | 0:972874f31c98 | 61 | } while( ptr != end_ptr ); |
iforce2d | 0:972874f31c98 | 62 | } |
iforce2d | 0:972874f31c98 | 63 | |
iforce2d | 0:972874f31c98 | 64 | |
iforce2d | 0:972874f31c98 | 65 | |
iforce2d | 0:972874f31c98 | 66 | void u8g_pb16h1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) |
iforce2d | 0:972874f31c98 | 67 | { |
iforce2d | 0:972874f31c98 | 68 | b->buf = buf; |
iforce2d | 0:972874f31c98 | 69 | b->width = width; |
iforce2d | 0:972874f31c98 | 70 | u8g_pb16h1_Clear(b); |
iforce2d | 0:972874f31c98 | 71 | } |
iforce2d | 0:972874f31c98 | 72 | |
iforce2d | 0:972874f31c98 | 73 | |
iforce2d | 0:972874f31c98 | 74 | /* limitation: total buffer must not exceed 2*256 bytes */ |
iforce2d | 0:972874f31c98 | 75 | void u8g_pb16h1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) |
iforce2d | 0:972874f31c98 | 76 | { |
iforce2d | 0:972874f31c98 | 77 | register uint8_t mask; |
iforce2d | 0:972874f31c98 | 78 | u8g_uint_t tmp; |
iforce2d | 0:972874f31c98 | 79 | uint8_t *ptr = b->buf; |
iforce2d | 0:972874f31c98 | 80 | |
iforce2d | 0:972874f31c98 | 81 | y -= b->p.page_y0; |
iforce2d | 0:972874f31c98 | 82 | if ( y >= 8 ) |
iforce2d | 0:972874f31c98 | 83 | { |
iforce2d | 0:972874f31c98 | 84 | ptr += b->width; |
iforce2d | 0:972874f31c98 | 85 | y &= 0x07; |
iforce2d | 0:972874f31c98 | 86 | } |
iforce2d | 0:972874f31c98 | 87 | tmp = b->width; |
iforce2d | 0:972874f31c98 | 88 | tmp >>= 3; |
iforce2d | 0:972874f31c98 | 89 | tmp *= (uint8_t)y; |
iforce2d | 0:972874f31c98 | 90 | ptr += tmp; |
iforce2d | 0:972874f31c98 | 91 | |
iforce2d | 0:972874f31c98 | 92 | mask = 0x080; |
iforce2d | 0:972874f31c98 | 93 | mask >>= x & 7; |
iforce2d | 0:972874f31c98 | 94 | x >>= 3; |
iforce2d | 0:972874f31c98 | 95 | ptr += x; |
iforce2d | 0:972874f31c98 | 96 | if ( color_index ) |
iforce2d | 0:972874f31c98 | 97 | { |
iforce2d | 0:972874f31c98 | 98 | *ptr |= mask; |
iforce2d | 0:972874f31c98 | 99 | } |
iforce2d | 0:972874f31c98 | 100 | else |
iforce2d | 0:972874f31c98 | 101 | { |
iforce2d | 0:972874f31c98 | 102 | mask ^=0xff; |
iforce2d | 0:972874f31c98 | 103 | *ptr &= mask; |
iforce2d | 0:972874f31c98 | 104 | } |
iforce2d | 0:972874f31c98 | 105 | |
iforce2d | 0:972874f31c98 | 106 | } |
iforce2d | 0:972874f31c98 | 107 | |
iforce2d | 0:972874f31c98 | 108 | |
iforce2d | 0:972874f31c98 | 109 | void u8g_pb16h1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) |
iforce2d | 0:972874f31c98 | 110 | { |
iforce2d | 0:972874f31c98 | 111 | if ( arg_pixel->y < b->p.page_y0 ) |
iforce2d | 0:972874f31c98 | 112 | return; |
iforce2d | 0:972874f31c98 | 113 | if ( arg_pixel->y > b->p.page_y1 ) |
iforce2d | 0:972874f31c98 | 114 | return; |
iforce2d | 0:972874f31c98 | 115 | if ( arg_pixel->x >= b->width ) |
iforce2d | 0:972874f31c98 | 116 | return; |
iforce2d | 0:972874f31c98 | 117 | u8g_pb16h1_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); |
iforce2d | 0:972874f31c98 | 118 | } |
iforce2d | 0:972874f31c98 | 119 | |
iforce2d | 0:972874f31c98 | 120 | void u8g_pb16h1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) |
iforce2d | 0:972874f31c98 | 121 | { |
iforce2d | 0:972874f31c98 | 122 | register uint8_t pixel = arg_pixel->pixel; |
iforce2d | 0:972874f31c98 | 123 | do |
iforce2d | 0:972874f31c98 | 124 | { |
iforce2d | 0:972874f31c98 | 125 | if ( pixel & 128 ) |
iforce2d | 0:972874f31c98 | 126 | { |
iforce2d | 0:972874f31c98 | 127 | u8g_pb16h1_SetPixel(b, arg_pixel); |
iforce2d | 0:972874f31c98 | 128 | } |
iforce2d | 0:972874f31c98 | 129 | switch( arg_pixel->dir ) |
iforce2d | 0:972874f31c98 | 130 | { |
iforce2d | 0:972874f31c98 | 131 | case 0: arg_pixel->x++; break; |
iforce2d | 0:972874f31c98 | 132 | case 1: arg_pixel->y++; break; |
iforce2d | 0:972874f31c98 | 133 | case 2: arg_pixel->x--; break; |
iforce2d | 0:972874f31c98 | 134 | case 3: arg_pixel->y--; break; |
iforce2d | 0:972874f31c98 | 135 | } |
iforce2d | 0:972874f31c98 | 136 | pixel <<= 1; |
iforce2d | 0:972874f31c98 | 137 | } while( pixel != 0 ); |
iforce2d | 0:972874f31c98 | 138 | } |
iforce2d | 0:972874f31c98 | 139 | |
iforce2d | 0:972874f31c98 | 140 | void u8g_pb16h1_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) |
iforce2d | 0:972874f31c98 | 141 | { |
iforce2d | 0:972874f31c98 | 142 | register uint8_t pixel = arg_pixel->pixel; |
iforce2d | 0:972874f31c98 | 143 | u8g_uint_t dx = 0; |
iforce2d | 0:972874f31c98 | 144 | u8g_uint_t dy = 0; |
iforce2d | 0:972874f31c98 | 145 | |
iforce2d | 0:972874f31c98 | 146 | switch( arg_pixel->dir ) |
iforce2d | 0:972874f31c98 | 147 | { |
iforce2d | 0:972874f31c98 | 148 | case 0: dx++; break; |
iforce2d | 0:972874f31c98 | 149 | case 1: dy++; break; |
iforce2d | 0:972874f31c98 | 150 | case 2: dx--; break; |
iforce2d | 0:972874f31c98 | 151 | case 3: dy--; break; |
iforce2d | 0:972874f31c98 | 152 | } |
iforce2d | 0:972874f31c98 | 153 | |
iforce2d | 0:972874f31c98 | 154 | do |
iforce2d | 0:972874f31c98 | 155 | { |
iforce2d | 0:972874f31c98 | 156 | if ( pixel & 128 ) |
iforce2d | 0:972874f31c98 | 157 | u8g_pb16h1_SetPixel(b, arg_pixel); |
iforce2d | 0:972874f31c98 | 158 | arg_pixel->x += dx; |
iforce2d | 0:972874f31c98 | 159 | arg_pixel->y += dy; |
iforce2d | 0:972874f31c98 | 160 | pixel <<= 1; |
iforce2d | 0:972874f31c98 | 161 | } while( pixel != 0 ); |
iforce2d | 0:972874f31c98 | 162 | } |
iforce2d | 0:972874f31c98 | 163 | |
iforce2d | 0:972874f31c98 | 164 | |
iforce2d | 0:972874f31c98 | 165 | uint8_t u8g_dev_pb16h1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) |
iforce2d | 0:972874f31c98 | 166 | { |
iforce2d | 0:972874f31c98 | 167 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); |
iforce2d | 0:972874f31c98 | 168 | switch(msg) |
iforce2d | 0:972874f31c98 | 169 | { |
iforce2d | 0:972874f31c98 | 170 | case U8G_DEV_MSG_SET_8PIXEL: |
iforce2d | 0:972874f31c98 | 171 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) |
iforce2d | 0:972874f31c98 | 172 | u8g_pb16h1_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg); |
iforce2d | 0:972874f31c98 | 173 | break; |
iforce2d | 0:972874f31c98 | 174 | case U8G_DEV_MSG_SET_PIXEL: |
iforce2d | 0:972874f31c98 | 175 | u8g_pb16h1_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); |
iforce2d | 0:972874f31c98 | 176 | break; |
iforce2d | 0:972874f31c98 | 177 | case U8G_DEV_MSG_INIT: |
iforce2d | 0:972874f31c98 | 178 | break; |
iforce2d | 0:972874f31c98 | 179 | case U8G_DEV_MSG_STOP: |
iforce2d | 0:972874f31c98 | 180 | break; |
iforce2d | 0:972874f31c98 | 181 | case U8G_DEV_MSG_PAGE_FIRST: |
iforce2d | 0:972874f31c98 | 182 | u8g_pb16h1_Clear(pb); |
iforce2d | 0:972874f31c98 | 183 | u8g_page_First(&(pb->p)); |
iforce2d | 0:972874f31c98 | 184 | break; |
iforce2d | 0:972874f31c98 | 185 | case U8G_DEV_MSG_PAGE_NEXT: |
iforce2d | 0:972874f31c98 | 186 | if ( u8g_page_Next(&(pb->p)) == 0 ) |
iforce2d | 0:972874f31c98 | 187 | return 0; |
iforce2d | 0:972874f31c98 | 188 | u8g_pb16h1_Clear(pb); |
iforce2d | 0:972874f31c98 | 189 | break; |
iforce2d | 0:972874f31c98 | 190 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION |
iforce2d | 0:972874f31c98 | 191 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: |
iforce2d | 0:972874f31c98 | 192 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); |
iforce2d | 0:972874f31c98 | 193 | #endif |
iforce2d | 0:972874f31c98 | 194 | case U8G_DEV_MSG_GET_PAGE_BOX: |
iforce2d | 0:972874f31c98 | 195 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); |
iforce2d | 0:972874f31c98 | 196 | break; |
iforce2d | 0:972874f31c98 | 197 | case U8G_DEV_MSG_GET_WIDTH: |
iforce2d | 0:972874f31c98 | 198 | *((u8g_uint_t *)arg) = pb->width; |
iforce2d | 0:972874f31c98 | 199 | break; |
iforce2d | 0:972874f31c98 | 200 | case U8G_DEV_MSG_GET_HEIGHT: |
iforce2d | 0:972874f31c98 | 201 | *((u8g_uint_t *)arg) = pb->p.total_height; |
iforce2d | 0:972874f31c98 | 202 | break; |
iforce2d | 0:972874f31c98 | 203 | case U8G_DEV_MSG_SET_COLOR_ENTRY: |
iforce2d | 0:972874f31c98 | 204 | break; |
iforce2d | 0:972874f31c98 | 205 | case U8G_DEV_MSG_SET_XY_CB: |
iforce2d | 0:972874f31c98 | 206 | break; |
iforce2d | 0:972874f31c98 | 207 | case U8G_DEV_MSG_GET_MODE: |
iforce2d | 0:972874f31c98 | 208 | return U8G_MODE_BW; |
iforce2d | 0:972874f31c98 | 209 | } |
iforce2d | 0:972874f31c98 | 210 | return 1; |
iforce2d | 0:972874f31c98 | 211 | } |
iforce2d | 0:972874f31c98 | 212 | |
iforce2d | 0:972874f31c98 | 213 | |
iforce2d | 0:972874f31c98 | 214 |