From: Rostislav Lisovy Date: Thu, 7 Apr 2011 22:58:48 +0000 (+0200) Subject: Added Comedi userspace program for setting DACs. Tested. Working X-Git-Url: https://rtime.felk.cvut.cz/gitweb/mf6xx.git/commitdiff_plain/18aa77c7064c27c6247407d17ccd38d525272ed2 Added Comedi userspace program for setting DACs. Tested. Working --- diff --git a/src/comedi/simple_driver/userspace/dac_example/Makefile b/src/comedi/simple_driver/userspace/dac_example/Makefile new file mode 100644 index 0000000..8e4f4ee --- /dev/null +++ b/src/comedi/simple_driver/userspace/dac_example/Makefile @@ -0,0 +1,2 @@ +all: + gcc main.c -o main -lcomedi -lm diff --git a/src/comedi/simple_driver/userspace/dac_example/main.c b/src/comedi/simple_driver/userspace/dac_example/main.c new file mode 100644 index 0000000..7e70a41 --- /dev/null +++ b/src/comedi/simple_driver/userspace/dac_example/main.c @@ -0,0 +1,40 @@ +#include +#include +#include "../mf624.h" + +/* Converts Volts into format needed by card. +Input should be integer (no float) */ +int phys_to_comedi(int val) +{ + if (val >= -10 && val <= 10) { + return 0x2000 + (val * (0x2000/10)); + } + else { + return 0x2000; // 0V + } +} + +int main(int argc, char* argv[]) +{ + comedi_t* comedi_dev; + int status; + int channel = 0; + int range = 0; + int aref = 0; + + comedi_dev = comedi_open("/dev/comedi0"); + if (comedi_dev == NULL) { + comedi_perror("comedi_open"); + return 1; + } + + while(1) { + status = comedi_data_write(comedi_dev, MF624_AO_SUBDEV, channel, range, aref, phys_to_comedi(5)); + if (status == -1) { + comedi_perror("comedi_data_write"); + } + sleep(1); + } + + return 0; +} diff --git a/src/comedi/simple_driver/userspace/dout_example/main.c b/src/comedi/simple_driver/userspace/dout_example/main.c index 22b4f4e..58f61ec 100644 --- a/src/comedi/simple_driver/userspace/dout_example/main.c +++ b/src/comedi/simple_driver/userspace/dout_example/main.c @@ -1,6 +1,6 @@ #include #include -#include "mf624.h" +#include "../mf624.h" int main(int argc, char* argv[]) { diff --git a/src/comedi/simple_driver/userspace/dout_example/mf624.h b/src/comedi/simple_driver/userspace/mf624.h similarity index 100% rename from src/comedi/simple_driver/userspace/dout_example/mf624.h rename to src/comedi/simple_driver/userspace/mf624.h