#!/usr/bin/python

"""This module uses ftdi_amforth to communicate with a forth based 
I/O module with PORTA output lines that are bit selectable.
Before running, first upload am128io.frt, then upload am128_porta.frt.
"""

import ftdi_amforth as amforth

serial = amforth.serial
time = amforth.time


forth=amforth.ForthShell()
forth.do_open('/dev/tty.usbserial-A3000PrP')
forth.ffd.timeout=5

#forth.default('words')

def init_output(forth):
    forth.default("hex")
    forth.default("00 PORTA c!") # all off
    forth.default("FF PORTA 1- c!") # all output

def measure(forth, portbit):
    forth.default("00 PORTA c!") # all off
    forth.default(portbit+" high")

portbits=["PA.0","PA.1","PA.2","PA.3","PA.4","PA.5"]

def test(forth,portbits):
    for i in portbits:
        measure(forth, i)

def test_loop(forth, portbits):
    init_output(forth)
    while (True):
        test(forth, portbits)




