16 #include <dev/ppbus/ppi.h>
17 #include <dev/ppbus/ppbconf.h>
41 std::cerr <<
"parallel_write:" << std::endl;
42 std::cerr <<
" set the data on the parallel port" << std::endl;
43 std::cerr <<
"syntax: parallel_write [-i|--init] [-f val|--frequency val] [-?|-h|--help] [bits|seq] " << std::endl;
44 std::cerr <<
" bits: data bits of the parallel port" << std::endl;
45 std::cerr <<
" examples: parallel_write 1101" << std::endl;
46 std::cerr <<
" sets data1, data3 and data4 to '1'" << std::endl;
47 std::cerr <<
" parallel_write 5 0 10" << std::endl;
48 std::cerr <<
" sets data1 (5 times) and data3 (3 times) high then low" << std::endl;
49 std::cerr <<
" keeps other bits unchanged" << std::endl;
50 std::cerr <<
" --init: put the INIT bit 'low' then 'high'" << std::endl;
51 std::cerr <<
" --frequency val: sets the frequency of the most frequent bit change" << std::endl;
52 std::cerr <<
" default (and max value): 500Hz" << std::endl;
53 std::cerr <<
"author: P.Smars, 2008-9" << std::endl;
54 std::cerr <<
"version: 2009-05-12" << std::endl;
63 ioctl(
fd, PPIGCTRL, &
val);
65 ioctl(
fd, PPISCTRL, &
val);
67 ioctl(
fd, PPISCTRL, &
val);
73 ioctl(
fd, PPIGCTRL, &stat);
75 ioctl(
fd, PPISCTRL, &stat);
77 ioctl(
fd, PPISCTRL, &stat);
80 int main(
int argc,
char *argv[] )
91 else if (args.OptionId() ==
OPT_INIT)
93 else if (args.OptionId() ==
OPT_FREQ)
96 o << args.OptionArg();
97 std::istringstream in(o.str().c_str());
100 if ((freq >= 0.00001)&&(freq <= 5000))
101 wtime = (1/freq)*1000000/2;
107 std::cerr <<
"Invalid argument: " << args.OptionText() << std::endl;
108 return error(args.LastError());
111 if ((args.FileCount() < 1)&&(!do_init))
return error(-2);
112 fd = open (
"/dev/ppi0", O_RDWR);
115 if (args.FileCount() == 1)
119 std::string
binary = args.File(0);
120 for (
int i=
binary.size()-1; i>-1; i--)
125 else if (digit !=
'0')
131 ioctl (
fd, PPISDATA, &
val);
132 ioctl(
fd, PPIGCTRL, &
val);
134 ioctl(
fd, PPISCTRL, &
val);
136 ioctl(
fd, PPISCTRL, &
val);
138 else if (args.FileCount() > 8)
140 else if (args.FileCount() > 1)
143 unsigned int num[] = {0,0,0,0,0,0,0,0};
144 int num0[] = {-1,-1,-1,-1,-1,-1,-1,-1};
146 for (
int i=0; i<args.FileCount(); i++)
148 std::string ns = args.File(i);
149 std::istringstream in(ns.c_str());
154 ioctl (
fd, PPIGDATA, &val0);
155 for (
int i=1; i<=nmax; i++)
159 for (
int j=0; j<8; j++)
164 int t = (int)(i*num[j]/(
double)(nmax)+.5);
165 if ((t>0)&&(t != num0[j]))
174 ioctl (
fd, PPISDATA, &val0);
178 ioctl (
fd, PPISDATA, &val0);
A cross-platform command line library which can parse almost any of the standard command line formats...
#define SO_END_OF_OPTIONS
this option definition must be the last entry in the table
#define CSimpleOpt
TCHAR version dependent on if _UNICODE is defined.
int main(int argc, char *argv[])
CSimpleOpt::SOption g_rgOptions[]