18 from libpruio
import *
29 PINS = (P8_12, P8_11, P8_16)
32 io =
pruio_new(PRUIO_DEF_ACTIVE, 4, 0x98, 0)
35 if IO.Errr:
raise AssertionError(
"pruio_new failed (%s)" % IO.Errr)
38 IO.Pwm.contents.ForceUpDown = 1 << 1
39 AqCtl = IO.Pwm.contents.AqCtl
42 AqCtl[AqC_A] = 0b000000000110
43 AqCtl[AqC_B] = 0b011000000000
45 realfreq = c_float(0.0)
48 raise AssertionError(
"failed setting P9_14 (%s)" % IO.Errr)
51 raise AssertionError(
"failed setting P9_16 (%s)" % IO.Errr)
54 raise AssertionError(
"failed setting P9_42 (%s)" % IO.Errr)
57 raise AssertionError(
"failed getting PWM value (%s)" % IO.Errr)
61 raise AssertionError(
"QEP pin configuration failed (%s)" % IO.Errr)
63 raise AssertionError(
"config failed (%s)" % IO.Errr)
65 t = (
" A",
" A & B",
"A, B & I")
71 stdscr.addstr(0,0,
" p=%u" % p)
72 stdscr.addstr(1,0,
" m=%i" % m)
73 stdscr.addstr(2,0,
" %s input" % t[p])
74 stdscr.addstr(3,0,
" %s input" % t[0])
75 stdscr.addstr(4,0,
" %s input" % t[1])
76 stdscr.addstr(5,0,
" %s input" % t[2])
79 raise AssertionError(
"failed getting QEP Value (%s)" % IO.Errr)
80 stdscr.addstr(7,0,
"Position: %8X , Speed: %7.2f" % (posi.value, velo.value))
84 if c == ord(
'a')
or c == ord(
'A'): m = 0
85 elif c == ord(
'b')
or c == ord(
'B'): m = 1
86 elif c == ord(
'i')
or c == ord(
'I'): m = 2
87 elif c == ord(
'p')
or c == ord(
'P'): m = 3; freq = 500000.
if freq >= 499995.
else freq + 5.
88 elif c == ord(
'm')
or c == ord(
'M'): m = 3; freq = 25.
if freq <= 30.
else freq - 5.
89 elif c == ord(
'*'): m = 3; freq = 500000.
if freq >= 250000.
else freq * 5.
90 elif c == ord(
'/'): m = 3; freq = 25.
if freq <= 50.
else freq / 5.
91 elif c == ord(
'0'): m = p; pmax = 0
92 elif c == ord(
'1'): m = p; pmax = 1023
93 elif c == ord(
'4'): m = p; pmax = 4095
94 elif c == ord(
'5'): m = p; pmax = 511
95 elif c == ord(
'8'): m = p; pmax = 8191
96 elif c == ord(
'+'): m = 3; AqCtl[AqC_A] = 0x6
97 elif c == ord(
'-'): m = 3; AqCtl[AqC_B] = 0x9
101 raise AssertionError(
"failed setting PWM value (%s)" % IO.Errr)
103 raise AssertionError(
"failed getting PWM value (%s)" % IO.Errr)
109 raise AssertionError(
"failed setting PWM value (%s)" % IO.Errr)
111 raise AssertionError(
"failed getting PWM value (%s)" % IO.Errr)
115 raise AssertionError(
"QEP pin reconfiguration failed (%s)" % IO.Errr)
116 stdscr.addstr(7,50,
"%s input, %10f Hz (%10f), PMax=%u" % (t[p], freq, realfreq.value, pmax))
120 if __name__ ==
"__main__":
char * pruio_config(pruIo *Io, uint32 Samp, uint32 Mask, uint32 Tmr, uint16 Mds)
Wrapper function for PruIo::config().
char * pruio_pwm_setValue(pruIo *Io, uint8 Ball, float_t Hz, float_t Du)
Wrapper function for PwmMod::setValue().
pruIo * pruio_new(uint16 Act, uint8 Av, uint32 OpD, uint8 SaD)
Wrapper function for the constructor PruIo::PruIo().
char * pruio_qep_config(pruIo *Io, uint8 Ball, uint32 PMax, float_t VHz, float_t Scale, uint8 Mo)
Wrapper function for QepMod::config().
char * pruio_pwm_Value(pruIo *Io, uint8 Ball, float_t *Hz, float_t *Du)
Wrapper function for PwmMod::Value().
char * pruio_qep_Value(pruIo *Io, uint8 Ball, uint32 *Posi, float_t *Velo)
Wrapper function for QepMod::Value().
void pruio_destroy(pruIo *Io)
Wrapper function for the destructor PruIo::~PruIo().