iforce2d Chris
/
ubxDistanceMeter
Displays distance to start location on OLED screen.
u8g_dev_gprof.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_dev_gprof.c |
iforce2d | 0:972874f31c98 | 4 | |
iforce2d | 0:972874f31c98 | 5 | Device for performance measurement with gprof. |
iforce2d | 0:972874f31c98 | 6 | Does not write any data, but uses a buffer. |
iforce2d | 0:972874f31c98 | 7 | |
iforce2d | 0:972874f31c98 | 8 | Universal 8bit Graphics Library |
iforce2d | 0:972874f31c98 | 9 | |
iforce2d | 0:972874f31c98 | 10 | Copyright (c) 2011, 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 | |
iforce2d | 0:972874f31c98 | 39 | */ |
iforce2d | 0:972874f31c98 | 40 | |
iforce2d | 0:972874f31c98 | 41 | #include "u8g.h" |
iforce2d | 0:972874f31c98 | 42 | |
iforce2d | 0:972874f31c98 | 43 | |
iforce2d | 0:972874f31c98 | 44 | #define WIDTH 128 |
iforce2d | 0:972874f31c98 | 45 | #define HEIGHT 64 |
iforce2d | 0:972874f31c98 | 46 | #define PAGE_HEIGHT 8 |
iforce2d | 0:972874f31c98 | 47 | |
iforce2d | 0:972874f31c98 | 48 | uint8_t u8g_dev_gprof_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); |
iforce2d | 0:972874f31c98 | 49 | |
iforce2d | 0:972874f31c98 | 50 | uint8_t u8g_pb_dev_gprof_buf[WIDTH]; |
iforce2d | 0:972874f31c98 | 51 | u8g_pb_t u8g_pb_dev_gprof = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_pb_dev_gprof_buf }; |
iforce2d | 0:972874f31c98 | 52 | |
iforce2d | 0:972874f31c98 | 53 | u8g_dev_t u8g_dev_gprof = { u8g_dev_gprof_fn, &u8g_pb_dev_gprof, NULL }; |
iforce2d | 0:972874f31c98 | 54 | |
iforce2d | 0:972874f31c98 | 55 | uint8_t u8g_dev_gprof_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) |
iforce2d | 0:972874f31c98 | 56 | { |
iforce2d | 0:972874f31c98 | 57 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); |
iforce2d | 0:972874f31c98 | 58 | |
iforce2d | 0:972874f31c98 | 59 | switch(msg) |
iforce2d | 0:972874f31c98 | 60 | { |
iforce2d | 0:972874f31c98 | 61 | case U8G_DEV_MSG_INIT: |
iforce2d | 0:972874f31c98 | 62 | break; |
iforce2d | 0:972874f31c98 | 63 | case U8G_DEV_MSG_STOP: |
iforce2d | 0:972874f31c98 | 64 | break; |
iforce2d | 0:972874f31c98 | 65 | case U8G_DEV_MSG_PAGE_FIRST: |
iforce2d | 0:972874f31c98 | 66 | u8g_pb_Clear(pb); |
iforce2d | 0:972874f31c98 | 67 | u8g_page_First(&(pb->p)); |
iforce2d | 0:972874f31c98 | 68 | break; |
iforce2d | 0:972874f31c98 | 69 | case U8G_DEV_MSG_PAGE_NEXT: |
iforce2d | 0:972874f31c98 | 70 | /* |
iforce2d | 0:972874f31c98 | 71 | { |
iforce2d | 0:972874f31c98 | 72 | uint8_t i, j; |
iforce2d | 0:972874f31c98 | 73 | uint8_t page_height; |
iforce2d | 0:972874f31c98 | 74 | page_height = pb->p.page_y1; |
iforce2d | 0:972874f31c98 | 75 | page_height -= pb->p.page_y0; |
iforce2d | 0:972874f31c98 | 76 | page_height++; |
iforce2d | 0:972874f31c98 | 77 | for( j = 0; j < page_height; j++ ) |
iforce2d | 0:972874f31c98 | 78 | { |
iforce2d | 0:972874f31c98 | 79 | printf("%02d ", j); |
iforce2d | 0:972874f31c98 | 80 | for( i = 0; i < WIDTH; i++ ) |
iforce2d | 0:972874f31c98 | 81 | { |
iforce2d | 0:972874f31c98 | 82 | if ( (u8g_pb_dev_stdout_buf[i] & (1<<j)) != 0 ) |
iforce2d | 0:972874f31c98 | 83 | printf("#"); |
iforce2d | 0:972874f31c98 | 84 | else |
iforce2d | 0:972874f31c98 | 85 | printf("."); |
iforce2d | 0:972874f31c98 | 86 | } |
iforce2d | 0:972874f31c98 | 87 | printf("\n"); |
iforce2d | 0:972874f31c98 | 88 | } |
iforce2d | 0:972874f31c98 | 89 | } |
iforce2d | 0:972874f31c98 | 90 | */ |
iforce2d | 0:972874f31c98 | 91 | if ( u8g_page_Next(&(pb->p)) == 0 ) |
iforce2d | 0:972874f31c98 | 92 | { |
iforce2d | 0:972874f31c98 | 93 | //printf("\n"); |
iforce2d | 0:972874f31c98 | 94 | return 0; |
iforce2d | 0:972874f31c98 | 95 | } |
iforce2d | 0:972874f31c98 | 96 | u8g_pb_Clear(pb); |
iforce2d | 0:972874f31c98 | 97 | break; |
iforce2d | 0:972874f31c98 | 98 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION |
iforce2d | 0:972874f31c98 | 99 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: |
iforce2d | 0:972874f31c98 | 100 | { |
iforce2d | 0:972874f31c98 | 101 | u8g_dev_arg_bbx_t *bbx = (u8g_dev_arg_bbx_t *)arg; |
iforce2d | 0:972874f31c98 | 102 | u8g_uint_t x2, y2; |
iforce2d | 0:972874f31c98 | 103 | |
iforce2d | 0:972874f31c98 | 104 | y2 = bbx->y; |
iforce2d | 0:972874f31c98 | 105 | y2 += bbx->h; |
iforce2d | 0:972874f31c98 | 106 | y2--; |
iforce2d | 0:972874f31c98 | 107 | |
iforce2d | 0:972874f31c98 | 108 | if ( u8g_pb_IsYIntersection(pb, bbx->y, y2) == 0 ) |
iforce2d | 0:972874f31c98 | 109 | return 0; |
iforce2d | 0:972874f31c98 | 110 | |
iforce2d | 0:972874f31c98 | 111 | /* 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 | 112 | x2 = bbx->x; |
iforce2d | 0:972874f31c98 | 113 | x2 += bbx->w; |
iforce2d | 0:972874f31c98 | 114 | x2--; |
iforce2d | 0:972874f31c98 | 115 | |
iforce2d | 0:972874f31c98 | 116 | if ( u8g_pb_IsXIntersection(pb, bbx->x, x2) == 0 ) |
iforce2d | 0:972874f31c98 | 117 | return 0; |
iforce2d | 0:972874f31c98 | 118 | } |
iforce2d | 0:972874f31c98 | 119 | return 1; |
iforce2d | 0:972874f31c98 | 120 | #endif |
iforce2d | 0:972874f31c98 | 121 | case U8G_DEV_MSG_GET_PAGE_BOX: |
iforce2d | 0:972874f31c98 | 122 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); |
iforce2d | 0:972874f31c98 | 123 | break; |
iforce2d | 0:972874f31c98 | 124 | case U8G_DEV_MSG_SET_COLOR_ENTRY: |
iforce2d | 0:972874f31c98 | 125 | break; |
iforce2d | 0:972874f31c98 | 126 | case U8G_DEV_MSG_SET_XY_CB: |
iforce2d | 0:972874f31c98 | 127 | break; |
iforce2d | 0:972874f31c98 | 128 | } |
iforce2d | 0:972874f31c98 | 129 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); |
iforce2d | 0:972874f31c98 | 130 | } |
iforce2d | 0:972874f31c98 | 131 |