ctk-mouse.c

00001 /*
00002  * Copyright (c) 2007, Swedish Institute of Computer Science.
00003  * All rights reserved. 
00004  *
00005  * Redistribution and use in source and binary forms, with or without 
00006  * modification, are permitted provided that the following conditions 
00007  * are met: 
00008  * 1. Redistributions of source code must retain the above copyright 
00009  *    notice, this list of conditions and the following disclaimer. 
00010  * 2. Redistributions in binary form must reproduce the above copyright 
00011  *    notice, this list of conditions and the following disclaimer in the 
00012  *    documentation and/or other materials provided with the distribution. 
00013  * 3. Neither the name of the Institute nor the names of its contributors 
00014  *    may be used to endorse or promote products derived from this software 
00015  *    without specific prior written permission. 
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
00027  * SUCH DAMAGE. 
00028  *
00029  * This file is part of the Contiki operating system.
00030  * 
00031  * Author: Oliver Schmidt <ol.sc@web.de>
00032  *
00033  * $Id: ctk-mouse.c,v 1.3 2009/10/18 09:33:08 oliverschmidt Exp $
00034  */
00035 
00036 #include <mouse.h>
00037 #include <stdlib.h>
00038 #include <modload.h>
00039 
00040 #include "cfs/cfs.h"
00041 #include "ctk.h"
00042 #include "ctk-mouse.h"
00043 
00044 #if CTK_CONF_MOUSE_SUPPORT
00045 
00046 static struct mouse_pos pos;
00047 static u8_t okay;
00048 
00049 /*-----------------------------------------------------------------------------------*/
00050 void
00051 ctk_mouse_init(void)
00052 {
00053   struct mod_ctrl module_control = {cfs_read};
00054 
00055   module_control.callerdata = cfs_open(mouse_stddrv, CFS_READ);
00056   okay = module_control.callerdata >= 0;
00057   if(okay) {
00058     okay = mod_load(&module_control) == MLOAD_OK;
00059     if(okay) {
00060       okay = mouse_install(&mouse_def_callbacks, module_control.module) == MOUSE_ERR_OK;
00061       if(okay) {
00062         atexit((void (*)(void))mouse_uninstall);
00063       } else {
00064         mod_free(module_control.module);
00065       }
00066     }
00067     cfs_close(module_control.callerdata);
00068   }
00069 }
00070 /*-----------------------------------------------------------------------------------*/
00071 unsigned short
00072 ctk_mouse_x(void)
00073 {
00074   if(okay) {
00075     mouse_pos(&pos);
00076   }
00077   return pos.x;
00078 }
00079 /*-----------------------------------------------------------------------------------*/
00080 unsigned short
00081 ctk_mouse_y(void)
00082 {
00083   if(okay) {
00084     mouse_pos(&pos);
00085   }
00086   return pos.y;
00087 }
00088 /*-----------------------------------------------------------------------------------*/
00089 unsigned char
00090 ctk_mouse_button(void)
00091 {
00092   if(okay) {
00093     return mouse_buttons();
00094   }
00095   return 0;
00096 }
00097 /*-----------------------------------------------------------------------------------*/
00098 unsigned char
00099 ctk_mouse_xtoc(unsigned short x)
00100 {
00101   return MOUSE_CONF_XTOC(x);
00102 }
00103 /*-----------------------------------------------------------------------------------*/
00104 unsigned char
00105 ctk_mouse_ytoc(unsigned short y)
00106 {
00107   return MOUSE_CONF_YTOC(y);
00108 }
00109 /*-----------------------------------------------------------------------------------*/
00110 void
00111 ctk_mouse_hide(void)
00112 {
00113   if(okay) {
00114     mouse_hide();
00115   }
00116 }
00117 /*-----------------------------------------------------------------------------------*/
00118 void
00119 ctk_mouse_show(void)
00120 {
00121   if(okay) {
00122     mouse_show();
00123   }
00124 }
00125 /*-----------------------------------------------------------------------------------*/
00126 #endif /* CTK_CONF_MOUSE_SUPPORT */

Generated on Mon Apr 11 14:23:33 2011 for Contiki 2.5 by  doxygen 1.6.1