<commit_before>#!/usr/bin/python
# -*- coding: iso-8859-1 -*-

import RPi.GPIO as GPIO
import Tkinter
import time
import datetime

class player_frame(Tkinter.Frame):
  def __init__(self, parent):
    Tkinter.Frame.__init__(self, parent)
    self.parent = parent
    self.initialize()

  def initialize(self):

    self.TARGET_1 = 6
    self.TARGET_2 = 13
    self.TARGET_3 = 19
    self.TARGET_4 = 26

    GPIO.setmode(GPIO.BCM)
    GPIO.setup(self.TARGET_1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(self.TARGET_2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(self.TARGET_3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(self.TARGET_4, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    self.grid()

    buttonClock = Tkinter.Button(self, text=u"Start Clock", command=self.OnStartClock)
    buttonClock.grid(column=2, row=0)

    self.labelVariable = Tkinter.StringVar()
    label = Tkinter.Label(self, textvariable=self.labelVariable, anchor="w", fg="white", bg="blue")
    label.grid(column=0, row=0, sticky='EW')
    self.labelVariable.set(self.parent.entryVariable.get())

    self.timer = Tkinter.StringVar()
    label = Tkinter.Label(self, textvariable=self.timer, padx=10, fg="white", bg="black")
    label.grid(column=1, row=0, sticky='EW')
    self.timer.set(u"00:00.000")

    self.grid_columnconfigure(0, weight=1)
#    self.grid_columnconfigure(1, weight=1)

  def OnStartClock(self):
    start_time = time.time()
    print 'Started timer'
    while GPIO.input(self.TARGET_1) == GPIO.HIGH or \
          GPIO.input(self.TARGET_2) == GPIO.HIGH or \
          GPIO.input(self.TARGET_3) == GPIO.HIGH or \
          GPIO.input(self.TARGET_4) == GPIO.HIGH:

      time.sleep(0.2)

      timeDisplay = datetime.datetime.fromtimestamp(time.time() - start_time).strftime('%M:%S.%f')[:-3]
      self.timer.set(timeDisplay)
      self.update()

      if GPIO.input(self.TARGET_1):
        print 'target 1 input was HIGH'
      else:
        print 'target 1 input was LOW'

      if GPIO.input(self.TARGET_2):
        print 'target 2 input was HIGH'
      else:
        print 'target 2 input was LOW'

      if GPIO.input(self.TARGET_3):
        print 'target 3 input was HIGH'
      else:
        print 'target 3 input was LOW'
<commit_msg>Fix bug when running clock multiple times<commit_after>#!/usr/bin/python
# -*- coding: iso-8859-1 -*-

import RPi.GPIO as GPIO
import Tkinter
import time
import datetime

class player_frame(Tkinter.Frame):
  def __init__(self, parent):
    Tkinter.Frame.__init__(self, parent)
    self.parent = parent
    self.initialize()

  def initialize(self):

    self.TARGET_1 = 6
    self.TARGET_2 = 13
    self.TARGET_3 = 19
    self.TARGET_4 = 26

    self.grid()

    buttonClock = Tkinter.Button(self, text=u"Start Clock", command=self.OnStartClock)
    buttonClock.grid(column=2, row=0)

    self.labelVariable = Tkinter.StringVar()
    label = Tkinter.Label(self, textvariable=self.labelVariable, anchor="w", fg="white", bg="blue")
    label.grid(column=0, row=0, sticky='EW')
    self.labelVariable.set(self.parent.entryVariable.get())

    self.timer = Tkinter.StringVar()
    label = Tkinter.Label(self, textvariable=self.timer, padx=10, fg="white", bg="black")
    label.grid(column=1, row=0, sticky='EW')
    self.timer.set(u"00:00.000")

    self.grid_columnconfigure(0, weight=1)
#    self.grid_columnconfigure(1, weight=1)

  def OnStartClock(self):
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(self.TARGET_1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(self.TARGET_2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(self.TARGET_3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(self.TARGET_4, GPIO.IN, pull_up_down=GPIO.PUD_UP)

    start_time = time.time()
    print 'Started timer'
    while GPIO.input(self.TARGET_1) == GPIO.HIGH or \
          GPIO.input(self.TARGET_2) == GPIO.HIGH or \
          GPIO.input(self.TARGET_3) == GPIO.HIGH or \
          GPIO.input(self.TARGET_4) == GPIO.HIGH:

      time.sleep(0.2)

      timeDisplay = datetime.datetime.fromtimestamp(time.time() - start_time).strftime('%M:%S.%f')[:-3]
      self.timer.set(timeDisplay)
      self.update()

      if GPIO.input(self.TARGET_1):
        print 'target 1 input was HIGH'
      else:
        print 'target 1 input was LOW'

      if GPIO.input(self.TARGET_2):
        print 'target 2 input was HIGH'
      else:
        print 'target 2 input was LOW'

      if GPIO.input(self.TARGET_3):
        print 'target 3 input was HIGH'
      else:
        print 'target 3 input was LOW'

{'fraction_non_alphanumeric': 0.13566062748563854, 'fraction_numerical': 0.024304021210782147, 'mean_word_length': 3.149404216315307, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2293162', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1592, 'n_words': 310}