5 * Copyright (c) 2001 David A. Schleef <ds@schleef.org>
7 * This file may be freely modified, distributed, and combined with
8 * other software, as long as proper attribution is given in the
14 * - A board with a digital output subdevice and a subdevice that
15 * can trigger on an external digital line. A parallel port
16 * satisfies these requirements.
17 * - A Fantazein LED Clock modified so that the individual LEDs
18 * can be controlled directly by the digital I/O lines.
20 * The Fantazein clock has 8 LEDs arranged in a row on a wand that
21 * sweeps back and forth at about 15 Hz. Unmodified, the firmware
22 * of the clock lights the LEDs at the appropriate time to print
23 * words and the time of day. Since the wand moves quickly, it is
24 * barely visible, so it looks like the image floats in the air.
25 * Stuart Hughes modified a clock so that the LEDs could be controlled
26 * directly by the parallel port of a computer, and wrote the
27 * appropriate software using RTAI to create a stable image. This
28 * is an attempt to port the demo to Comedi.
36 #include <comedilib.h>
58 unsigned int chanlist[16];
61 void prepare_cmd(comedi_t *dev,comedi_cmd *cmd);
62 void do_cmd(comedi_t *dev,comedi_cmd *cmd);
66 void config_output(void)
71 comedi_dio_config(device,out_subd,i,COMEDI_OUTPUT);
88 memset(insn,0,3*sizeof(comedi_insn));
90 insn[0].insn = INSN_BITS;
92 insn[0].data = data+0;
93 insn[0].subdev = out_subd;
99 insn[1].insn = INSN_WAIT;
101 insn[1].data = data+2;
105 insn[2].insn = INSN_BITS;
107 insn[2].data = data+4;
108 insn[2].subdev = out_subd;
114 comedi_do_insnlist(device,&il);
117 unsigned int mask = 0xff;
122 comedi_dio_bitfield(device,out_subd,mask,&data);
126 int main(int argc, char *argv[])
134 device = comedi_open(fn);
145 ret = fcntl(comedi_fileno(device),F_SETFL,O_NONBLOCK|O_ASYNC);
146 if(ret<0)perror("fcntl");
150 struct sched_param p;
152 memset(&p,0,sizeof(p));
153 p.sched_priority = 1;
154 ret = sched_setscheduler(0,SCHED_FIFO,&p);
155 if(ret<0)perror("sched_setscheduler");
159 prepare_cmd(device,&cmd);
166 void do_cmd(comedi_t *dev,comedi_cmd *cmd)
172 struct timeval timeout;
174 ret=comedi_command_test(dev,cmd);
176 printf("test ret=%d\n",ret);
178 printf("errno=%d\n",errno);
179 comedi_perror("comedi_command_test");
183 dump_cmd(stdout,cmd);
185 ret=comedi_command_test(dev,cmd);
187 printf("test ret=%d\n",ret);
189 printf("errno=%d\n",errno);
190 comedi_perror("comedi_command_test");
194 dump_cmd(stdout,cmd);
196 ret=comedi_command(dev,cmd);
198 printf("ret=%d\n",ret);
200 printf("errno=%d\n",errno);
201 comedi_perror("comedi_command");
208 FD_SET(comedi_fileno(dev),&rdset);
210 timeout.tv_usec = 50000;
211 ret = select(comedi_fileno(dev)+1,&rdset,NULL,NULL,&timeout);
216 }else if(FD_ISSET(comedi_fileno(dev),&rdset)){
217 ret=read(comedi_fileno(dev),buf,BUFSZ);
229 //printf("read %d %d\n",ret,total);
230 //printf("count = %d\n",count);
233 for(i=0;i<ret;i+=sizeof(sampl_t)){
243 * This part of the demo measures channels 1, 2, 3, 4 at a rate of
244 * 10 khz, with the inter-sample time at 10 us (100 khz). The number
245 * of scans measured is 10. This is analogous to the old mode2
248 void prepare_cmd(comedi_t *dev,comedi_cmd *cmd)
250 memset(cmd,0,sizeof(*cmd));
252 /* the subdevice that the command is sent to */
253 cmd->subdev = subdevice;
256 cmd->flags = TRIG_WAKE_EOS;
258 cmd->start_src = TRIG_NOW;
261 cmd->scan_begin_src = TRIG_EXT;
262 cmd->scan_begin_arg = 0;
265 cmd->convert_src = TRIG_TIMER;
266 cmd->convert_arg = 1;
268 cmd->convert_src = TRIG_ANY;
269 cmd->convert_arg = 0;
272 cmd->scan_end_src = TRIG_COUNT;
273 cmd->scan_end_arg = 1;
275 cmd->stop_src = TRIG_NONE;
278 cmd->chanlist = chanlist;
279 cmd->chanlist_len = 1;
281 chanlist[0]=CR_PACK(0,0,0);