wacom.c File Reference

#include <glib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <string.h>
#include "log.h"
#include "system.h"
#include "wacom.h"
Include dependency graph for wacom.c:

Go to the source code of this file.

Data Structures

struct  command

Defines

#define NUM_COMMANDS   8
#define DEV_WACOM   "/dev/ttymxc1"

Functions

static gboolean send_command (char *name)
static gint port_open (char *name)
static void set_defaults (void)
void wacom_scan_high ()
 Set Wacom tablet scanning to high accuracy, increasing power usage.
void wacom_scan_normal ()
 Normal Wacom tablet scanning, descreasing accuracy and preserving power.
void wacom_suspend ()
 Suspend Wacom tablet, wakes up when pen detected.
void wacom_resume ()
 Enable Wacom tablet, return to normal scanning.
void wacom_tilt_correction_enable (gboolean tilt_enable)
 Enable/Disable Hardware Tilt Correction algorithm.
void wacom_enable ()
 Enable Wacom tablet.
void wacom_disable ()
 Disable Wacom tablet. No scanning at all.
void wacom_reset ()
 Reset Wacom tablet by toggling hardware reset line.
gboolean wacom_is_enabled ()
 Query if Wacom tablet is enabled.

Variables

static command commands []
static gboolean g_wacom_enabled = FALSE

Define Documentation

#define DEV_WACOM   "/dev/ttymxc1"

Definition at line 61 of file wacom.c.

Referenced by send_command().

#define NUM_COMMANDS   8

Definition at line 60 of file wacom.c.

Referenced by send_command().


Function Documentation

static gint port_open ( char *  name  )  [static]

Definition at line 254 of file wacom.c.

References ERRORPRINTF, fd, and LOGPRINTF.

00255 {
00256     LOGPRINTF("entry");
00257     
00258     g_return_val_if_fail(name != NULL, FALSE);
00259     
00260     gint fd;
00261     struct termios t;
00262     
00263     if ((fd = open(name, O_RDWR | O_NOCTTY)) < 0)
00264     {
00265         ERRORPRINTF("Can't open device %s\n", name);
00266         return FALSE;
00267     }
00268 
00269     tcgetattr(fd, &t);
00270 
00271     t.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
00272     t.c_oflag &= ~OPOST;
00273     t.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
00274     t.c_cflag &= ~(CSIZE|PARENB);
00275     t.c_cflag |= CS8|CLOCAL;
00276     t.c_cflag &= ~(CSTOPB);     // 1 stop bit 
00277     t.c_cflag &= ~(CSIZE);      // 8 data bits 
00278     t.c_cflag |= CS8;
00279     t.c_cflag &= ~(PARENB);     // no parity 
00280     t.c_iflag |= IXOFF;         // flow control XOff 
00281     t.c_cc[VMIN] = 0;           // vmin value 
00282     t.c_cc[VTIME] = 10;         // vtime value 
00283 
00284     cfsetispeed(&t, B19200);
00285     cfsetospeed(&t, B19200);
00286     tcflush(fd, TCIFLUSH);
00287     tcsetattr(fd, TCSANOW, &t);
00288     
00289     return fd;
00290 }

static gboolean send_command ( char *  name  )  [static]

Definition at line 217 of file wacom.c.

References DEV_WACOM, ERRORPRINTF, fd, LOGPRINTF, NUM_COMMANDS, and port_open().

Referenced by wacom_scan_high(), wacom_scan_normal(), and wacom_tilt_correction_enable().

00218 {
00219     LOGPRINTF("entry");
00220 
00221     g_return_val_if_fail(name != NULL, FALSE);
00222 
00223     gboolean retval = FALSE;
00224     gint fd = 0;
00225     gint num = 0;
00226 
00227     fd = port_open(DEV_WACOM);
00228     if (fd > 0)
00229     {
00230         gint i;
00231         for (i=0; i<NUM_COMMANDS; i++)
00232         {
00233             if (strcmp(name, commands[i].uname)==0)
00234             {
00235                 LOGPRINTF("sending command %s, %s", commands[i].uname, commands[i].help);
00236 
00237                 num = write(fd,commands[i].cmd, strlen(commands[i].cmd));
00238                 LOGPRINTF("- bytes sent %d (%s)", num, commands[i].cmd);
00239                 if (num < 0)
00240                 {
00241                     ERRORPRINTF("- error sending: %d (%s)", errno, strerror(errno));
00242                 }
00243                     
00244                 retval = TRUE;
00245             }
00246         }
00247         close(fd);
00248     }
00249     
00250     return retval;
00251 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_defaults ( void   )  [static]

Definition at line 210 of file wacom.c.

References wacom_scan_high(), and wacom_tilt_correction_enable().

Referenced by wacom_enable(), and wacom_reset().

00211 {
00212     wacom_scan_high();
00213     wacom_tilt_correction_enable(FALSE);
00214 }

Here is the call graph for this function:

Here is the caller graph for this function:

void wacom_disable ( void   ) 

Disable Wacom tablet. No scanning at all.

---------------------------------------------------------------------------

Name : wacom_disable

Parameters:
-- 
Returns:
--

--------------------------------------------------------------------------

Definition at line 181 of file wacom.c.

References g_wacom_enabled, LOGPRINTF, and sys_set_power().

Referenced by cb_sys_set_stylus(), event_gconf_value_changed(), set_startup_defaults(), and start_demo_mode().

00182 {
00183     LOGPRINTF("entry");
00184     
00185     sys_set_power("wacom", 0);
00186     g_wacom_enabled = FALSE;
00187 }

Here is the call graph for this function:

Here is the caller graph for this function:

void wacom_enable ( void   ) 

Enable Wacom tablet.

---------------------------------------------------------------------------

Name : wacom_enable

Parameters:
-- 
Returns:
--

--------------------------------------------------------------------------

Definition at line 171 of file wacom.c.

References g_wacom_enabled, LOGPRINTF, set_defaults(), and sys_set_power().

Referenced by cb_sys_set_stylus(), event_gconf_value_changed(), set_startup_defaults(), and stop_demo_mode().

00172 {
00173     LOGPRINTF("entry");
00174     
00175     g_wacom_enabled = TRUE;
00176     sys_set_power("wacom", 1);
00177     set_defaults();
00178 }

Here is the call graph for this function:

Here is the caller graph for this function:

gboolean wacom_is_enabled ( void   ) 

Query if Wacom tablet is enabled.

---------------------------------------------------------------------------

Name : wacom_is_enabled

Parameters:
-- 
Returns:
TRUE when Wacom tablet is enabled, FALSE otherwise

--------------------------------------------------------------------------

Definition at line 200 of file wacom.c.

References g_wacom_enabled.

Referenced by cb_sys_get_stylus(), and do_idle().

00201 {
00202     return g_wacom_enabled;
00203 }

Here is the caller graph for this function:

void wacom_reset (  ) 

Reset Wacom tablet by toggling hardware reset line.

---------------------------------------------------------------------------

Name : wacom_reset

Parameters:
-- 
Returns:
--

--------------------------------------------------------------------------

Definition at line 190 of file wacom.c.

References g_wacom_enabled, LOGPRINTF, set_defaults(), and sys_set_power().

Referenced by do_idle().

00191 {
00192     LOGPRINTF("entry");
00193     
00194     g_wacom_enabled = TRUE;
00195     sys_set_power("wacom_reset", 1);
00196     set_defaults();
00197 }

Here is the call graph for this function:

Here is the caller graph for this function:

void wacom_resume ( void   ) 

Enable Wacom tablet, return to normal scanning.

---------------------------------------------------------------------------

Name : wacom_resume

Parameters:
-- 
Returns:
--

--------------------------------------------------------------------------

Definition at line 139 of file wacom.c.

References g_wacom_enabled, LOGPRINTF, and WARNPRINTF.

Referenced by cb_sys_set_stylus(), do_idle(), wacom_scan_high(), and wacom_scan_normal().

00140 {
00141     LOGPRINTF("entry");
00142     if (g_wacom_enabled)
00143     {
00144         // since the wacom switches to writing mode (133pps) automatically, don't do anything
00145     }
00146     else
00147     {
00148         WARNPRINTF("wacom is disabled, mode not changed");
00149     }
00150 }

Here is the caller graph for this function:

void wacom_scan_high ( void   ) 

Set Wacom tablet scanning to high accuracy, increasing power usage.

File Name : wacom.h

Description: Wacom tables functions Copyright (C) 2008 iRex Technologies B.V. All rights reserved.---------------------------------------------------------------------------

Name : wacom_scan_high

Parameters:
-- 
Returns:
--

--------------------------------------------------------------------------

Definition at line 95 of file wacom.c.

References g_wacom_enabled, LOGPRINTF, send_command(), wacom_resume(), and WARNPRINTF.

Referenced by cb_sys_set_stylus(), and set_defaults().

00096 {
00097     LOGPRINTF("entry");
00098     if (g_wacom_enabled)
00099     {
00100         wacom_resume();
00101         send_command("sample-133");
00102     }
00103     else
00104     {
00105         WARNPRINTF("wacom is disabled, mode not changed");
00106     }
00107 }

Here is the call graph for this function:

Here is the caller graph for this function:

void wacom_scan_normal ( void   ) 

Normal Wacom tablet scanning, descreasing accuracy and preserving power.

---------------------------------------------------------------------------

Name : wacom_scan_normal

Parameters:
-- 
Returns:
--

--------------------------------------------------------------------------

Definition at line 110 of file wacom.c.

References g_wacom_enabled, LOGPRINTF, send_command(), wacom_resume(), and WARNPRINTF.

Referenced by cb_sys_set_stylus().

00111 {
00112     LOGPRINTF("entry");
00113     if (g_wacom_enabled)
00114     {
00115         wacom_resume();
00116         send_command("sample-80");
00117     }
00118     else
00119     {
00120         WARNPRINTF("wacom is disabled, mode not changed");
00121     }
00122 }

Here is the call graph for this function:

Here is the caller graph for this function:

void wacom_suspend ( void   ) 

Suspend Wacom tablet, wakes up when pen detected.

---------------------------------------------------------------------------

Name : wacom_suspend

Parameters:
-- 
Returns:
--

--------------------------------------------------------------------------

Definition at line 125 of file wacom.c.

References g_wacom_enabled, LOGPRINTF, and WARNPRINTF.

Referenced by cb_sys_set_stylus(), and do_idle().

00126 {
00127     LOGPRINTF("entry");
00128     if (g_wacom_enabled)
00129     {
00130         // since the wacom switches to normal mode (8pps) automatically, don't do anything
00131     }
00132     else
00133     {
00134         WARNPRINTF("wacom is disabled, mode not changed");
00135     }
00136 }

Here is the caller graph for this function:

void wacom_tilt_correction_enable ( gboolean  tilt_enable  ) 

Enable/Disable Hardware Tilt Correction algorithm.

---------------------------------------------------------------------------

Name : wacom_tilt_correction_enable

Parameters:
tilt_enable TRUE to enable correction, FALSE to disable it
Returns:
--

--------------------------------------------------------------------------

Definition at line 153 of file wacom.c.

References g_wacom_enabled, LOGPRINTF, send_command(), and WARNPRINTF.

Referenced by set_defaults().

00154 {
00155     LOGPRINTF("entry");
00156     if (g_wacom_enabled && tilt_enable)
00157     {
00158         send_command("tiltcor-on");
00159     }
00160     else if (g_wacom_enabled && !tilt_enable)
00161     {
00162         send_command("tiltcor-off");
00163     }
00164     else
00165     {
00166         WARNPRINTF("wacom is disabled, tilt correction not changed");
00167     }
00168 }

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

command commands[] [static]
Initial value:
 {
    {"stop",        "0", "Stop sampling"},
    {"sample-133",  "1", "Start sampling at 133 pts/sec"},
    {"sample-80",   "2", "Start sampling at 80 pts/sec"},
    {"sample-40",   "3", "Start sampling at 40 pts/sec"},
    {"survey-on",   "+", "Enable survey scan"},
    {"survey-off",  "-", "Disable survey scan"},
    {"tiltcor-on",  "t", "Enable tilt correction"},
    {"tiltcor-off", "u", "Disable tilt correction"},
}

Definition at line 68 of file wacom.c.

gboolean g_wacom_enabled = FALSE [static]
Generated by  doxygen 1.6.2-20100208