iforce2d Chris
/
ubxDistanceMeter
Displays distance to start location on OLED screen.
u8g_scale.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_scale.c |
iforce2d | 0:972874f31c98 | 4 | |
iforce2d | 0:972874f31c98 | 5 | Universal 8bit Graphics Library |
iforce2d | 0:972874f31c98 | 6 | |
iforce2d | 0:972874f31c98 | 7 | Copyright (c) 2012, olikraus@gmail.com |
iforce2d | 0:972874f31c98 | 8 | All rights reserved. |
iforce2d | 0:972874f31c98 | 9 | |
iforce2d | 0:972874f31c98 | 10 | Redistribution and use in source and binary forms, with or without modification, |
iforce2d | 0:972874f31c98 | 11 | are permitted provided that the following conditions are met: |
iforce2d | 0:972874f31c98 | 12 | |
iforce2d | 0:972874f31c98 | 13 | * Redistributions of source code must retain the above copyright notice, this list |
iforce2d | 0:972874f31c98 | 14 | of conditions and the following disclaimer. |
iforce2d | 0:972874f31c98 | 15 | |
iforce2d | 0:972874f31c98 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this |
iforce2d | 0:972874f31c98 | 17 | list of conditions and the following disclaimer in the documentation and/or other |
iforce2d | 0:972874f31c98 | 18 | materials provided with the distribution. |
iforce2d | 0:972874f31c98 | 19 | |
iforce2d | 0:972874f31c98 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
iforce2d | 0:972874f31c98 | 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, |
iforce2d | 0:972874f31c98 | 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
iforce2d | 0:972874f31c98 | 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
iforce2d | 0:972874f31c98 | 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
iforce2d | 0:972874f31c98 | 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
iforce2d | 0:972874f31c98 | 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
iforce2d | 0:972874f31c98 | 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
iforce2d | 0:972874f31c98 | 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
iforce2d | 0:972874f31c98 | 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
iforce2d | 0:972874f31c98 | 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
iforce2d | 0:972874f31c98 | 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
iforce2d | 0:972874f31c98 | 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
iforce2d | 0:972874f31c98 | 33 | |
iforce2d | 0:972874f31c98 | 34 | Scale screen by some constant factors. Usefull for making bigger fonts wiht less |
iforce2d | 0:972874f31c98 | 35 | memory consumption |
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 | uint8_t u8g_dev_scale_2x2_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); |
iforce2d | 0:972874f31c98 | 42 | |
iforce2d | 0:972874f31c98 | 43 | |
iforce2d | 0:972874f31c98 | 44 | u8g_dev_t u8g_dev_scale = { u8g_dev_scale_2x2_fn, NULL, NULL }; |
iforce2d | 0:972874f31c98 | 45 | |
iforce2d | 0:972874f31c98 | 46 | void u8g_UndoScale(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 47 | { |
iforce2d | 0:972874f31c98 | 48 | if ( u8g->dev != &u8g_dev_scale ) |
iforce2d | 0:972874f31c98 | 49 | return; |
iforce2d | 0:972874f31c98 | 50 | u8g->dev = u8g_dev_scale.dev_mem; |
iforce2d | 0:972874f31c98 | 51 | u8g_UpdateDimension(u8g); |
iforce2d | 0:972874f31c98 | 52 | } |
iforce2d | 0:972874f31c98 | 53 | |
iforce2d | 0:972874f31c98 | 54 | void u8g_SetScale2x2(u8g_t *u8g) |
iforce2d | 0:972874f31c98 | 55 | { |
iforce2d | 0:972874f31c98 | 56 | if ( u8g->dev != &u8g_dev_scale ) |
iforce2d | 0:972874f31c98 | 57 | { |
iforce2d | 0:972874f31c98 | 58 | u8g_dev_scale.dev_mem = u8g->dev; |
iforce2d | 0:972874f31c98 | 59 | u8g->dev = &u8g_dev_scale; |
iforce2d | 0:972874f31c98 | 60 | } |
iforce2d | 0:972874f31c98 | 61 | u8g_dev_scale.dev_fn = u8g_dev_scale_2x2_fn; |
iforce2d | 0:972874f31c98 | 62 | u8g_UpdateDimension(u8g); |
iforce2d | 0:972874f31c98 | 63 | } |
iforce2d | 0:972874f31c98 | 64 | |
iforce2d | 0:972874f31c98 | 65 | |
iforce2d | 0:972874f31c98 | 66 | uint8_t u8g_dev_scale_2x2_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) |
iforce2d | 0:972874f31c98 | 67 | { |
iforce2d | 0:972874f31c98 | 68 | u8g_dev_t *chain = (u8g_dev_t *)(dev->dev_mem); |
iforce2d | 0:972874f31c98 | 69 | uint8_t pixel; |
iforce2d | 0:972874f31c98 | 70 | uint16_t scaled_pixel; |
iforce2d | 0:972874f31c98 | 71 | uint8_t i; |
iforce2d | 0:972874f31c98 | 72 | uint8_t dir; |
iforce2d | 0:972874f31c98 | 73 | u8g_uint_t x, y, xx,yy; |
iforce2d | 0:972874f31c98 | 74 | |
iforce2d | 0:972874f31c98 | 75 | switch(msg) |
iforce2d | 0:972874f31c98 | 76 | { |
iforce2d | 0:972874f31c98 | 77 | default: |
iforce2d | 0:972874f31c98 | 78 | return u8g_call_dev_fn(u8g, chain, msg, arg); |
iforce2d | 0:972874f31c98 | 79 | case U8G_DEV_MSG_GET_WIDTH: |
iforce2d | 0:972874f31c98 | 80 | *((u8g_uint_t *)arg) = u8g_GetWidthLL(u8g, chain) / 2; |
iforce2d | 0:972874f31c98 | 81 | break; |
iforce2d | 0:972874f31c98 | 82 | case U8G_DEV_MSG_GET_HEIGHT: |
iforce2d | 0:972874f31c98 | 83 | *((u8g_uint_t *)arg) = u8g_GetHeightLL(u8g, chain) / 2; |
iforce2d | 0:972874f31c98 | 84 | break; |
iforce2d | 0:972874f31c98 | 85 | case U8G_DEV_MSG_GET_PAGE_BOX: |
iforce2d | 0:972874f31c98 | 86 | /* get page size from next device in the chain */ |
iforce2d | 0:972874f31c98 | 87 | u8g_call_dev_fn(u8g, chain, msg, arg); |
iforce2d | 0:972874f31c98 | 88 | ((u8g_box_t *)arg)->x0 /= 2; |
iforce2d | 0:972874f31c98 | 89 | ((u8g_box_t *)arg)->x1 /= 2; |
iforce2d | 0:972874f31c98 | 90 | ((u8g_box_t *)arg)->y0 /= 2; |
iforce2d | 0:972874f31c98 | 91 | ((u8g_box_t *)arg)->y1 /= 2; |
iforce2d | 0:972874f31c98 | 92 | return 1; |
iforce2d | 0:972874f31c98 | 93 | case U8G_DEV_MSG_SET_PIXEL: |
iforce2d | 0:972874f31c98 | 94 | x = ((u8g_dev_arg_pixel_t *)arg)->x; |
iforce2d | 0:972874f31c98 | 95 | x *= 2; |
iforce2d | 0:972874f31c98 | 96 | y = ((u8g_dev_arg_pixel_t *)arg)->y; |
iforce2d | 0:972874f31c98 | 97 | y *= 2; |
iforce2d | 0:972874f31c98 | 98 | ((u8g_dev_arg_pixel_t *)arg)->x = x; |
iforce2d | 0:972874f31c98 | 99 | ((u8g_dev_arg_pixel_t *)arg)->y = y; |
iforce2d | 0:972874f31c98 | 100 | u8g_call_dev_fn(u8g, chain, msg, arg); |
iforce2d | 0:972874f31c98 | 101 | x++; |
iforce2d | 0:972874f31c98 | 102 | ((u8g_dev_arg_pixel_t *)arg)->x = x; |
iforce2d | 0:972874f31c98 | 103 | ((u8g_dev_arg_pixel_t *)arg)->y = y; |
iforce2d | 0:972874f31c98 | 104 | u8g_call_dev_fn(u8g, chain, msg, arg); |
iforce2d | 0:972874f31c98 | 105 | y++; |
iforce2d | 0:972874f31c98 | 106 | ((u8g_dev_arg_pixel_t *)arg)->x = x; |
iforce2d | 0:972874f31c98 | 107 | ((u8g_dev_arg_pixel_t *)arg)->y = y; |
iforce2d | 0:972874f31c98 | 108 | u8g_call_dev_fn(u8g, chain, msg, arg); |
iforce2d | 0:972874f31c98 | 109 | x--; |
iforce2d | 0:972874f31c98 | 110 | ((u8g_dev_arg_pixel_t *)arg)->x = x; |
iforce2d | 0:972874f31c98 | 111 | ((u8g_dev_arg_pixel_t *)arg)->y = y; |
iforce2d | 0:972874f31c98 | 112 | u8g_call_dev_fn(u8g, chain, msg, arg); |
iforce2d | 0:972874f31c98 | 113 | break; |
iforce2d | 0:972874f31c98 | 114 | case U8G_DEV_MSG_SET_8PIXEL: |
iforce2d | 0:972874f31c98 | 115 | pixel = ((u8g_dev_arg_pixel_t *)arg)->pixel; |
iforce2d | 0:972874f31c98 | 116 | dir = ((u8g_dev_arg_pixel_t *)arg)->dir; |
iforce2d | 0:972874f31c98 | 117 | scaled_pixel = 0; |
iforce2d | 0:972874f31c98 | 118 | for( i = 0; i < 8; i++ ) |
iforce2d | 0:972874f31c98 | 119 | { |
iforce2d | 0:972874f31c98 | 120 | scaled_pixel<<=2; |
iforce2d | 0:972874f31c98 | 121 | if ( pixel & 128 ) |
iforce2d | 0:972874f31c98 | 122 | { |
iforce2d | 0:972874f31c98 | 123 | scaled_pixel |= 3; |
iforce2d | 0:972874f31c98 | 124 | } |
iforce2d | 0:972874f31c98 | 125 | pixel<<=1; |
iforce2d | 0:972874f31c98 | 126 | } |
iforce2d | 0:972874f31c98 | 127 | x = ((u8g_dev_arg_pixel_t *)arg)->x; |
iforce2d | 0:972874f31c98 | 128 | x *= 2; |
iforce2d | 0:972874f31c98 | 129 | xx = x; |
iforce2d | 0:972874f31c98 | 130 | y = ((u8g_dev_arg_pixel_t *)arg)->y; |
iforce2d | 0:972874f31c98 | 131 | y *= 2; |
iforce2d | 0:972874f31c98 | 132 | yy = y; |
iforce2d | 0:972874f31c98 | 133 | if ( ((u8g_dev_arg_pixel_t *)arg)->dir & 1 ) |
iforce2d | 0:972874f31c98 | 134 | { |
iforce2d | 0:972874f31c98 | 135 | xx++; |
iforce2d | 0:972874f31c98 | 136 | } |
iforce2d | 0:972874f31c98 | 137 | else |
iforce2d | 0:972874f31c98 | 138 | { |
iforce2d | 0:972874f31c98 | 139 | yy++; |
iforce2d | 0:972874f31c98 | 140 | } |
iforce2d | 0:972874f31c98 | 141 | |
iforce2d | 0:972874f31c98 | 142 | ((u8g_dev_arg_pixel_t *)arg)->pixel = scaled_pixel>>8; |
iforce2d | 0:972874f31c98 | 143 | ((u8g_dev_arg_pixel_t *)arg)->x = x; |
iforce2d | 0:972874f31c98 | 144 | ((u8g_dev_arg_pixel_t *)arg)->y = y; |
iforce2d | 0:972874f31c98 | 145 | ((u8g_dev_arg_pixel_t *)arg)->dir = dir; |
iforce2d | 0:972874f31c98 | 146 | u8g_call_dev_fn(u8g, chain, msg, arg); |
iforce2d | 0:972874f31c98 | 147 | |
iforce2d | 0:972874f31c98 | 148 | |
iforce2d | 0:972874f31c98 | 149 | ((u8g_dev_arg_pixel_t *)arg)->x = xx; |
iforce2d | 0:972874f31c98 | 150 | ((u8g_dev_arg_pixel_t *)arg)->y = yy; |
iforce2d | 0:972874f31c98 | 151 | ((u8g_dev_arg_pixel_t *)arg)->dir = dir; |
iforce2d | 0:972874f31c98 | 152 | u8g_call_dev_fn(u8g, chain, msg, arg); |
iforce2d | 0:972874f31c98 | 153 | |
iforce2d | 0:972874f31c98 | 154 | ((u8g_dev_arg_pixel_t *)arg)->pixel = scaled_pixel&255; |
iforce2d | 0:972874f31c98 | 155 | //((u8g_dev_arg_pixel_t *)arg)->pixel = 0x00; |
iforce2d | 0:972874f31c98 | 156 | switch(dir) |
iforce2d | 0:972874f31c98 | 157 | { |
iforce2d | 0:972874f31c98 | 158 | case 0: |
iforce2d | 0:972874f31c98 | 159 | x+=8; |
iforce2d | 0:972874f31c98 | 160 | xx+=8; |
iforce2d | 0:972874f31c98 | 161 | break; |
iforce2d | 0:972874f31c98 | 162 | case 1: |
iforce2d | 0:972874f31c98 | 163 | y+=8; |
iforce2d | 0:972874f31c98 | 164 | yy+=8; |
iforce2d | 0:972874f31c98 | 165 | break; |
iforce2d | 0:972874f31c98 | 166 | case 2: |
iforce2d | 0:972874f31c98 | 167 | x-=8; |
iforce2d | 0:972874f31c98 | 168 | xx-=8; |
iforce2d | 0:972874f31c98 | 169 | break; |
iforce2d | 0:972874f31c98 | 170 | case 3: |
iforce2d | 0:972874f31c98 | 171 | y-=8; |
iforce2d | 0:972874f31c98 | 172 | yy-=8; |
iforce2d | 0:972874f31c98 | 173 | break; |
iforce2d | 0:972874f31c98 | 174 | } |
iforce2d | 0:972874f31c98 | 175 | ((u8g_dev_arg_pixel_t *)arg)->x = x; |
iforce2d | 0:972874f31c98 | 176 | ((u8g_dev_arg_pixel_t *)arg)->y = y; |
iforce2d | 0:972874f31c98 | 177 | ((u8g_dev_arg_pixel_t *)arg)->dir = dir; |
iforce2d | 0:972874f31c98 | 178 | u8g_call_dev_fn(u8g, chain, msg, arg); |
iforce2d | 0:972874f31c98 | 179 | |
iforce2d | 0:972874f31c98 | 180 | ((u8g_dev_arg_pixel_t *)arg)->x = xx; |
iforce2d | 0:972874f31c98 | 181 | ((u8g_dev_arg_pixel_t *)arg)->y = yy; |
iforce2d | 0:972874f31c98 | 182 | ((u8g_dev_arg_pixel_t *)arg)->dir = dir; |
iforce2d | 0:972874f31c98 | 183 | u8g_call_dev_fn(u8g, chain, msg, arg); |
iforce2d | 0:972874f31c98 | 184 | break; |
iforce2d | 0:972874f31c98 | 185 | } |
iforce2d | 0:972874f31c98 | 186 | return 1; |
iforce2d | 0:972874f31c98 | 187 | } |
iforce2d | 0:972874f31c98 | 188 | |
iforce2d | 0:972874f31c98 | 189 |