iforce2d Chris / Mbed 2 deprecated ubxDistanceMeter

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers u8g_pb8h8.c Source File

u8g_pb8h8.c

00001 /*
00002 
00003   u8g_pb8h8.c
00004   
00005   8 lines per page, horizontal, 8 bits per pixel
00006   (22 May 2013: might also support any number of lines --> needs to be checked)
00007   
00008   Universal 8bit Graphics Library
00009   
00010   Copyright (c) 2012, olikraus@gmail.com
00011   All rights reserved.
00012 
00013   Redistribution and use in source and binary forms, with or without modification, 
00014   are permitted provided that the following conditions are met:
00015 
00016   * Redistributions of source code must retain the above copyright notice, this list 
00017     of conditions and the following disclaimer.
00018     
00019   * Redistributions in binary form must reproduce the above copyright notice, this 
00020     list of conditions and the following disclaimer in the documentation and/or other 
00021     materials provided with the distribution.
00022 
00023   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
00024   CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
00025   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00026   MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
00027   DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
00028   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00029   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
00030   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
00031   LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
00032   CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
00033   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00034   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00035   ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
00036 
00037 
00038 struct _u8g_pb_t
00039 {
00040   u8g_page_t p;
00041   u8g_uint_t width;
00042   void *buf;
00043 };
00044 typedef struct _u8g_pb_t u8g_pb_t;
00045 
00046 
00047 uint8_t u8g_index_color_8h8_buf[WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ; 
00048 u8g_pb_t u8g_index_color_8h8_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0},  WIDTH, u8g_index_color_8h8_buff}; 
00049 u8g_dev_t name = { dev_fn, &u8g_index_color_8h8_pb, com_fn }
00050 
00051 */
00052 
00053 #include "u8g.h"
00054 
00055 /*
00056 #define WIDTH_BITS 7
00057 #define WIDTH (1<<WIDTH_BITS)
00058 #define PAGE_HEIGHT_BITS 3
00059 #define PAGE_HEIGHT (1<<PAGE_HEIGHT_BITS)
00060 */
00061 
00062 void u8g_pb8h8_Clear(u8g_pb_t *b)
00063 {
00064   uint8_t *ptr = (uint8_t *)b->buf;
00065   uint8_t *end_ptr = ptr;
00066   uint8_t cnt = b->p.page_height;
00067   end_ptr += b->width*cnt;
00068   /*
00069   do
00070   {
00071     end_ptr += b->width;
00072     cnt--;
00073   } while( cnt > 0 );
00074   */
00075   do
00076   {
00077     *ptr++ = 0;
00078   } while( ptr != end_ptr );
00079 }
00080 
00081 
00082 void u8g_pb8h8_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
00083 {
00084   b->buf = buf;
00085   b->width = width;
00086   u8g_pb8h8_Clear(b);
00087 }
00088 
00089 static void u8g_pb8h8_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index)
00090 {
00091   uint16_t tmp;
00092   uint8_t *ptr = b->buf;
00093   y -= b->p.page_y0;
00094   tmp = y;
00095   tmp *= b->width;
00096   tmp += x;
00097   ptr += tmp;
00098   *ptr = color_index;
00099 }
00100 
00101 void u8g_pb8h8_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
00102 {
00103   if ( arg_pixel->y < b->p.page_y0 )
00104     return;
00105   if ( arg_pixel->y > b->p.page_y1 )
00106     return;
00107   if ( arg_pixel->x >= b->width )
00108     return;
00109   u8g_pb8h8_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color);
00110 }
00111 
00112 
00113 void u8g_pb8h8_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
00114 {
00115   register uint8_t pixel = arg_pixel->pixel;
00116   u8g_uint_t dx = 0;
00117   u8g_uint_t dy = 0;
00118   
00119   switch( arg_pixel->dir )
00120   {
00121     case 0: dx++; break;
00122     case 1: dy++; break;
00123     case 2: dx--; break;
00124     case 3: dy--; break;
00125   }
00126   
00127   do
00128   {
00129     if ( pixel & 128 )
00130       u8g_pb8h8_SetPixel(b, arg_pixel);
00131     arg_pixel->x += dx;
00132     arg_pixel->y += dy;
00133     pixel <<= 1;
00134   } while( pixel != 0  );  
00135 }
00136 
00137 
00138 uint8_t u8g_dev_pb8h8_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
00139 {
00140   u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
00141   switch(msg)
00142   {
00143     case U8G_DEV_MSG_SET_8PIXEL:
00144       if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
00145         u8g_pb8h8_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg);
00146       break;
00147     case U8G_DEV_MSG_SET_PIXEL:
00148       u8g_pb8h8_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
00149       break;
00150     case U8G_DEV_MSG_INIT:
00151       break;
00152     case U8G_DEV_MSG_STOP:
00153       break;
00154     case U8G_DEV_MSG_PAGE_FIRST:
00155       u8g_pb8h8_Clear(pb);
00156       u8g_page_First(&(pb->p));
00157       break;
00158     case U8G_DEV_MSG_PAGE_NEXT:
00159       if ( u8g_page_Next(&(pb->p)) == 0 )
00160         return 0;
00161       u8g_pb8h8_Clear(pb);
00162       break;
00163 #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
00164     case U8G_DEV_MSG_IS_BBX_INTERSECTION:
00165       return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
00166 #endif
00167     case U8G_DEV_MSG_GET_PAGE_BOX:
00168       u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
00169       break;
00170     case U8G_DEV_MSG_GET_WIDTH:
00171       *((u8g_uint_t *)arg) = pb->width;
00172       break;
00173     case U8G_DEV_MSG_GET_HEIGHT:
00174       *((u8g_uint_t *)arg) = pb->p.total_height;
00175       break;
00176     case U8G_DEV_MSG_SET_COLOR_ENTRY:
00177       break;
00178     case U8G_DEV_MSG_SET_XY_CB:
00179       break;
00180     case U8G_DEV_MSG_GET_MODE:
00181       return U8G_MODE_R3G3B2;
00182   }
00183   return 1;
00184 }
00185 
00186