Fraise  2.1
FRAmework for Interfacing Software and Electronics
 All Classes Files Functions Typedefs Groups
switch.h
1 /*********************************************************************
2  *
3  * Switch library for Fraise pic18f device
4  *
5  *
6  *********************************************************************
7  * Author Date Comment
8  *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9  * Antoine Rousseau march 2013 Original.
10  ********************************************************************/
11 /*
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 2
15 # of the License, or (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 # MA 02110-1301, USA.
26 */
27 #ifndef _SWITCH__H_
28 #define _SWITCH__H_
29 
30 #include <fruit.h>
31 
32 void switchInit();
33 
34 void switchSelectHW(unsigned char channel, unsigned char *port, unsigned char bit); // assign a port/bit to a channel ; bit is decimal (0-7)
35 
36 void switchDeselect(unsigned char channel); // deselect a channel
37 
38 void switchService(void); // call often
39 
40 char switchSend(void); // call at the maximum rate you want to report switches
41  // return number of channels sent
42 
43 char switchGet(unsigned char chan);
44 
45 #define SWITCH_SELECT_(num,connport,connbit) \
46  do { switchSelectHW(num,&PORT##connport,connbit); } while(0)
47 
48 // use next macro like this : SERVO_SET_PORT(0,K2); to assign switch_0 to K2 connector.
49 #define switchSelect(num,conn) do { \
50  pinModeDigitalIn(conn); \
51  CALL_FUN3(SWITCH_SELECT_,num,KPORT(conn),KBIT(conn)); } while(0)
52 
53 #endif //