]> rtime.felk.cvut.cz Git - mf6xx.git/blob - src/comedi/fpoulain/comedi+rtai/configEnc.c
Initial commit of Comedi driver for MF624 card; Original author Francois Poulain...
[mf6xx.git] / src / comedi / fpoulain / comedi+rtai / configEnc.c
1 /***********************************************************************
2 Copyright (C) 2007  Francois Poulain, <fpoulain AT gmail DOT com>
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software Foundation,
15 Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 ***********************************************************************/
17
18 #include <stdio.h>
19 #include <time.h>
20 #include <comedilib.h>
21 #include "mf624.h"
22
23 #define PERIOD  250000000.0     /* in nanoseconds       */
24 #define TIME    2.0             /* in seconds           */
25
26 int main(void)
27 {
28         comedi_t *device;
29         comedi_insn instruction;
30         lsampl_t data[MF624_ENC_DATA_SIZE], dataReaded;
31         int subdev = MF624_ENC_SUBDEV;
32         int chan = 2;
33         int range = 0;
34         int aref = 0;
35         char filename[] = "/dev/comedi0";
36         
37         int toc = 0;
38         struct timespec tempo;
39
40         tempo.tv_sec = PERIOD/1e9;
41         tempo.tv_nsec = PERIOD - tempo.tv_sec*1e9;
42
43         data[0] = MF624_ENC_MODE_RISING;                /* Encoder mode         */
44         data[1] = MF624_ENC_COUNT_ENABLE;               /* Encoder counting     */
45         data[2] = MF624_ENC_RESET_ENABLE_BYINPUT;       /* Encoder reset        */
46         data[3] = MF624_ENC_FILTER_ON;                  /* Encoder filtering    */
47
48         instruction.insn = INSN_CONFIG;
49         instruction.n = MF624_ENC_DATA_SIZE;
50         instruction.data = data;
51         instruction.subdev = subdev;
52         instruction.chanspec=CR_PACK(chan,range,aref);
53
54 //      comedi_loglevel(4);
55
56         /* Open comedi device */
57         device = comedi_open(filename);
58         if(!device){
59                 comedi_perror(filename);
60                 return(1);
61         }
62
63         comedi_do_insn(device , &instruction);
64
65         while(toc++ < TIME/(PERIOD/1000000000)){
66                 comedi_data_read(device, subdev, chan, range, aref, &dataReaded);
67                 printf("retour : %x\n", dataReaded);
68                 nanosleep(&tempo, NULL);
69         }
70
71         comedi_close(device);
72
73         return 0;
74 }
75