contentLister/src/cursor.c File Reference

content lister - eReader cursor handling (x,y) --> (y,x) on e-inkt display More...

#include <config.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <gtk/gtk.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <liberdm/display.h>
#include <libermanifest/ermanifest.h>
#include "contentListerLog.h"
#include "displayUpdate.h"
#include "erConnect.h"
#include "system.h"
#include "gtkPincodeScreen.h"
#include "control.h"
#include "cursor.h"
#include "lister.h"

Go to the source code of this file.

Functions

static gboolean cursor_blink (gpointer user_data)
static void cursor_blink_handler_stop (void)
int cursor_init (ContentLister *theContentLister)
int cursor_set_state (const int pos, const cursor_state_t new_state)
void cursor_hide_all (void)
void cursor_redraw ()
void cursor_destroy ()
void start_progress_indicator ()

Variables

static struct display_update_info updateinfo
static ContentListerg_contentLister = NULL
static int g_framebuffer_device = -1
static gboolean g_cursor_needs_update = FALSE
static guint g_cursor_num_blinking = 0
static guint g_cursor_blink_handler = 0
static int g_cursor_x_pos
static int g_cursor_x_pos_alt
static int g_cursor_x_pos_blink
struct {
   int   y_pos
   cursor_state_t   state
cursor_info [MAX_ITEMS_ON_ONE_PAGE]


Detailed Description

content lister - eReader cursor handling (x,y) --> (y,x) on e-inkt display

<File description>="">

Depending on the configure value "cursor-used" the e-reader specific cursor code will be enabled/disabled

Definition in file cursor.c.


Function Documentation

static gboolean cursor_blink ( gpointer  user_data  )  [static]

Definition at line 317 of file cursor.c.

00318 {
00319     int                    rc;
00320     int                    pos;
00321     gboolean               call_me_again = FALSE;
00322     struct brush_draw_info drawinfo;
00323 
00324     CL_CURSORPRINTF("entry");
00325 
00326     if (g_cursor_num_blinking == 0)
00327     {
00328         CL_WARNPRINTF("Stop blink handler, because num_blinking is zero");
00329         g_cursor_blink_handler = 0;
00330         return call_me_again;
00331     }
00332 
00333     // hide old cursors (i.e. paint white)
00334     drawinfo.sourcex  = WHITE_CURSOR_X;
00335     drawinfo.sourcey  = WHITE_CURSOR_Y;
00336     drawinfo.sizex    = WHITE_CURSOR_SIZE_X;
00337     drawinfo.sizey    = WHITE_CURSOR_SIZE_Y;
00338     drawinfo.desty    = SCREEN_WIDTH - g_cursor_x_pos_blink;
00339     drawinfo.brushlsb = WHITE;
00340     for (pos = 0 ; pos < MAX_ITEMS_ON_ONE_PAGE ; pos++)
00341     {
00342         if (cursor_info[pos].state == e_cursor_blink)
00343         {
00344             drawinfo.destx = cursor_info[pos].y_pos;
00345 
00346             // write the brush/drawing to framebuffer (in-memory)
00347             if (display_update_get_level() < NO_DISPLAY_UPDATE_LEVEL)
00348             {
00349                 CL_CURSORPRINTF("FBIO_DRAW_BRUSH location %dx%d color %d", drawinfo.desty, drawinfo.destx, drawinfo.brushlsb);
00350                 rc = ioctl(g_framebuffer_device, FBIO_DRAW_BRUSH_GENERIC, &drawinfo);
00351                 if (rc != 0)
00352                 {
00353                     CL_ERRORPRINTF("Error drawing brush (err=0x%x)", rc);
00354                 }
00355             }
00356         }
00357     }
00358 
00359     // determine new cursor position
00360     if (g_cursor_x_pos_blink == g_cursor_x_pos)
00361     {
00362         g_cursor_x_pos_blink = g_cursor_x_pos_alt;
00363     }
00364     else
00365     {
00366         g_cursor_x_pos_blink = g_cursor_x_pos;
00367     }
00368 
00369     // show new cursors (black)
00370     drawinfo.sourcex  = BLACK_CURSOR_X;
00371     drawinfo.sourcey  = BLACK_CURSOR_Y;
00372     drawinfo.sizex    = BLACK_CURSOR_SIZE_X;
00373     drawinfo.sizey    = BLACK_CURSOR_SIZE_Y;
00374     drawinfo.desty    = SCREEN_WIDTH - g_cursor_x_pos_blink;
00375     drawinfo.brushlsb = BLACK;
00376     for (pos = 0 ; pos < MAX_ITEMS_ON_ONE_PAGE ; pos++)
00377     {
00378         if (cursor_info[pos].state == e_cursor_blink)
00379         {
00380             drawinfo.destx = cursor_info[pos].y_pos;
00381 
00382             // write the brush/drawing to framebuffer (in-memory)
00383             if (display_update_get_level() < NO_DISPLAY_UPDATE_LEVEL)
00384             {
00385                 CL_CURSORPRINTF("FBIO_DRAW_BRUSH location %dx%d color %d", drawinfo.desty, drawinfo.destx, drawinfo.brushlsb);
00386                 rc = ioctl(g_framebuffer_device, FBIO_DRAW_BRUSH_GENERIC, &drawinfo);
00387                 if (rc != 0)
00388                 {
00389                     CL_ERRORPRINTF("Error drawing brush (err=0x%x)", rc);
00390                 }
00391             }
00392         }
00393     }
00394 
00395     // update screen
00396     g_cursor_needs_update = TRUE;
00397     cursor_redraw();
00398     
00399     // trigger next blink
00400     call_me_again = TRUE;
00401     return call_me_again;
00402 }

Here is the call graph for this function:

static void cursor_blink_handler_stop ( void   )  [static]

Definition at line 306 of file cursor.c.

00307 {
00308     CL_CURSORPRINTF("entry: blink_handler [%d]", g_cursor_blink_handler);
00309 
00310     if (g_cursor_blink_handler != 0)
00311     {
00312         g_source_remove(g_cursor_blink_handler);
00313         g_cursor_blink_handler = 0;
00314     }
00315 }

void cursor_destroy (  ) 

Free resources used by cursor

Parameters:
- 
Returns:
-

Definition at line 404 of file cursor.c.

00405 {
00406     close(g_framebuffer_device);
00407 }

void cursor_hide_all ( void   ) 

Hide cursor for all lister items

Parameters:
-- 
Returns:
--

Definition at line 229 of file cursor.c.

00230 {
00231     int                    rc;
00232     int                    pos;
00233     struct brush_draw_info drawinfo;
00234     GtkWidget*             listItem = NULL;
00235 
00236     CL_CURSORPRINTF("entry");
00237 
00238     // stop blink handler
00239     cursor_blink_handler_stop();
00240     g_cursor_num_blinking = 0;
00241     g_cursor_x_pos_blink  = g_cursor_x_pos;
00242 
00243     // hide all cursors (i.e. paint white)
00244     drawinfo.sourcex  = WHITE_CURSOR_X;
00245     drawinfo.sourcey  = WHITE_CURSOR_Y;
00246     drawinfo.sizex    = WHITE_CURSOR_SIZE_X;
00247     drawinfo.sizey    = WHITE_CURSOR_SIZE_Y;
00248     drawinfo.brushlsb = WHITE;
00249     for (pos = 0 ; pos < MAX_ITEMS_ON_ONE_PAGE ; pos++)
00250     {
00251         drawinfo.destx = cursor_info[pos].y_pos;
00252 
00253         cursor_info[pos].state = e_cursor_hide;
00254         
00255         // hide gtk cursor
00256         listItem  = lsGetListerItem(g_contentLister->lister, pos);
00257         gtk_content_list_item_show_cursor(GTK_CONTENT_LIST_ITEM(listItem), FALSE);
00258 
00259         // write the brush/drawing for standard location to framebuffer (in-memory)
00260         drawinfo.desty = SCREEN_WIDTH - g_cursor_x_pos;
00261         if (display_update_get_level() < NO_DISPLAY_UPDATE_LEVEL)
00262         {
00263             CL_CURSORPRINTF("FBIO_DRAW_BRUSH location %dx%d color %d", drawinfo.desty, drawinfo.destx, drawinfo.brushlsb);
00264             rc = ioctl(g_framebuffer_device, FBIO_DRAW_BRUSH_GENERIC, &drawinfo);
00265             if (rc != 0)
00266             {
00267                 CL_ERRORPRINTF("Error drawing brush (err=0x%x)", rc);
00268             }
00269         }
00270         
00271         // write the brush/drawing for alternative location to framebuffer (in-memory)
00272         drawinfo.desty = SCREEN_WIDTH - g_cursor_x_pos_alt;
00273         if (display_update_get_level() < NO_DISPLAY_UPDATE_LEVEL)
00274         {
00275             CL_CURSORPRINTF("FBIO_DRAW_BRUSH location %dx%d color %d", drawinfo.desty, drawinfo.destx, drawinfo.brushlsb);
00276             rc = ioctl(g_framebuffer_device, FBIO_DRAW_BRUSH_GENERIC, &drawinfo);
00277             if (rc != 0)
00278             {
00279                 CL_ERRORPRINTF("Error drawing brush (err=0x%x)", rc);
00280             }
00281         }
00282         g_cursor_needs_update = TRUE;
00283     }
00284 }

Here is the call graph for this function:

int cursor_init ( ContentLister theContentLister  ) 

Load bitmap, open framebuffer_device, init values...

Returns:
0/-1 = ok/failure

Definition at line 89 of file cursor.c.

00090 {
00091     int i;
00092 
00093     g_contentLister = theContentLister;
00094 
00095     // open framebuffer device
00096     g_framebuffer_device = open("/dev/fb0", O_RDWR);
00097     if (g_framebuffer_device == -1)
00098     {
00099         CL_ERRORPRINTF("Error opening framebufferdevice. # mknod /dev/fb0 c 29 0");
00100         return -1;  // -1 = error
00101     }
00102 
00103     // determine X coordinate
00104     g_cursor_x_pos     = CURSOR_X;
00105     g_cursor_x_pos_alt = g_cursor_x_pos - BLACK_CURSOR_SIZE_Y;
00106     if (g_cursor_x_pos_alt < BLACK_CURSOR_SIZE_Y + 3)
00107     {
00108         g_cursor_x_pos_alt = BLACK_CURSOR_SIZE_Y + 3;
00109     }
00110     g_cursor_x_pos_blink = g_cursor_x_pos;
00111 
00112     // determine Y coordinate
00113     for (i = 0 ; i < MAX_ITEMS_ON_ONE_PAGE ; i++)
00114     {
00115         cursor_info[i].y_pos = CURSOR_START_Y + i * CURSOR_STEP;
00116         cursor_info[i].state = e_cursor_hide;
00117     }
00118 
00119     // set waveform parameters
00120     updateinfo.waveform = WAVEFORM_FAST_BLACK_WHITE;
00121     updateinfo.sequence = 0;
00122     
00123     return 0;  // 0 = ok
00124 }

void cursor_redraw ( void   ) 

Redraw cursur, when needed

Parameters:
-- 
Returns:
--

Definition at line 286 of file cursor.c.

00287 {
00288     CL_CURSORPRINTF("entry");
00289 
00290     int  rc;
00291 
00292     if (   g_cursor_needs_update
00293         && display_update_get_level() < NO_DISPLAY_UPDATE_LEVEL )
00294     {
00295         // display the modification on screen
00296         CL_CURSORPRINTF("FBIO_REDRAW waveform %d - sequence %d", updateinfo.waveform, updateinfo.sequence);
00297         rc = ioctl(g_framebuffer_device, FBIO_REDRAW, &updateinfo);
00298         if (rc != 0)
00299         {
00300             CL_ERRORPRINTF("Error sending FBIO_REDRAW: %x", rc);
00301         }
00302         g_cursor_needs_update = FALSE;
00303     }
00304 }

Here is the call graph for this function:

int cursor_set_state ( const int  pos,
const cursor_state_t  state 
)

Show/hide/blink cursor at lister-item position

Parameters:
pos - index of lister item (0 ..)
state - new state of cursor
Returns:
0/-1 = ok/failure

Definition at line 130 of file cursor.c.

00131 {
00132     int retVal = 0;  // 0 = ok
00133 
00134     if (pos == -1)
00135     {
00136         return 0;  // 0 = ok
00137     }
00138     CL_CURSORPRINTF("entry: pos [%d] new_state [%d]", pos, new_state);
00139     g_return_val_if_fail((pos >= 0  &&  pos < MAX_ITEMS_ON_ONE_PAGE), -1);
00140 
00141     int                    rc;
00142     struct brush_draw_info drawinfo;
00143     cursor_state_t         old_state = cursor_info[pos].state;
00144     GtkWidget*             listItem  = lsGetListerItem(g_contentLister->lister, pos);
00145 
00146     if (new_state == e_cursor_hide)
00147     {
00148         gtk_content_list_item_show_cursor(GTK_CONTENT_LIST_ITEM(listItem), FALSE);
00149 
00150         // remove cursor (i.e. paint white)
00151         drawinfo.sourcex  = WHITE_CURSOR_X;
00152         drawinfo.sourcey  = WHITE_CURSOR_Y;
00153         drawinfo.sizex    = WHITE_CURSOR_SIZE_X;
00154         drawinfo.sizey    = WHITE_CURSOR_SIZE_Y;
00155         drawinfo.destx    = cursor_info[pos].y_pos;
00156         drawinfo.desty    = SCREEN_WIDTH - ((old_state == e_cursor_blink) ? g_cursor_x_pos_blink : g_cursor_x_pos);
00157         drawinfo.brushlsb = WHITE;
00158     }
00159     else
00160     {
00161         gtk_content_list_item_show_cursor(GTK_CONTENT_LIST_ITEM(listItem), TRUE);
00162 
00163         // show cursor (black)
00164         drawinfo.sourcex  = BLACK_CURSOR_X;
00165         drawinfo.sourcey  = BLACK_CURSOR_Y;
00166         drawinfo.sizex    = BLACK_CURSOR_SIZE_X;
00167         drawinfo.sizey    = BLACK_CURSOR_SIZE_Y;
00168         drawinfo.destx    = cursor_info[pos].y_pos;
00169         drawinfo.desty    = SCREEN_WIDTH - ((new_state == e_cursor_blink) ? g_cursor_x_pos_blink : g_cursor_x_pos);
00170         drawinfo.brushlsb = BLACK;
00171     }
00172     cursor_info[pos].state = new_state;
00173 
00174     // write the brush/drawing to framebuffer (in-memory)
00175     if (display_update_get_level() < NO_DISPLAY_UPDATE_LEVEL)
00176     {
00177         CL_CURSORPRINTF("FBIO_DRAW_BRUSH location %dx%d color %d", drawinfo.desty, drawinfo.destx, drawinfo.brushlsb);
00178         rc = ioctl(g_framebuffer_device, FBIO_DRAW_BRUSH_GENERIC, &drawinfo);
00179         if (rc != 0)
00180         {
00181             CL_ERRORPRINTF("Error drawing brush (err=0x%x)", rc);
00182             retVal = -1;  // -1 = error
00183         }
00184     }
00185 
00186     // set blinking parameters
00187     //   adjust number of blinking cursors
00188     if (old_state == e_cursor_blink  &&  g_cursor_num_blinking > 0)
00189     {
00190         g_cursor_num_blinking--;
00191     }
00192     if (new_state == e_cursor_blink)
00193     {
00194         g_cursor_num_blinking++;
00195     }
00196     g_cursor_num_blinking = g_cursor_num_blinking;
00197     //   start/stop blink timeout handler
00198     if (g_cursor_num_blinking == 0)
00199     {
00200         if (g_cursor_blink_handler != 0)
00201         {
00202             cursor_blink_handler_stop();
00203             g_cursor_x_pos_blink = g_cursor_x_pos;
00204         }
00205     }
00206     else
00207     {
00208         if (g_cursor_blink_handler == 0)
00209         {
00210             g_cursor_blink_handler = g_timeout_add(800, cursor_blink, NULL);
00211         }
00212     }
00213 
00214     // screen update needed except when blink
00215     if (   (new_state == e_cursor_blink  &&  g_cursor_num_blinking > 1)
00216         || (old_state == e_cursor_blink  &&  g_cursor_num_blinking > 0) )
00217     {
00218         // wait for next blink timer to do screen update
00219     }
00220     else
00221     {
00222         // do screen update now
00223         g_cursor_needs_update = TRUE;
00224     }
00225 
00226     return retVal;
00227 }

Here is the call graph for this function:

void start_progress_indicator ( void   ) 

Start progress indicator (knight rider)

Parameters:
- 
Returns:
-

Definition at line 409 of file cursor.c.

00410 {
00411     int framebuffer_device;
00412 
00413     // start the timer now, the viewer has been launched
00414     if (display_update_get_level() < NO_DISPLAY_UPDATE_LEVEL)
00415     {
00416         framebuffer_device = open("/dev/fb0", O_RDWR);    
00417         if ((ioctl(framebuffer_device, FBIO_START_PROGRESS_BAR)) != 0)
00418         {
00419             CL_ERRORPRINTF("einkfb IOCTL failed");
00420         }
00421         close(framebuffer_device);
00422     }
00423 }

Here is the call graph for this function:


Variable Documentation

struct { ... } cursor_info[MAX_ITEMS_ON_ONE_PAGE] [static]

ContentLister* g_contentLister = NULL [static]

Definition at line 62 of file cursor.c.

guint g_cursor_blink_handler = 0 [static]

Definition at line 68 of file cursor.c.

gboolean g_cursor_needs_update = FALSE [static]

Definition at line 65 of file cursor.c.

guint g_cursor_num_blinking = 0 [static]

Definition at line 67 of file cursor.c.

int g_cursor_x_pos [static]

Definition at line 70 of file cursor.c.

int g_cursor_x_pos_alt [static]

Definition at line 71 of file cursor.c.

int g_cursor_x_pos_blink [static]

Definition at line 72 of file cursor.c.

int g_framebuffer_device = -1 [static]

Definition at line 64 of file cursor.c.

Definition at line 77 of file cursor.c.

Definition at line 60 of file cursor.c.

int y_pos

Definition at line 76 of file cursor.c.


Generated on Sun Dec 14 17:13:21 2008 by  doxygen 1.5.6