iforce2d Chris
/
ubxDistanceMeter
Displays distance to start location on OLED screen.
u8g_virtual_screen.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_virtual_screen.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 | |
iforce2d | 0:972874f31c98 | 35 | */ |
iforce2d | 0:972874f31c98 | 36 | |
iforce2d | 0:972874f31c98 | 37 | #include "u8g.h" |
iforce2d | 0:972874f31c98 | 38 | |
iforce2d | 0:972874f31c98 | 39 | struct _u8g_vs_t |
iforce2d | 0:972874f31c98 | 40 | { |
iforce2d | 0:972874f31c98 | 41 | u8g_uint_t x; |
iforce2d | 0:972874f31c98 | 42 | u8g_uint_t y; |
iforce2d | 0:972874f31c98 | 43 | u8g_t *u8g; |
iforce2d | 0:972874f31c98 | 44 | }; |
iforce2d | 0:972874f31c98 | 45 | typedef struct _u8g_vs_t u8g_vs_t; |
iforce2d | 0:972874f31c98 | 46 | |
iforce2d | 0:972874f31c98 | 47 | #define U8g_VS_MAX 4 |
iforce2d | 0:972874f31c98 | 48 | uint8_t u8g_vs_cnt = 0; |
iforce2d | 0:972874f31c98 | 49 | u8g_vs_t u8g_vs_list[U8g_VS_MAX]; |
iforce2d | 0:972874f31c98 | 50 | uint8_t u8g_vs_current; |
iforce2d | 0:972874f31c98 | 51 | u8g_uint_t u8g_vs_width; |
iforce2d | 0:972874f31c98 | 52 | u8g_uint_t u8g_vs_height; |
iforce2d | 0:972874f31c98 | 53 | |
iforce2d | 0:972874f31c98 | 54 | uint8_t u8g_dev_vs_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) |
iforce2d | 0:972874f31c98 | 55 | { |
iforce2d | 0:972874f31c98 | 56 | switch(msg) |
iforce2d | 0:972874f31c98 | 57 | { |
iforce2d | 0:972874f31c98 | 58 | default: |
iforce2d | 0:972874f31c98 | 59 | { |
iforce2d | 0:972874f31c98 | 60 | uint8_t i; |
iforce2d | 0:972874f31c98 | 61 | for( i = 0; i < u8g_vs_cnt; i++ ) |
iforce2d | 0:972874f31c98 | 62 | { |
iforce2d | 0:972874f31c98 | 63 | u8g_call_dev_fn(u8g_vs_list[i].u8g, u8g_vs_list[i].u8g->dev, msg, arg); |
iforce2d | 0:972874f31c98 | 64 | } |
iforce2d | 0:972874f31c98 | 65 | } |
iforce2d | 0:972874f31c98 | 66 | return 1; |
iforce2d | 0:972874f31c98 | 67 | case U8G_DEV_MSG_PAGE_FIRST: |
iforce2d | 0:972874f31c98 | 68 | u8g_vs_current = 0; |
iforce2d | 0:972874f31c98 | 69 | if ( u8g_vs_cnt != 0 ) |
iforce2d | 0:972874f31c98 | 70 | return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); |
iforce2d | 0:972874f31c98 | 71 | return 0; |
iforce2d | 0:972874f31c98 | 72 | case U8G_DEV_MSG_PAGE_NEXT: |
iforce2d | 0:972874f31c98 | 73 | { |
iforce2d | 0:972874f31c98 | 74 | uint8_t ret = 0; |
iforce2d | 0:972874f31c98 | 75 | if ( u8g_vs_cnt != 0 ) |
iforce2d | 0:972874f31c98 | 76 | ret = u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); |
iforce2d | 0:972874f31c98 | 77 | if ( ret != 0 ) |
iforce2d | 0:972874f31c98 | 78 | return ret; |
iforce2d | 0:972874f31c98 | 79 | u8g_vs_current++; /* next device */ |
iforce2d | 0:972874f31c98 | 80 | if ( u8g_vs_current >= u8g_vs_cnt ) /* reached end? */ |
iforce2d | 0:972874f31c98 | 81 | return 0; |
iforce2d | 0:972874f31c98 | 82 | return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, U8G_DEV_MSG_PAGE_FIRST, arg); |
iforce2d | 0:972874f31c98 | 83 | } |
iforce2d | 0:972874f31c98 | 84 | return 0; |
iforce2d | 0:972874f31c98 | 85 | case U8G_DEV_MSG_GET_WIDTH: |
iforce2d | 0:972874f31c98 | 86 | *((u8g_uint_t *)arg) = u8g_vs_width; |
iforce2d | 0:972874f31c98 | 87 | break; |
iforce2d | 0:972874f31c98 | 88 | case U8G_DEV_MSG_GET_HEIGHT: |
iforce2d | 0:972874f31c98 | 89 | *((u8g_uint_t *)arg) = u8g_vs_height; |
iforce2d | 0:972874f31c98 | 90 | break; |
iforce2d | 0:972874f31c98 | 91 | case U8G_DEV_MSG_GET_PAGE_BOX: |
iforce2d | 0:972874f31c98 | 92 | if ( u8g_vs_current < u8g_vs_cnt ) |
iforce2d | 0:972874f31c98 | 93 | { |
iforce2d | 0:972874f31c98 | 94 | u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); |
iforce2d | 0:972874f31c98 | 95 | ((u8g_box_t *)arg)->x0 += u8g_vs_list[u8g_vs_current].x; |
iforce2d | 0:972874f31c98 | 96 | ((u8g_box_t *)arg)->x1 += u8g_vs_list[u8g_vs_current].x; |
iforce2d | 0:972874f31c98 | 97 | ((u8g_box_t *)arg)->y0 += u8g_vs_list[u8g_vs_current].y; |
iforce2d | 0:972874f31c98 | 98 | ((u8g_box_t *)arg)->y1 += u8g_vs_list[u8g_vs_current].y; |
iforce2d | 0:972874f31c98 | 99 | } |
iforce2d | 0:972874f31c98 | 100 | else |
iforce2d | 0:972874f31c98 | 101 | { |
iforce2d | 0:972874f31c98 | 102 | ((u8g_box_t *)arg)->x0 = 0; |
iforce2d | 0:972874f31c98 | 103 | ((u8g_box_t *)arg)->x1 = 0; |
iforce2d | 0:972874f31c98 | 104 | ((u8g_box_t *)arg)->y0 = 0; |
iforce2d | 0:972874f31c98 | 105 | ((u8g_box_t *)arg)->y1 = 0; |
iforce2d | 0:972874f31c98 | 106 | } |
iforce2d | 0:972874f31c98 | 107 | return 1; |
iforce2d | 0:972874f31c98 | 108 | case U8G_DEV_MSG_SET_PIXEL: |
iforce2d | 0:972874f31c98 | 109 | case U8G_DEV_MSG_SET_8PIXEL: |
iforce2d | 0:972874f31c98 | 110 | if ( u8g_vs_current < u8g_vs_cnt ) |
iforce2d | 0:972874f31c98 | 111 | { |
iforce2d | 0:972874f31c98 | 112 | ((u8g_dev_arg_pixel_t *)arg)->x -= u8g_vs_list[u8g_vs_current].x; |
iforce2d | 0:972874f31c98 | 113 | ((u8g_dev_arg_pixel_t *)arg)->y -= u8g_vs_list[u8g_vs_current].y; |
iforce2d | 0:972874f31c98 | 114 | return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); |
iforce2d | 0:972874f31c98 | 115 | } |
iforce2d | 0:972874f31c98 | 116 | break; |
iforce2d | 0:972874f31c98 | 117 | } |
iforce2d | 0:972874f31c98 | 118 | return 1; |
iforce2d | 0:972874f31c98 | 119 | } |
iforce2d | 0:972874f31c98 | 120 | |
iforce2d | 0:972874f31c98 | 121 | |
iforce2d | 0:972874f31c98 | 122 | |
iforce2d | 0:972874f31c98 | 123 | u8g_dev_t u8g_dev_vs = { u8g_dev_vs_fn, NULL, NULL }; |
iforce2d | 0:972874f31c98 | 124 | |
iforce2d | 0:972874f31c98 | 125 | void u8g_SetVirtualScreenDimension(u8g_t *vs_u8g, u8g_uint_t width, u8g_uint_t height) |
iforce2d | 0:972874f31c98 | 126 | { |
iforce2d | 0:972874f31c98 | 127 | if ( vs_u8g->dev != &u8g_dev_vs ) |
iforce2d | 0:972874f31c98 | 128 | return; /* abort if there is no a virtual screen device */ |
iforce2d | 0:972874f31c98 | 129 | u8g_vs_width = width; |
iforce2d | 0:972874f31c98 | 130 | u8g_vs_height = height; |
iforce2d | 0:972874f31c98 | 131 | } |
iforce2d | 0:972874f31c98 | 132 | |
iforce2d | 0:972874f31c98 | 133 | uint8_t u8g_AddToVirtualScreen(u8g_t *vs_u8g, u8g_uint_t x, u8g_uint_t y, u8g_t *child_u8g) |
iforce2d | 0:972874f31c98 | 134 | { |
iforce2d | 0:972874f31c98 | 135 | if ( vs_u8g->dev != &u8g_dev_vs ) |
iforce2d | 0:972874f31c98 | 136 | return 0; /* abort if there is no a virtual screen device */ |
iforce2d | 0:972874f31c98 | 137 | if ( u8g_vs_cnt >= U8g_VS_MAX ) |
iforce2d | 0:972874f31c98 | 138 | return 0; /* maximum number of child u8g's reached */ |
iforce2d | 0:972874f31c98 | 139 | u8g_vs_list[u8g_vs_cnt].u8g = child_u8g; |
iforce2d | 0:972874f31c98 | 140 | u8g_vs_list[u8g_vs_cnt].x = x; |
iforce2d | 0:972874f31c98 | 141 | u8g_vs_list[u8g_vs_cnt].y = y; |
iforce2d | 0:972874f31c98 | 142 | u8g_vs_cnt++; |
iforce2d | 0:972874f31c98 | 143 | return 1; |
iforce2d | 0:972874f31c98 | 144 | } |
iforce2d | 0:972874f31c98 | 145 | |
iforce2d | 0:972874f31c98 | 146 |