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_line.c
lixianyu 0:d8f4c441e032 4
lixianyu 0:d8f4c441e032 5 Universal 8bit Graphics Library
lixianyu 0:d8f4c441e032 6
lixianyu 0:d8f4c441e032 7 Copyright (c) 2012, olikraus@gmail.com
lixianyu 0:d8f4c441e032 8 All rights reserved.
lixianyu 0:d8f4c441e032 9
lixianyu 0:d8f4c441e032 10 Redistribution and use in source and binary forms, with or without modification,
lixianyu 0:d8f4c441e032 11 are permitted provided that the following conditions are met:
lixianyu 0:d8f4c441e032 12
lixianyu 0:d8f4c441e032 13 * Redistributions of source code must retain the above copyright notice, this list
lixianyu 0:d8f4c441e032 14 of conditions and the following disclaimer.
lixianyu 0:d8f4c441e032 15
lixianyu 0:d8f4c441e032 16 * Redistributions in binary form must reproduce the above copyright notice, this
lixianyu 0:d8f4c441e032 17 list of conditions and the following disclaimer in the documentation and/or other
lixianyu 0:d8f4c441e032 18 materials provided with the distribution.
lixianyu 0:d8f4c441e032 19
lixianyu 0:d8f4c441e032 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
lixianyu 0:d8f4c441e032 21 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
lixianyu 0:d8f4c441e032 22 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
lixianyu 0:d8f4c441e032 23 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
lixianyu 0:d8f4c441e032 24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
lixianyu 0:d8f4c441e032 25 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
lixianyu 0:d8f4c441e032 26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
lixianyu 0:d8f4c441e032 27 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
lixianyu 0:d8f4c441e032 28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
lixianyu 0:d8f4c441e032 29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
lixianyu 0:d8f4c441e032 30 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
lixianyu 0:d8f4c441e032 31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
lixianyu 0:d8f4c441e032 32 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
lixianyu 0:d8f4c441e032 33
lixianyu 0:d8f4c441e032 34 */
lixianyu 0:d8f4c441e032 35
lixianyu 0:d8f4c441e032 36 #include "u8g.h"
lixianyu 0:d8f4c441e032 37
lixianyu 0:d8f4c441e032 38 void u8g_DrawLine(u8g_t *u8g, u8g_uint_t x1, u8g_uint_t y1, u8g_uint_t x2, u8g_uint_t y2)
lixianyu 0:d8f4c441e032 39 {
lixianyu 0:d8f4c441e032 40 u8g_uint_t tmp;
lixianyu 0:d8f4c441e032 41 u8g_uint_t x,y;
lixianyu 0:d8f4c441e032 42 u8g_uint_t dx, dy;
lixianyu 0:d8f4c441e032 43 u8g_int_t err;
lixianyu 0:d8f4c441e032 44 u8g_int_t ystep;
lixianyu 0:d8f4c441e032 45
lixianyu 0:d8f4c441e032 46 uint8_t swapxy = 0;
lixianyu 0:d8f4c441e032 47
lixianyu 0:d8f4c441e032 48 /* no BBX intersection check at the moment, should be added... */
lixianyu 0:d8f4c441e032 49
lixianyu 0:d8f4c441e032 50 if ( x1 > x2 ) dx = x1-x2; else dx = x2-x1;
lixianyu 0:d8f4c441e032 51 if ( y1 > y2 ) dy = y1-y2; else dy = y2-y1;
lixianyu 0:d8f4c441e032 52
lixianyu 0:d8f4c441e032 53 if ( dy > dx )
lixianyu 0:d8f4c441e032 54 {
lixianyu 0:d8f4c441e032 55 swapxy = 1;
lixianyu 0:d8f4c441e032 56 tmp = dx; dx =dy; dy = tmp;
lixianyu 0:d8f4c441e032 57 tmp = x1; x1 =y1; y1 = tmp;
lixianyu 0:d8f4c441e032 58 tmp = x2; x2 =y2; y2 = tmp;
lixianyu 0:d8f4c441e032 59 }
lixianyu 0:d8f4c441e032 60 if ( x1 > x2 )
lixianyu 0:d8f4c441e032 61 {
lixianyu 0:d8f4c441e032 62 tmp = x1; x1 =x2; x2 = tmp;
lixianyu 0:d8f4c441e032 63 tmp = y1; y1 =y2; y2 = tmp;
lixianyu 0:d8f4c441e032 64 }
lixianyu 0:d8f4c441e032 65 err = dx >> 1;
lixianyu 0:d8f4c441e032 66 if ( y2 > y1 ) ystep = 1; else ystep = -1;
lixianyu 0:d8f4c441e032 67 y = y1;
lixianyu 0:d8f4c441e032 68
lixianyu 0:d8f4c441e032 69 #ifndef U8G_16BIT
lixianyu 0:d8f4c441e032 70 if ( x2 == 255 )
lixianyu 0:d8f4c441e032 71 x2--;
lixianyu 0:d8f4c441e032 72 #else
lixianyu 0:d8f4c441e032 73 if ( x2 == 0xffff )
lixianyu 0:d8f4c441e032 74 x2--;
lixianyu 0:d8f4c441e032 75 #endif
lixianyu 0:d8f4c441e032 76
lixianyu 0:d8f4c441e032 77 for( x = x1; x <= x2; x++ )
lixianyu 0:d8f4c441e032 78 {
lixianyu 0:d8f4c441e032 79 if ( swapxy == 0 )
lixianyu 0:d8f4c441e032 80 u8g_DrawPixel(u8g, x, y);
lixianyu 0:d8f4c441e032 81 else
lixianyu 0:d8f4c441e032 82 u8g_DrawPixel(u8g, y, x);
lixianyu 0:d8f4c441e032 83 err -= (uint8_t)dy;
lixianyu 0:d8f4c441e032 84 if ( err < 0 )
lixianyu 0:d8f4c441e032 85 {
lixianyu 0:d8f4c441e032 86 y += (u8g_uint_t)ystep;
lixianyu 0:d8f4c441e032 87 err += (u8g_uint_t)dx;
lixianyu 0:d8f4c441e032 88 }
lixianyu 0:d8f4c441e032 89 }
lixianyu 0:d8f4c441e032 90 }
lixianyu 0:d8f4c441e032 91