pos_remote = pos_local + 2

	# display the label for the remote and local dice roll states
	stdscr.addstr(pos_local, 0, "local dice roll: ".encode(code), curses.A_BOLD)
	stdscr.addstr(pos_remote, 0, "remote dice roll: ".encode(code), curses.A_BOLD)

	# display the starting prompt next to local and remote dice state lines
	stdscr.addstr(pos_local, pos_state, "waiting for first roll".encode(code))
	stdscr.addstr(pos_remote, pos_state, "waiting for first roll".encode(code))
	stdscr.refresh()

	# listen for keypresses and handle input
	while 1:
		c = stdscr.getch()

		if (c == 10 or c == 13): 
			local_state = random.randint(1,6)
			brew.publish("roll of the dice", local_state)
			stdscr.addstr(pos_local, pos_state, (" " * 30).encode(code))
			stdscr.addstr(pos_local, pos_state, str(local_state).encode(code))

		stdscr.refresh()

# closing out the app and returning terminal to old settings
finally:
	brew.stop()
	curses.nocbreak()
	stdscr.keypad(0)
	curses.echo()
	curses.endwin()
#         pin_bit = 1 << i
#         # First check if transitioned from not touched to touched.
#         if current_touched & pin_bit and not last_touched & pin_bit:
#             print('{0} touched!'.format(i))
#         # Next check if transitioned from touched to not touched.
#         if not current_touched & pin_bit and last_touched & pin_bit:
#             print('{0} released!'.format(i))
#     # Update last state and wait a short period before repeating.
#     last_touched = current_touched
#     time.sleep(0.1)


try:
    brew.start()
    #print("Should be looping")
    print("Press Ctrl-C to quit.")
    while True:
        #print("LOOP")
 #       GPIO.output(GREEN_LED, False)
        if cap.is_touched(0):
		    print("Button 0 Pushed")
		    brew.publish('buttonPress', True)
  #      GPIO.output(GREEN_LED, lightOn)
        time.sleep(CHECK_FREQ)
    
finally:
    GPIO.cleanup()
    brew.stop()


	stdscr.refresh()

	pos_type = stdscr.getyx()[0] + 2
	pos_out = pos_type + 2
	pos_in = pos_out + 1
	stdscr.addstr(pos_type, 0, "new msg: ".encode(code), curses.A_BOLD)
	stdscr.refresh()

	column_str = stdscr.getyx()[1]
	cur_line = ""

	while 1:
		c = stdscr.getch()

		if (c == 10 or c == 13) and len(cur_line) > 0: 
			brew.publish('chat outgoing',cur_line)
			stdscr.addstr(pos_type, pos_con, " cur_line sent      ".encode(code), curses.A_STANDOUT)
			stdscr.addstr(pos_out, 0, "outgoing: ".encode(code), curses.A_BOLD)
			stdscr.addstr(pos_out, pos_msg, (" " * pos_max).encode(code))
			stdscr.addstr(pos_out, pos_msg, cur_line.encode(code))

			cur_line = ""
			stdscr.addstr(pos_type, pos_msg, (" " * pos_max).encode(code))			

		elif (c == 10 or c == 13) and len(cur_line) == 0:
			stdscr.addstr(pos_type, pos_con, " no message to send ".encode(code), curses.A_STANDOUT)			

		elif c == curses.KEY_DC or c == curses.KEY_BACKSPACE or c == 127:
			cur_line = cur_line[0:-1]
			stdscr.addstr(pos_type, (pos["x"] + pos_msg + len(cur_line)), " ".encode(code))			
			stdscr.addstr(pos_type, pos_con, "                     ".encode(code))
try:

    print("Press Ctrl-C to quit.")
    brew.start()

    while True:
        for event in sense.stick.get_events():
            # Check if the joystick was pressed
            if event.action == "pressed":

                # Check which direction
                if event.direction == "up":
                    sense.show_letter("U")  # Up arrow
                elif event.direction == "down":
                    sense.show_letter("D")  # Down arrow
                elif event.direction == "left":
                    sense.show_letter("L")  # Left arrow
                elif event.direction == "right":
                    sense.show_letter("R")  # Right arrow
                elif event.direction == "middle":
                    sense.show_letter("M")  # Enter key

                # publish the joystick press to Spacebrew
                brew.publish('joystick', event.direction)

                # Wait a while and then clear the screen
                time.sleep(0.5)
                sense.clear()

finally:
    brew.stop()
Exemple #5
0
#start connection with spacebrew
try:
    brew.start()
    print("Press Ctrl-C to quit.")

    #loop to get continuous data from Pi's IMU Unit
    while True:
        #loop function to check for joystick events
        for event in sense.stick.get_events():
            #if an event is found check what was pressed
            print(event.action)
            print(event.direction)
            #the directions read by Pi are adjusted to the orientation in which the Pi is held
            if event.direction == "left":
                brew.publish("up", True)
            elif (event.direction == "up"):
                brew.publish("right", True)
            elif (event.direction == "right"):
                brew.publish("down", True)
            elif (event.direction == "down"):
                brew.publish("left", True)
            elif (event.direction == "middle"):
                brew.publish("buttonPressed", True)
        #delay to read again
        time.sleep(CHECK_FREQ)
        sense.clear

#function that runs once pressed Ctrl-C
finally:
    brew.stop()
	pos_local = stdscr.getyx()[0] + 2
	pos_remote = pos_local + 2

	# display the label for the remote and local boolean states
	stdscr.addstr(pos_local, 0, "local state: ".encode(code), curses.A_BOLD)
	stdscr.addstr(pos_remote, 0, "remote state: ".encode(code), curses.A_BOLD)

	# display the starting state for remote and local boolean states
	stdscr.addstr(pos_local, pos_state, (str(local_state) + "  ").encode(code))
	stdscr.addstr(pos_remote, pos_state, (str(remote_state) + "  ").encode(code))
	stdscr.refresh()

	# listen for keypresses and handle input
	while 1:
		c = stdscr.getch()

		if (c == 10 or c == 13): 
			local_state = not local_state
			brew.publish('local state', local_state)
			stdscr.addstr(pos_local, pos_state, (str(local_state) + "  ").encode(code))

		stdscr.refresh()

# closing out the app and returning terminal to old settings
finally:
	brew.stop()
	curses.nocbreak()
	stdscr.keypad(0)
	curses.echo()
	curses.endwin()
	pos_local = stdscr.getyx()[0] + 2
	pos_remote = pos_local + 2

	# display the label for the remote and local boolean states
	stdscr.addstr(pos_local, 0, "local state: ".encode(code), curses.A_BOLD)
	stdscr.addstr(pos_remote, 0, "remote state: ".encode(code), curses.A_BOLD)

	# display the starting state for remote and local boolean states
	stdscr.addstr(pos_local, pos_state, (str(local_state) + "  ").encode(code))
	stdscr.addstr(pos_remote, pos_state, (str(remote_state) + "  ").encode(code))
	stdscr.refresh()

	# listen for keypresses and handle input
	while 1:
		c = stdscr.getch()

		if (c == 10 or c == 13): 
			local_state = not local_state
			brew.publish('local state', str(local_state).lower())
			stdscr.addstr(pos_local, pos_state, (str(local_state) + "  ").encode(code))

		stdscr.refresh()

# closing out the app and returning terminal to old settings
finally:
	brew.stop()
	curses.nocbreak()
	stdscr.keypad(0)
	curses.echo()
	curses.endwin()
# Main loop to print a message every time a pin is touched.
try:
    brew.start()
    print('Press Ctrl-C to quit.')
    last_touched = cap.touched()

    while True:
        current_touched = cap.touched()
        # Check each pin's last and current state to see if it was pressed or released.
        for i in range(12):
            # Each pin is represented by a bit in the touched value.  A value of 1
            # means the pin is being touched, and 0 means it is not being touched.
            pin_bit = 1 << i
            # First check if transitioned from not touched to touched.
            if current_touched & pin_bit and not last_touched & pin_bit:
                brew.publish('P{0}'.format(i), True)
                print('P{0} touched!'.format(i), True)
                time.sleep(0.1)
            # Next check if transitioned from touched to not touched.
            if not current_touched & pin_bit and last_touched & pin_bit:
                brew.publish('P{0}'.format(i), False)
                print('P{0} released!'.format(i), False)
                time.sleep(0.1)
        # Update last state and wait a short period before repeating.
        last_touched = current_touched
        time.sleep(0.1)
finally:
    brew.stop()

##############################################################
# Orignial Adaruit licnece
Exemple #9
0
    displayRange(remote_state, col_remote)
    stdscr.refresh()

    # listen for keypresses and handle input
    while 1:
        c = stdscr.getch()

        new_data = False
        if c == ord('+') or c == ord('='):
            local_state += 10
            if local_state > 1023: local_state = 1023
            new_data = True
        elif c == ord('-') or c == ord('_'):
            local_state -= 10
            if local_state < 0: local_state = 0
            new_data = True

        if new_data:
            brew.publish("slider", local_state)
            displayRange(local_state, col_local)

        stdscr.refresh()

# closing out the app and returning terminal to old settings
finally:
    brew.stop()
    curses.nocbreak()
    stdscr.keypad(0)
    curses.echo()
    curses.endwin()
Exemple #10
0
import serial
import sys
import time
from pySpacebrew.spacebrew import Spacebrew

ser = serial.Serial('/dev/tty.usbserial-AD01SUMG', 9600)
connected = False

# GENERAL IDEA
# Listen for events coming from the arduino and forward them as Spacebrew Events
# bool, string, range
# Take Spacebrew events and forward them to the arduino
# bool, string, range

# setup Spacebrew
brew = Spacebrew("pyRFID", description="Python contolled rfid scanner", server="beaglebone.local", port=9000)
brew.addPublisher("rfidscan", "string")
brew.start()

while True:
	message = ser.readline()
	connected = True
	print(message)
	brew.publish('rfidscan', message)
	time.sleep(0.1)

	ser.close
Exemple #11
0
    stdscr.refresh()

    pos_type = stdscr.getyx()[0] + 2
    pos_out = pos_type + 2
    pos_in = pos_out + 1
    stdscr.addstr(pos_type, 0, "new msg: ".encode(code), curses.A_BOLD)
    stdscr.refresh()

    column_str = stdscr.getyx()[1]
    cur_line = ""

    while 1:
        c = stdscr.getch()

        if (c == 10 or c == 13) and len(cur_line) > 0:
            brew.publish('chat outgoing', cur_line)
            stdscr.addstr(pos_type, pos_con,
                          " cur_line sent      ".encode(code),
                          curses.A_STANDOUT)
            stdscr.addstr(pos_out, 0, "outgoing: ".encode(code), curses.A_BOLD)
            stdscr.addstr(pos_out, pos_msg, (" " * pos_max).encode(code))
            stdscr.addstr(pos_out, pos_msg, cur_line.encode(code))

            cur_line = ""
            stdscr.addstr(pos_type, pos_msg, (" " * pos_max).encode(code))

        elif (c == 10 or c == 13) and len(cur_line) == 0:
            stdscr.addstr(pos_type, pos_con,
                          " no message to send ".encode(code),
                          curses.A_STANDOUT)
Exemple #12
0
    # display the label for the remote and local dice roll states
    stdscr.addstr(pos_local, 0, "local dice roll: ".encode(code),
                  curses.A_BOLD)
    stdscr.addstr(pos_remote, 0, "remote dice roll: ".encode(code),
                  curses.A_BOLD)

    # display the starting prompt next to local and remote dice state lines
    stdscr.addstr(pos_local, pos_state, "waiting for first roll".encode(code))
    stdscr.addstr(pos_remote, pos_state, "waiting for first roll".encode(code))
    stdscr.refresh()

    # listen for keypresses and handle input
    while 1:
        c = stdscr.getch()

        if (c == 10 or c == 13):
            local_state = random.randint(1, 6)
            brew.publish("roll of the dice", local_state)
            stdscr.addstr(pos_local, pos_state, (" " * 30).encode(code))
            stdscr.addstr(pos_local, pos_state, str(local_state).encode(code))

        stdscr.refresh()

# closing out the app and returning terminal to old settings
finally:
    brew.stop()
    curses.nocbreak()
    stdscr.keypad(0)
    curses.echo()
    curses.endwin()
Exemple #13
0
	displayRange(remote_state, col_remote) 
	stdscr.refresh()

	# listen for keypresses and handle input
	while 1:
		c = stdscr.getch()

		new_data = False
		if c == ord('+') or c == ord('='):
			local_state += 10
			if local_state > 1023: local_state = 1023
			new_data = True
		elif c == ord('-') or c == ord('_'):
			local_state -= 10
			if local_state < 0: local_state = 0
			new_data = True

		if new_data:
			brew.publish("slider", local_state)
			displayRange(local_state, col_local)

		stdscr.refresh()

# closing out the app and returning terminal to old settings
finally:
	brew.stop()
	curses.nocbreak()
	stdscr.keypad(0)
	curses.echo()
	curses.endwin()
Exemple #14
0
    cmdCall = subprocess.check_output('sudo iwlist wlan0 scan | grep ESSID',
                                      shell=True)
    output = cmdCall.decode("utf-8").splitlines()
    for i, s in enumerate(output):
        output[i] = s[27:-1]  #trim out all the stuff we don't need

    return output


try:
    brew.start()
    print("Press Ctrl-C to quit.")
    wifiNetworks = makeArray()

    while True:
        if (connected == True):
            if (CURR_INDEX < len(wifiNetworks) - 1):
                CURR_INDEX += 1
            else:
                CURR_INDEX = 0
            #print("Wifi Sent")
            print(wifiNetworks[CURR_INDEX])
            currentWifi = wifiNetworks[CURR_INDEX]
            brew.publish('wifi', currentWifi)
            brew.publish('networkEvent', True)
        connected = True
        time.sleep(CHECK_FREQ)

finally:
    brew.stop()