driver.c File Reference

#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include "driver.h"
#include "scblog.h"
Include dependency graph for driver.c:

Go to the source code of this file.

Defines

#define DMPORT   50555
#define DMSERVER   "127.0.0.1"
#define FRAMEBUFFER_DEVICE   "/dev/fb0"

Functions

void erscribble_driver_init ()
void erscribble_driver_close ()
void erscribble_driver_draw_points (DrvPointsBufPtr ptr)
void erscribble_driver_draw_reset_context ()
gboolean erscribble_driver_draw_now ()
void erscribble_driver_draw_record (const ScbDevPointPtr ptr, const unsigned char size, const unsigned char color, const unsigned char pen_down)
void erscribble_driver_draw ()
void erscribble_driver_update_display ()

Variables

static int fd = 0
static FastDrawContext s_driver_draw_ctx
static struct sockaddr_in server_addr

Define Documentation

#define DMPORT   50555

Copyright (C) 2008 iRex Technologies B.V. All rights reserved.

Definition at line 61 of file driver.c.

Referenced by erscribble_driver_init(), gtk_messages(), init_socket(), and main().

#define DMSERVER   "127.0.0.1"

Definition at line 62 of file driver.c.

Referenced by erscribble_driver_init(), init_socket(), and main().

#define FRAMEBUFFER_DEVICE   "/dev/fb0"

Definition at line 64 of file driver.c.

Referenced by erscribble_driver_init().


Function Documentation

void erscribble_driver_close (  ) 

Definition at line 121 of file driver.c.

References fd.

Referenced by erscribble_uninit().

00122 {
00123     // close display manager socket
00124     close(fd);
00125     fd = 0;
00126 
00127 #ifdef ENABLE_DRIVER
00128     // close frame buffer
00129     close(fbdev);
00130     fbdev = 0;
00131 #endif
00132 }

Here is the caller graph for this function:

void erscribble_driver_draw (  ) 

Definition at line 214 of file driver.c.

References erscribble_driver_draw_points(), and _FastDrawContext::points.

Referenced by erscribble_stroke_driver_draw_point().

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean erscribble_driver_draw_now (  ) 

Definition at line 161 of file driver.c.

References _DrvPointsBuf::count, ERSCRIBBLE_DEF_DRIVER_DRAW_COUNT, ERSCRIBBLE_DEF_DRIVER_DRAW_TIME, LOGPRINTF, and _FastDrawContext::points.

Referenced by erscribble_stroke_driver_draw_point().

00162 {
00163 #ifdef ENABLE_DRIVER
00164     // check points 
00165     if (s_driver_draw_ctx.points.count > ERSCRIBBLE_DEF_DRIVER_DRAW_COUNT)
00166     {
00167         //LOGPRINTF("Should draw now points!");
00168         return TRUE;
00169     }
00170 
00171     // check time
00172     static const long usec = 1000 * 1000;
00173     long elapsed = ( s_driver_draw_ctx.t2.tv_sec - s_driver_draw_ctx.t1.tv_sec ) * usec;
00174     elapsed += s_driver_draw_ctx.t2.tv_usec - s_driver_draw_ctx.t1.tv_usec;
00175 
00176     if (elapsed >= ERSCRIBBLE_DEF_DRIVER_DRAW_TIME)
00177     {
00178         LOGPRINTF("Should draw now time!");
00179         return TRUE;
00180     }
00181     
00182     LOGPRINTF("No, not yet. Waiting for...");
00183     return FALSE;
00184 
00185 #else
00186 
00187     return TRUE;
00188 
00189 #endif
00190 }

Here is the caller graph for this function:

void erscribble_driver_draw_points ( DrvPointsBufPtr  ptr  ) 

Definition at line 135 of file driver.c.

References ERRORPRINTF, and FBIO_DELTA_DRAWMODE_PIXELS.

Referenced by erscribble_driver_draw(), and erscribble_stroke_driver_draw().

00136 {
00137 #ifdef ENABLE_DRIVER
00138     if (ptr)
00139     {   
00140         if (ioctl (fbdev, FBIO_DELTA_DRAWMODE_PIXELS, ptr) != 0)
00141         {
00142             ERRORPRINTF("ioctl request error!");
00143         }
00144     }
00145 #endif
00146 }

Here is the caller graph for this function:

void erscribble_driver_draw_record ( const ScbDevPointPtr  ptr,
const unsigned char  size,
const unsigned char  color,
const unsigned char  pen_down 
)

Definition at line 193 of file driver.c.

References _DrvPointsBuf::count, ERSCRIBBLE_DEF_DRIVER_DRAW_BUF_LEN, _ScbDevPoint::point, _DrvPointsBuf::points, _FastDrawContext::points, _ScbPoint::x, and _ScbPoint::y.

Referenced by erscribble_stroke_driver_draw_point().

00197 {
00198 #ifdef ENABLE_DRIVER
00199     // make a check
00200     if (s_driver_draw_ctx.points.count <  ERSCRIBBLE_DEF_DRIVER_DRAW_BUF_LEN && ptr)
00201     {
00202         s_driver_draw_ctx.points.points[s_driver_draw_ctx.points.count].x = ptr->point.x;
00203         s_driver_draw_ctx.points.points[s_driver_draw_ctx.points.count].y = ptr->point.y;
00204         s_driver_draw_ctx.points.points[s_driver_draw_ctx.points.count].size = size;
00205         s_driver_draw_ctx.points.points[s_driver_draw_ctx.points.count].color = color;
00206         s_driver_draw_ctx.points.points[s_driver_draw_ctx.points.count].pen_down = pen_down;
00207         ++s_driver_draw_ctx.points.count;
00208         gettimeofday(&s_driver_draw_ctx.t2, NULL);
00209     }
00210 #endif
00211 }

Here is the caller graph for this function:

void erscribble_driver_draw_reset_context (  ) 

Definition at line 150 of file driver.c.

References _DrvPointsBuf::count, and _FastDrawContext::points.

Referenced by erscribble_stroke_driver_draw_point(), erscribble_stroke_new(), and erscribble_stroke_new_with_attributes().

00151 {
00152 #ifdef ENABLE_DRIVER
00153     s_driver_draw_ctx.points.count = 0;
00154     gettimeofday(&s_driver_draw_ctx.t1, NULL);
00155     s_driver_draw_ctx.t2.tv_sec   = s_driver_draw_ctx.t1.tv_sec;
00156     s_driver_draw_ctx.t2.tv_usec  = s_driver_draw_ctx.t1.tv_usec;
00157 #endif
00158 }

Here is the caller graph for this function:

void erscribble_driver_init (  ) 

Definition at line 88 of file driver.c.

References DMPORT, DMSERVER, ERRORPRINTF, fd, FRAMEBUFFER_DEVICE, and server_addr.

Referenced by erscribble_init().

00089 {
00090     // create and bind display manager socket
00091     fd = socket(PF_INET, SOCK_DGRAM, 0);
00092     if (-1 == fd)
00093     {
00094         ERRORPRINTF("Could not open port %d at %s, errno %d (%s)", DMPORT, DMSERVER, errno, strerror(errno));
00095         fd = 0;
00096         return;
00097     }
00098     memset(&server_addr, '\0', sizeof(struct sockaddr_in));
00099     server_addr.sin_family = AF_INET;
00100     server_addr.sin_port = htons(DMPORT);
00101     server_addr.sin_addr.s_addr = inet_addr(DMSERVER);
00102     
00103 #ifdef ENABLE_DRIVER
00104     if (fbdev != 0)
00105     {
00106         ERRORPRINTF(FRAMEBUFFER_DEVICE " already open!");
00107         return;
00108     }
00109 
00110     fbdev = open(FRAMEBUFFER_DEVICE, O_RDWR);
00111     if (-1 == fbdev)
00112     {
00113         ERRORPRINTF("Could not open " FRAMEBUFFER_DEVICE "!");
00114         fbdev = 0;
00115         return;
00116     }
00117 #endif
00118 }

Here is the caller graph for this function:

void erscribble_driver_update_display (  ) 

Definition at line 220 of file driver.c.

References fd, LOGPRINTF, msg, and server_addr.

00221 {
00222     // Send update message to display manager
00223     //
00224     //   Syntax: !I,cmd,pid,x,y,w,h,ignore,window,type,widget,focus
00225     //   - paint full screen (w=768,h=1024)
00226     //   - skip the normal rules (ignore=1)
00227     //   - special widget (widget=erscribble)
00228     //   - rest unused (0)
00229     const char *msg = "!I,0,0,0,768,1024,1,0,0,erscribble,0\n";
00230     sendto(fd, msg, strlen(msg), 0, (struct sockaddr*) &server_addr, sizeof(server_addr));
00231     LOGPRINTF("Sent message `%s` to display manager", msg);
00232 }


Variable Documentation

int fd = 0 [static]

Definition at line 75 of file driver.c.

struct sockaddr_in server_addr [static]

Definition at line 76 of file driver.c.

Referenced by erscribble_driver_init(), and erscribble_driver_update_display().

Generated by  doxygen 1.6.2-20100208