hadif azli / Mbed 2 deprecated TEST123

Dependencies:   mbed Blynk

Committer:
lixianyu
Date:
Mon Jun 13 02:21:11 2016 +0000
Revision:
1:0e75de2a5d21
Parent:
0:d8f4c441e032
u8glib???????????????????????????Adafruit_GFX????OLED????????bitmap??????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lixianyu 0:d8f4c441e032 1 /*
lixianyu 0:d8f4c441e032 2
lixianyu 0:d8f4c441e032 3 u8g_pb.c
lixianyu 0:d8f4c441e032 4
lixianyu 0:d8f4c441e032 5 common procedures for the page buffer
lixianyu 0:d8f4c441e032 6
lixianyu 0:d8f4c441e032 7 Universal 8bit Graphics Library
lixianyu 0:d8f4c441e032 8
lixianyu 0:d8f4c441e032 9 Copyright (c) 2011, olikraus@gmail.com
lixianyu 0:d8f4c441e032 10 All rights reserved.
lixianyu 0:d8f4c441e032 11
lixianyu 0:d8f4c441e032 12 Redistribution and use in source and binary forms, with or without modification,
lixianyu 0:d8f4c441e032 13 are permitted provided that the following conditions are met:
lixianyu 0:d8f4c441e032 14
lixianyu 0:d8f4c441e032 15 * Redistributions of source code must retain the above copyright notice, this list
lixianyu 0:d8f4c441e032 16 of conditions and the following disclaimer.
lixianyu 0:d8f4c441e032 17
lixianyu 0:d8f4c441e032 18 * Redistributions in binary form must reproduce the above copyright notice, this
lixianyu 0:d8f4c441e032 19 list of conditions and the following disclaimer in the documentation and/or other
lixianyu 0:d8f4c441e032 20 materials provided with the distribution.
lixianyu 0:d8f4c441e032 21
lixianyu 0:d8f4c441e032 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
lixianyu 0:d8f4c441e032 23 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
lixianyu 0:d8f4c441e032 24 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
lixianyu 0:d8f4c441e032 25 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
lixianyu 0:d8f4c441e032 26 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
lixianyu 0:d8f4c441e032 27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
lixianyu 0:d8f4c441e032 28 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
lixianyu 0:d8f4c441e032 29 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
lixianyu 0:d8f4c441e032 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
lixianyu 0:d8f4c441e032 31 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
lixianyu 0:d8f4c441e032 32 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
lixianyu 0:d8f4c441e032 33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
lixianyu 0:d8f4c441e032 34 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
lixianyu 0:d8f4c441e032 35
lixianyu 0:d8f4c441e032 36
lixianyu 0:d8f4c441e032 37 */
lixianyu 0:d8f4c441e032 38
lixianyu 0:d8f4c441e032 39 #include "u8g.h"
lixianyu 0:d8f4c441e032 40
lixianyu 0:d8f4c441e032 41 void u8g_pb_Clear(u8g_pb_t *b)
lixianyu 0:d8f4c441e032 42 {
lixianyu 0:d8f4c441e032 43 uint8_t *ptr = (uint8_t *)b->buf;
lixianyu 0:d8f4c441e032 44 uint8_t *end_ptr = ptr;
lixianyu 0:d8f4c441e032 45 end_ptr += b->width;
lixianyu 0:d8f4c441e032 46 do
lixianyu 0:d8f4c441e032 47 {
lixianyu 0:d8f4c441e032 48 *ptr++ = 0;
lixianyu 0:d8f4c441e032 49 } while( ptr != end_ptr );
lixianyu 0:d8f4c441e032 50 }
lixianyu 0:d8f4c441e032 51
lixianyu 0:d8f4c441e032 52 /* the following procedure does not work. why? Can be checked with descpic */
lixianyu 0:d8f4c441e032 53 /*
lixianyu 0:d8f4c441e032 54 void u8g_pb_Clear(u8g_pb_t *b)
lixianyu 0:d8f4c441e032 55 {
lixianyu 0:d8f4c441e032 56 uint8_t *ptr = (uint8_t *)b->buf;
lixianyu 0:d8f4c441e032 57 uint8_t cnt = b->width;
lixianyu 0:d8f4c441e032 58 do
lixianyu 0:d8f4c441e032 59 {
lixianyu 0:d8f4c441e032 60 *ptr++ = 0;
lixianyu 0:d8f4c441e032 61 cnt--;
lixianyu 0:d8f4c441e032 62 } while( cnt != 0 );
lixianyu 0:d8f4c441e032 63 }
lixianyu 0:d8f4c441e032 64 */
lixianyu 0:d8f4c441e032 65
lixianyu 0:d8f4c441e032 66 /*
lixianyu 0:d8f4c441e032 67 intersection assumptions:
lixianyu 0:d8f4c441e032 68 a1 <= a2 is always true
lixianyu 0:d8f4c441e032 69 */
lixianyu 0:d8f4c441e032 70 /*
lixianyu 0:d8f4c441e032 71 minimized version
lixianyu 0:d8f4c441e032 72 ---1----0 1 b1 <= a2 && b1 > b2
lixianyu 0:d8f4c441e032 73 -----1--0 1 b2 >= a1 && b1 > b2
lixianyu 0:d8f4c441e032 74 ---1-1--- 1 b1 <= a2 && b2 >= a1
lixianyu 0:d8f4c441e032 75 */
lixianyu 0:d8f4c441e032 76 /*
lixianyu 0:d8f4c441e032 77 uint8_t u8g_pb8v1_IsYIntersection___Old(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1)
lixianyu 0:d8f4c441e032 78 {
lixianyu 0:d8f4c441e032 79 uint8_t c0, c1, c;
lixianyu 0:d8f4c441e032 80 c0 = v0 <= b->p.page_y1;
lixianyu 0:d8f4c441e032 81 c1 = v1 >= b->p.page_y0;
lixianyu 0:d8f4c441e032 82 c = v0 > v1;
lixianyu 0:d8f4c441e032 83 if ( c0 && c1 ) return 1;
lixianyu 0:d8f4c441e032 84 if ( c0 && c ) return 1;
lixianyu 0:d8f4c441e032 85 if ( c1 && c ) return 1;
lixianyu 0:d8f4c441e032 86 return 0;
lixianyu 0:d8f4c441e032 87 }
lixianyu 0:d8f4c441e032 88 */
lixianyu 0:d8f4c441e032 89
lixianyu 0:d8f4c441e032 90 uint8_t u8g_pb_IsYIntersection(u8g_pb_t *pb, u8g_uint_t v0, u8g_uint_t v1)
lixianyu 0:d8f4c441e032 91 {
lixianyu 0:d8f4c441e032 92 uint8_t c1, c2, c3, tmp;
lixianyu 0:d8f4c441e032 93 c1 = v0 <= pb->p.page_y1;
lixianyu 0:d8f4c441e032 94 c2 = v1 >= pb->p.page_y0;
lixianyu 0:d8f4c441e032 95 c3 = v0 > v1;
lixianyu 0:d8f4c441e032 96 /*
lixianyu 0:d8f4c441e032 97 if ( c1 && c2 )
lixianyu 0:d8f4c441e032 98 return 1;
lixianyu 0:d8f4c441e032 99 if ( c1 && c3 )
lixianyu 0:d8f4c441e032 100 return 1;
lixianyu 0:d8f4c441e032 101 if ( c2 && c3 )
lixianyu 0:d8f4c441e032 102 return 1;
lixianyu 0:d8f4c441e032 103 return 0;
lixianyu 0:d8f4c441e032 104 */
lixianyu 0:d8f4c441e032 105
lixianyu 0:d8f4c441e032 106 tmp = c1;
lixianyu 0:d8f4c441e032 107 c1 &= c2;
lixianyu 0:d8f4c441e032 108 c2 &= c3;
lixianyu 0:d8f4c441e032 109 c3 &= tmp;
lixianyu 0:d8f4c441e032 110 c1 |= c2;
lixianyu 0:d8f4c441e032 111 c1 |= c3;
lixianyu 0:d8f4c441e032 112 return c1 & 1;
lixianyu 0:d8f4c441e032 113 }
lixianyu 0:d8f4c441e032 114
lixianyu 0:d8f4c441e032 115
lixianyu 0:d8f4c441e032 116 uint8_t u8g_pb_IsXIntersection(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1)
lixianyu 0:d8f4c441e032 117 {
lixianyu 0:d8f4c441e032 118 uint8_t /*c0, c1, */ c2, c3;
lixianyu 0:d8f4c441e032 119 /*
lixianyu 0:d8f4c441e032 120 conditions: b->p.page_y0 < b->p.page_y1
lixianyu 0:d8f4c441e032 121 there are no restriction on v0 and v1. If v0 > v1, then warp around unsigned is assumed
lixianyu 0:d8f4c441e032 122 */
lixianyu 0:d8f4c441e032 123 /*
lixianyu 0:d8f4c441e032 124 c0 = v0 < 0;
lixianyu 0:d8f4c441e032 125 c1 = v1 < 0;
lixianyu 0:d8f4c441e032 126 */
lixianyu 0:d8f4c441e032 127 c2 = v0 > b->width;
lixianyu 0:d8f4c441e032 128 c3 = v1 > b->width;
lixianyu 0:d8f4c441e032 129 /*if ( c0 && c1 ) return 0;*/
lixianyu 0:d8f4c441e032 130 if ( c2 && c3 ) return 0;
lixianyu 0:d8f4c441e032 131 /*if ( c1 && c2 ) return 0;*/
lixianyu 0:d8f4c441e032 132 return 1;
lixianyu 0:d8f4c441e032 133 }
lixianyu 0:d8f4c441e032 134
lixianyu 0:d8f4c441e032 135 uint8_t u8g_pb_IsIntersection(u8g_pb_t *pb, u8g_dev_arg_bbx_t *bbx)
lixianyu 0:d8f4c441e032 136 {
lixianyu 0:d8f4c441e032 137 u8g_uint_t tmp;
lixianyu 0:d8f4c441e032 138
lixianyu 0:d8f4c441e032 139 tmp = bbx->y;
lixianyu 0:d8f4c441e032 140 tmp += bbx->h;
lixianyu 0:d8f4c441e032 141 tmp--;
lixianyu 0:d8f4c441e032 142
lixianyu 0:d8f4c441e032 143 if ( u8g_pb_IsYIntersection(pb, bbx->y, tmp) == 0 )
lixianyu 0:d8f4c441e032 144 return 0;
lixianyu 0:d8f4c441e032 145
lixianyu 0:d8f4c441e032 146 /* maybe this one can be skiped... probability is very high to have an intersection, so it would be ok to always return 1 */
lixianyu 0:d8f4c441e032 147 tmp = bbx->x;
lixianyu 0:d8f4c441e032 148 tmp += bbx->w;
lixianyu 0:d8f4c441e032 149 tmp--;
lixianyu 0:d8f4c441e032 150
lixianyu 0:d8f4c441e032 151 return u8g_pb_IsXIntersection(pb, bbx->x, tmp);
lixianyu 0:d8f4c441e032 152 }
lixianyu 0:d8f4c441e032 153
lixianyu 0:d8f4c441e032 154 void u8g_pb_GetPageBox(u8g_pb_t *pb, u8g_box_t *box)
lixianyu 0:d8f4c441e032 155 {
lixianyu 0:d8f4c441e032 156 box->x0 = 0;
lixianyu 0:d8f4c441e032 157 box->y0 = pb->p.page_y0;
lixianyu 0:d8f4c441e032 158 box->x1 = pb->width;
lixianyu 0:d8f4c441e032 159 box->x1--;
lixianyu 0:d8f4c441e032 160 box->y1 = pb->p.page_y1;
lixianyu 0:d8f4c441e032 161 }
lixianyu 0:d8f4c441e032 162
lixianyu 0:d8f4c441e032 163
lixianyu 0:d8f4c441e032 164 uint8_t u8g_pb_Is8PixelVisible(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
lixianyu 0:d8f4c441e032 165 {
lixianyu 0:d8f4c441e032 166 u8g_uint_t v0, v1;
lixianyu 0:d8f4c441e032 167 v0 = arg_pixel->y;
lixianyu 0:d8f4c441e032 168 v1 = v0;
lixianyu 0:d8f4c441e032 169 switch( arg_pixel->dir )
lixianyu 0:d8f4c441e032 170 {
lixianyu 0:d8f4c441e032 171 case 0:
lixianyu 0:d8f4c441e032 172 break;
lixianyu 0:d8f4c441e032 173 case 1:
lixianyu 0:d8f4c441e032 174 v1 += 8; /* this is independent from the page height */
lixianyu 0:d8f4c441e032 175 break;
lixianyu 0:d8f4c441e032 176 case 2:
lixianyu 0:d8f4c441e032 177 break;
lixianyu 0:d8f4c441e032 178 case 3:
lixianyu 0:d8f4c441e032 179 v0 -= 8;
lixianyu 0:d8f4c441e032 180 break;
lixianyu 0:d8f4c441e032 181 }
lixianyu 0:d8f4c441e032 182 return u8g_pb_IsYIntersection(b, v0, v1);
lixianyu 0:d8f4c441e032 183 }
lixianyu 0:d8f4c441e032 184
lixianyu 0:d8f4c441e032 185
lixianyu 0:d8f4c441e032 186
lixianyu 0:d8f4c441e032 187 uint8_t u8g_pb_WriteBuffer(u8g_pb_t *b, u8g_t *u8g, u8g_dev_t *dev)
lixianyu 0:d8f4c441e032 188 {
lixianyu 0:d8f4c441e032 189 return u8g_WriteSequence(u8g, dev, b->width, b->buf);
lixianyu 0:d8f4c441e032 190 }
lixianyu 0:d8f4c441e032 191
lixianyu 0:d8f4c441e032 192