]> rtime.felk.cvut.cz Git - mf6xx.git/blob - src/comedi/simple_driver/userspace/dac_example/main.c
Added a few comments. Cleaned coding style.
[mf6xx.git] / src / comedi / simple_driver / userspace / dac_example / main.c
1 #include <stdio.h>
2 #include <comedilib.h>
3 #include "../mf624.h"
4
5 /* Converts Volts into format needed by card.
6 Input should be integer (no float) */
7 int phys_to_comedi(int val)
8 {
9         if (val >= -10 && val <= 10) {
10                 return 0x2000 + (val * (0x2000/10));
11         }
12         else {
13                 return 0x2000; // 0V
14         }
15 }
16
17 int main(int argc, char* argv[])
18 {
19         comedi_t* comedi_dev;
20         int status;
21         int channel = 0;
22         int range = 0;
23         int aref = 0;
24
25         comedi_dev = comedi_open("/dev/comedi0");
26         if (comedi_dev == NULL) {
27                 comedi_perror("comedi_open");
28                 return 1;
29         }
30
31         while(1) {
32                 status = comedi_data_write(comedi_dev, MF624_AO_SUBDEV, channel, range, aref, phys_to_comedi(5));
33                 if (status == -1) {
34                         comedi_perror("comedi_data_write");
35                 }
36                 sleep(1);
37         }
38
39         return 0;
40 }