<commit_before>#!/usr/bin/python2

from multiprocessing import Process, Queue
import sys
import os
import time
import shlex
import cmd
import logging
from datetime import datetime

import RPi.GPIO as GPIO
from stepper_controller import MotorController

# stepper sequence.  motor dependent
# SEQ = [(1,0,0,0),
#        (0,1,0,0),
#        (1,1,0,0),
#        (0,0,1,0),
#        (1,0,1,0),
#        (0,1,1,0),
#        (1,1,1,0),
#        (0,0,0,1)]

# for Berg's particular stepper

SEQ = [(1,0,0,1),
       (1,0,0,0),
       (1,1,0,0),
       (0,1,0,0),
       (0,1,1,0),
       (0,0,1,0),
       (0,0,1,1),
       (0,0,0,1)]

# define pins and initialize low
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False) 
XPINS = [13,15,16,18]
YPINS = [37,33,31,29]
ZPINS = [32, 36, 38, 40]
GPIO.setup(XPINS + YPINS + ZPINS,
           GPIO.OUT,
           initial=GPIO.LOW)

# command interpreter class

class Hello(cmd.Cmd):
    """ simple command processor """

    # def __init__(self):
    #     cmd.Cmd.__init__(self)
    

    # printed at start of lopo
    intro = """
Usage:
 List available controllers with 'list'
 Select a controller with 'use', then send commands.
 ? for help
 CTRL-D or EOF to exit
"""

    # def preloop(self):
    #     """stuff done *before* command loops starts """
    #     pass

    def postcmd(self, stop, line):
        global status_que

        msg = "none"
        # if stop is True, we need to wait for sync
        if stop:
            logging.debug('postcmd %d', stop)
            msg = status_que.get()
            logging.debug('status que read: %s ', msg)
        if line == 'EOF':
            return True


    def do_greet(self, line):
        print( 'hello ' + line)

    def do_EOF(self, line):
        """Exit program"""
        logging.debug("do EOF")
        print()
        return False

    def do_fwd(self, args):
        """Go forward N steps"""
        global current
        current.send('step ' + args)
        return True

    def do_mov(self, args):
        """ move X Y Z  steps """
        """
        for now, we assume controllers are numbered 0, 1, 2
        """
        logging.debug("do mov: " + args)
        try:
            (x_steps, y_steps, z_steps) = [ i for i in shlex.split(args)]
            controls[0].send('step ' + x_steps)
            controls[1].send('step ' + y_steps)
            controls[2].send('step ' + z_steps)
            # wait for returns
            print(status_que.get())
            print(status_que.get())
            print(status_que.get())
            return False
        except Exception as ex:
            logging.debug(ex)
        
        
    def do_rev(self, args):
        """NOT IMPLEMENTED"""
        print( ' NOT IMPL rev ' + args)

    def do_list(self, args):
        """ list available controllers"""
        li = [n.name for n in controls]
        for i in range(len(li)):
            print(i, li[i])


    def do_use(self, arg):
        """ Use controller N from list"""
        global current
        try:
            val = int(arg)
            if 0 <= val < len(controls):
                current = controls[val]
                prompt.prompt = ('%s > ' ) % current.name
                print('using controller %s' % current.name)
            else:
                print('bad value for %d' % val)
        except ValueError:
            print('bad arg for use')
            pass
        <commit_msg>add timeouts for queue reads<commit_after>#!/usr/bin/python2

from multiprocessing import Process, Queue
import sys
import os
import time
import shlex
import cmd
import logging
from datetime import datetime

import RPi.GPIO as GPIO
from stepper_controller import MotorController

# stepper sequence.  motor dependent
# SEQ = [(1,0,0,0),
#        (0,1,0,0),
#        (1,1,0,0),
#        (0,0,1,0),
#        (1,0,1,0),
#        (0,1,1,0),
#        (1,1,1,0),
#        (0,0,0,1)]

# for Berg's particular stepper

SEQ = [(1,0,0,1),
       (1,0,0,0),
       (1,1,0,0),
       (0,1,0,0),
       (0,1,1,0),
       (0,0,1,0),
       (0,0,1,1),
       (0,0,0,1)]

# define pins and initialize low
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False) 
XPINS = [13,15,16,18]
YPINS = [37,33,31,29]
ZPINS = [32, 36, 38, 40]
GPIO.setup(XPINS + YPINS + ZPINS,
           GPIO.OUT,
           initial=GPIO.LOW)

# command interpreter class

class Hello(cmd.Cmd):
    """ simple command processor """

    # def __init__(self):
    #     cmd.Cmd.__init__(self)
    

    # printed at start of lopo
    intro = """
Usage:
 List available controllers with 'list'
 Select a controller with 'use', then send commands.
 ? for help
 CTRL-D or EOF to exit
"""

    # def preloop(self):
    #     """stuff done *before* command loops starts """
    #     pass

    # def postcmd(self, stop, line):
    #     """ stuff done after *each* command """
    #     pass



    def do_greet(self, line):
        print( 'hello ' + line)

    def do_EOF(self, line):
        """Exit program"""
        logging.debug("do EOF")
        print()
        return True # to exit the command interpreter loop

    def do_fwd(self, args):
        """Go forward N steps"""
        global current
        current.send('step ' + args)
        print(status_que.get(timout=10))


    def do_mov(self, args):
        """ move X Y Z  steps """
        """
        for now, we assume controllers are numbered 0, 1, 2
        """
        logging.debug("do mov: " + args)
        try:
            (x_steps, y_steps, z_steps) = [ i for i in shlex.split(args)]
            controls[0].send('step ' + x_steps)
            controls[1].send('step ' + y_steps)
            controls[2].send('step ' + z_steps)
            # wait for returns
            print(status_que.get(timeout=10))
            print(status_que.get(timeout=10))
            print(status_que.get(timeout=10))
            return False
        except Exception as ex:
            logging.debug(ex)
        
        
    def do_rev(self, args):
        """NOT IMPLEMENTED"""
        print( ' NOT IMPL rev ' + args)

    def do_list(self, args):
        """ list available controllers"""
        li = [n.name for n in controls]
        for i in range(len(li)):
            print(i, li[i])


    def do_use(self, arg):
        """ Use controller N from list"""
        global current
        try:
            val = int(arg)
            if 0 <= val < len(controls):
                current = controls[val]
                prompt.prompt = ('%s > ' ) % current.name
                print('using controller %s' % current.name)
            else:
                print('bad value for %d' % val)
        except ValueError:
            print('bad arg for use')
            pass
        
{'fraction_non_alphanumeric': 0.13561602870813397, 'fraction_numerical': 0.029904306220095694, 'mean_word_length': 1.8671238748392627, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5273418', 'n_tokens_mistral': 2261, 'n_tokens_neox': 2152, 'n_words': 592}