Wednesday, October 1, 2014

Designing a Brew Chamber Controller (Update 4)

 I've made some major changes to the code in the last few weeks.

I've added the ability to accept user input so parameters can be adjusted on the fly instead of being hard-coded in the program.

To check if we have any keyboard activity we use the UNIX select function to check sys.stdin.  If there is data available, read it in and act on it.

Using S and D we can set the desired temperature and the dwell while the program is running.

Later we'll add some automated functionality like brew cycles (ferment start, ferment, cold crash, lager, etc) so the program can do most of the work.

I also added a delay loop function that prints a sequence of characters on the screen to show the program is still running.

#check for user input###############################################
def check_input():

  if select.select([sys.stdin],[],[],0.0)[0]:
    key_input = sys.stdin.readline()

    if key_input[0] == 's' or key_input[0] == 'S':
      set_desired_temp()

    if key_input[0] == 'd' or key_input[0] == 'D':
      set_dwell()

    if key_input[0] == 'x' or key_input[0] == 'X':
      exit_program()

    print_output()
    heater_control(trending.moving_avg_temp)
    cooler_control(trending.moving_avg_temp)
    print_menu()
    print "\033[12;0H                  "
    print "\033[10;0H"

  return

#exit program######################################################
def exit_program():
  print "\033[24;0HExiting program..."
  time.sleep(2)
  exit(0)

#set dwell#########################################################
def set_dwell():
  global DWELL

  print "\033[24;0H"
  DWELL = input("Enter dwell: ")
  print "\033[25;0H                                   "

  return

#set desired temperature##########################################
def set_desired_temp():
  global DESIRED_TEMP

  print "\033[24;0H"
  DESIRED_TEMP = input("Enter desired temperature: ")
  print "\033[25;0H                                  "

  return

#delay_loop function#############################################
def delay_loop():
  print "\033[10;0H"
   
  for x in xrange(15):
    if x % 5 == 0: print "\033[11;0HRunning: ."
    if x % 5 == 1: print "\033[11;0HRunning: o"
    if x % 5 == 2: print "\033[11;0HRunning: O"
    if x % 5 == 3: print "\033[11;0HRunning: 0"
    if x % 5 == 4: print "\033[11;0HRunning: *"

    check_input()

    time.sleep(1) #sleep for 1 second and repeat while True loop

  return

No comments:

Post a Comment