31 #include <sys/types.h>
33 #include "libpruio/pruio.h"
34 #include "libpruio/pruio_pins.h"
57 struct timeval timeout;
61 FD_SET(STDIN_FILENO, &set);
65 timeout.tv_usec = mseconds * 1000;
67 return TEMP_FAILURE_RETRY(select(FD_SETSIZE,
73 #define PIN_OUT(a, b, c, d) \
74 if (pruio_gpio_setValue(Io, P1, a)) {printf("setValue P1 error (%s)\n", Io->Errr); break;} \
75 if (pruio_gpio_setValue(Io, P2, b)) {printf("setValue P2 error (%s)\n", Io->Errr); break;} \
76 if (pruio_gpio_setValue(Io, P3, c)) {printf("setValue P3 error (%s)\n", Io->Errr); break;} \
77 if (pruio_gpio_setValue(Io, P4, d)) {printf("setValue P4 error (%s)\n", Io->Errr); break;}
94 p &= Rot & 1 ? 7 : 6 ;
97 case 1:
PIN_OUT(1,0,0,0);
break;
98 case 2:
PIN_OUT(1,1,0,0);
break;
99 case 3:
PIN_OUT(0,1,0,0);
break;
100 case 4:
PIN_OUT(0,1,1,0);
break;
101 case 5:
PIN_OUT(0,0,1,0);
break;
102 case 6:
PIN_OUT(0,0,1,1);
break;
103 case 7:
PIN_OUT(0,0,0,1);
break;
109 int main(
int argc,
char **argv)
114 printf(
"initialisation failed (%s)\n", Io->
Errr);
break;}
120 printf(
"config failed (%s)\n", Io->
Errr);
break;}
123 printf(
"Controls: (other keys quit, 1 and 3 only when Direction = 0)\n");
124 printf(
" 8 = faster\n");
125 printf(
" 4 = rotate CW 5 = stop, hold position 6 = rotate CCW\n");
126 printf(
" 1 = single step CW 2 = slower 3 = single step CCW\n");
127 printf(
" 0 = stop, power off\n\n");
128 printf(
"Pins\t\tKey\t\tDirection\tSleep\n");
130 struct termios oldt, newt;
131 tcgetattr( STDIN_FILENO, &oldt );
133 newt.c_lflag &= ~( ICANON );
135 newt.c_cc[VTIME] = 1;
136 tcsetattr( STDIN_FILENO, TCSANOW, &newt );
139 printf(
"%1d-%1d-%1d-%1d\t\t%s\t\t%2d\t\t%3d",
142 fflush(STDIN_FILENO);
146 case '2':
if (
w < 512)
w <<= 1;
break;
147 case '8':
if (
w > 1)
w >>= 1;
break;
148 case '4':
d = -1;
break;
149 case '7':
d = -2;
break;
150 case '9':
d = 2;
break;
151 case '6':
d = 1;
break;
152 case '0':
d = 0;
PIN_OUT(0,0,0,0);
break;
153 case '5':
d = 0;
move(Io,
d);
break;
154 case '1':
if (
d == 0)
move(Io, -1);
break;
155 case '3':
if (
d == 0)
move(Io, 1);
break;
156 default:
goto finish;
158 printf(
"\t\t%2d\t\t%3d",
d,
w);
163 printf(
"\r%1d-%1d-%1d-%1d\t\t"
168 fflush(STDIN_FILENO);
172 tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
VAR p
The position of the 'x' character (if any).
VAR w
The required window width.
char * pruio_config(pruIo *Io, uint32 Samp, uint32 Mask, uint32 Tmr, uint16 Mds)
Wrapper function for PruIo::config().
uint32 pruio_gpio_Value(pruIo *Io, uint8 Ball)
Wrapper function for GpioUdt::Value().
pruIo * pruio_new(uint16 Act, uint8 Av, uint32 OpD, uint8 SaD)
Wrapper function for the constructor PruIo::PruIo().
void pruio_destroy(pruIo *Io)
Wrapper function for the destructor PruIo::~PruIo().
@ PRUIO_DEF_ACTIVE
Activate all subsystems.
const ANY_PTR NULL
The NULL pointer.
float_t d
the measured duty cycle
#define P3
The third pin of the stepper.
int isleep(unsigned int mseconds)
Wait for keystroke or timeout.
int main(int argc, char **argv)
The main function.
#define P1
The first pin of the stepper.
#define PIN_OUT(a, b, c, d)
Set values of all four output pins.
#define P4
The fourth pin of the stepper.
void move(pruIo *Io, int Rot)
Make the motor move the next step.
#define P2
The second pin of the stepper.
Wrapper structure for PruIo.
char * Errr
Pointer for error messages.