<commit_before>import os
from time import sleep
from threading import Thread
from flask import Flask
from flask import render_template
from flask import Response
import cv2
import json
import NetworkManager


class MotorThread(Thread):
    def __init__(self, pin=192):
        Thread.__init__(self)
        self.path = "/sys/class/gpio/gpio%d" % pin
        if not os.path.exists(self.path):
            with open("/sys/class/gpio/export", "w") as fh:
                fh.write(str(pin))
        with open(os.path.join(self.path, "direction"), "w") as fh:
            fh.write("out")
        self.speed = 0
        self.daemon = True
    def run(self):
        with open(os.path.join(self.path, "value"), "w") as fh:
          while True:
            if self.speed:
                fh.write("1")
                fh.flush()
                sleep(0.002 if self.speed > 0 else 0.001)
                fh.write("0")
                fh.flush()
                sleep(0.018 if self.speed > 0 else 0.019)
            else:
                sleep(0.020)
                
class SensorThread(Thread):
    def __init__(self, pin =192):                                
        for pin  in range(192,196):		 
         try:		
           with open("/sys/class/gpio/export", "w") as fh:		
               fh.write(str(pin))		
         except IOError:		
             pass		
             with open("/sys/class/gpio/gpio%d/direction" % pin, "w") as fh:		
                                fh.write("in")

left = MotorThread(202)
left.start()
right = MotorThread(196)
right.start()

app = Flask(__name__ )

@app.route('/camera')
def index():
    cap = cv2.VideoCapture(0)
    cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH,320);
    cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT,240);<commit_msg>Adding the light function, and the config file that config the new pins<commit_after>import os
from time import sleep
from threading import Thread
from flask import Flask
from flask import render_template
from flask import Response
import cv2
import ConfigParser
import json
import NetworkManager
config = ConfigParser.ConfigParser()
config.readfp(open('/etc/sumochip/sumochip.conf'))
#this for self check
#print("sanity check")

class MotorThread(Thread):
    def __init__(self, pin=192):
        Thread.__init__(self)
        self.path = "/sys/class/gpio/gpio%d" % pin
        if not os.path.exists(self.path):
            with open("/sys/class/gpio/export", "w") as fh:
                fh.write(str(pin))
        with open(os.path.join(self.path, "direction"), "w") as fh:
            fh.write("out")
        self.speed = 0
        self.daemon = True
    def run(self):
        with open(os.path.join(self.path, "value"), "w") as fh:
          while True:
            if self.speed:
                fh.write("1")
                fh.flush()
                sleep(0.002 if self.speed > 0 else 0.001)
                fh.write("0")
                fh.flush()
                sleep(0.018 if self.speed > 0 else 0.019)
            else:
                sleep(0.020)
                
class SensorThread(Thread):
    def __init__(self, pin =192):                                
        for pin  in range(192,196):		 
         try:		
           with open("/sys/class/gpio/export", "w") as fh:		
               fh.write(str(pin))		
         except IOError:		
             pass		
             with open("/sys/class/gpio/gpio%d/direction" % pin, "w") as fh:		
                                fh.write("in")
class LightStrip(Thread):
    def __init__(self):                                
        for pin  in range(192,197): 
            try:
                with open("/sys/class/gpio/export", "w") as fh:
                    fh.write(str(pin))
            except IOError:
                 pass
            with open("/sys/class/gpio/gpio%d/direction" % pin, "w") as fh:
                fh.write("out")


    def on(self, pin):
        with open("/sys/class/gpio/gpio%d/value" % pin, "w") as fh:
            fh.write("0")

    def off(self, pin):
        with open("/sys/class/gpio/gpio%d/value" % pin, "w") as fh:
            fh.write("1")

strip = LightStrip()
left = MotorThread(config.getint('pins', 'motor left'))
left.start()
right = MotorThread(config.getint('pins', 'motor right'))
right.start()
# Old function 
#left = MotorThread(202)
#left.start()
#right = MotorThread(196)
#right.start()

app = Flask(__name__ )

@app.route("/light")
def light():
    strip.on(193)
    sleep(1)
    strip.off(193)
    return "light"
    
@app.route("/light2")
def light2():
    strip.on(196)
    sleep(1)
    strip.off(196)
    return "light2"

@app.route("/light3")
def light3():
    strip.on(192)
    sleep(1)
    strip.off(192)
    return "light3"
    
@app.route('/camera')
def index():
    cap = cv2.VideoCapture(0)
    cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH,320);
    cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT,240);
{'fraction_non_alphanumeric': 0.13307280954339779, 'fraction_numerical': 0.029411764705882353, 'mean_word_length': 1.8488576449912126, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1097756', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1527, 'n_words': 363}