def light_piglow(colour,rotations):
    colourmap = {14 : "red", 13 : "green", 11 : "blue", 1: "orange", 4 : "yellow", 15 : "white" }
    from piglow import PiGlow
    piglow = PiGlow()
#    piglow.all(0)
    if ( colour != "all" ):
        ledcolour = colourmap[colour]
        for j in range(rotations):
            piglow.colour(ledcolour,j)
            sleep(0.001*j) # As the intensity increases, sleep for longer periods
    else:
    #    print ("Trying to run all ")
        for j in range(rotations):
            for colour in (colourmap.values()):
                piglow.colour(("%s" % colour), 255)
                sleep(0.2)
                piglow.colour(colour, 0)
                sleep(0.01)
    piglow.all(0)
예제 #2
0
class GlowShow(object):

    piglow = PiGlow(1)
    led_val = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    brightness = 25
    smoothness = 50
    speed = 10

    def set_speed(self, speed):
        print 'set_speed = ', speed
        self.speed = speed

    def set_brightness(self, brightness):
        print 'set_brightness = ', brightness
        self.brightness = brightness

    def set_pattern(self, pattern):
        print 'set_pattern = ', pattern
        led_last = list(self.led_val)
        self.led_val = self.map_vals(pattern)
        self.led_val = [v * self.brightness for v in self.led_val]

        # smooth transition from last to this value
        for i in range(0, self.smoothness + 1):
            led_step = [
                v0 + int((v1 - v0) * float(i) / float(self.smoothness))
                for v0, v1 in zip(led_last, self.led_val)
            ]

            # update the piglow with current values
            self.piglow.update_leds(led_step)
            time.sleep(1.0 / float(self.speed) / float(self.smoothness))

    def map_vals(self, led_set):
        led_map = [
            7, 8, 9, 6, 5, 10, 18, 17, 16, 14, 12, 11, 1, 2, 3, 4, 15, 13
        ]
        for i in range(0, len(led_map)):
            self.led_val[led_map[i] - 1] = led_set[i]
        return self.led_val
예제 #3
0
    def start(self):
        """Creates the socket and starts the threads"""

        try:
            self.piglow = PiGlow()

        except IOError as e:

            if e[0] == errno.EACCES:
                print >> sys.stderr, "Permission denied, try running as root"
            else:
                print >> sys.stderr, "Unknown error accessing the PiGlow"

            sys.exit(1)

        self.piglow.all(0)

        self.clock = Clock(self.piglow)
        self.alert = Alert(self.piglow)
        self.in_progress = In_Progress(self.piglow)

        address = (self.cfg.HOST, self.cfg.PORT)

        serversock = socket(AF_INET, SOCK_STREAM)
        serversock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
        serversock.bind(address)
        serversock.listen(5)

        self.check_jobs_thread = Thread(None, self.check_jobs, None, ())
        self.socket_manager_thread = Thread(None, self.socket_manager, None,
                                            (serversock, ))

        self.start_threads()

        while self.running == True:
            sleep(1)

        self.stop()
예제 #4
0
import sys
from piglow import PiGlow
import psutil

class GracefulKiller:
  kill_now = False
  def __init__(self):
    signal.signal(signal.SIGINT, self.exit_gracefully)
    signal.signal(signal.SIGTERM, self.exit_gracefully)

  def exit_gracefully(self,signum, frame):
    self.kill_now = True

if __name__ == '__main__':
  killer = GracefulKiller()
  piglow = PiGlow()
  while True:
    cpu = psutil.cpu_percent()
    piglow.all(0)

    if cpu < 5:
        piglow.red(20)
    elif cpu < 20:
        piglow.red(20)
        piglow.orange(20)
    elif cpu < 40:
        piglow.red(20)
        piglow.orange(20)
        piglow.yellow(20)
    elif cpu < 60:
        piglow.red(20)
예제 #5
0
    def do_GET(self):
        parts = urlparse.urlparse(self.path)
        if parts.path == "/":
            self.path = "/index.html"

        piglow = PiGlow()

        if parts.query != "":
            qs = urlparse.parse_qs(parts.query)

            if "r" in qs:
                r = int(qs['r'][0])
                piglow.red(r)

            if "o" in qs:
                o = int(qs['o'][0])
                piglow.orange(o)

            if "y" in qs:
                y = int(qs['y'][0])
                piglow.yellow(y)

            if "g" in qs:
                g = int(qs['g'][0])
                piglow.green(g)

            if "b" in qs:
                b = int(qs['b'][0])
                piglow.blue(b)

            if "w" in qs:
                w = int(qs['w'][0])
                piglow.white(w)

            self.send_response(200)
            self.send_header('Content-type', "application/json")
            self.end_headers()
            self.wfile.write('"true"')
            return

        try:
            #Check the file extension required and
            #set the right mime type

            sendReply = False
            if self.path.endswith(".html"):
                mimetype = 'text/html'
                sendReply = True
            if self.path.endswith(".png"):
                mimetype = 'image/png'
                sendReply = True
            if self.path.endswith(".woff"):
                mimetype = 'application/x-font-woff'
                sendReply = True
            if self.path.endswith(".woff2"):
                mimetype = 'application/font-woff2'
                sendReply = True
            if self.path.endswith(".ttf"):
                mimetype = 'application/octet-stream'
                sendReply = True
            if self.path.endswith(".js"):
                mimetype = 'application/javascript'
                sendReply = True
            if self.path.endswith(".css"):
                mimetype = 'text/css'
                sendReply = True

            if sendReply == True:
                #Open the static file requested and send it
                f = open(curdir + sep + self.path)
                self.send_response(200)
                self.send_header('Content-type', mimetype)
                self.end_headers()
                self.wfile.write(f.read())
                f.close()
            return

        except IOError:
            self.send_error(404, 'File Not Found: %s' % self.path)
예제 #6
0
 def __init__(self):
     self.piglow = PiGlow()