summaryrefslogtreecommitdiff
path: root/doc/stepper_test.py
blob: 95a4e2a4b7bec35a14e87da1c3c774a522fd3216 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3

import time
import statistics
import sqlite3
from datetime import datetime

from pyBusPirateLite import BitBang

if __name__ == '__main__':
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument('buspirate_port', nargs='?', default='/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AD01W1RF-if00-port0')
    args = parser.parse_args()

    bp = BitBang(args.buspirate_port)
    bp.enter_bb()
    bp.mosi = 1

    def stepper_direction_down():
        bp.aux = 0

    def stepper_direction_up():
        bp.aux = 1

    def stepper_step():
        bp.cs = 1
        #time.sleep(0.005)
        bp.cs = 0
        #time.sleep(0.005)

    import curses
    screen = curses.initscr()
    curses.noecho()
    curses.cbreak()
    screen.keypad(True)
    i = 0
    try:
        while True:
            key = screen.getch()
            if key == ord('q'):
                break

            screen.addstr('{: 4}'.format(i))

            if key == curses.KEY_DOWN:
                stepper_direction_down()
                stepper_step()
                i -= 1
            elif key == curses.KEY_UP:
                stepper_direction_up()
                stepper_step()
                i += 1

    finally:
        curses.nocbreak()
        screen.keypad(0)
        curses.echo()
        curses.endwin()