示例#1
0
    def loadSongSettings(self, filename, *args):
        self.frequencyThresholds = self.defaultThresholds
        self.frequencyOffThresholds = self.defaultOffThresholds
        self.frequencyBandOrder = self.defaultOrder

        iniPath = filename + '.ini'
        if os.path.exists(iniPath):
            cp = ConfigParserDefault()
            cp.read([iniPath])

            self.frequencyThresholds = map(float, cp.get_def('spectrum', 'thresholds').split(','))
            self.frequencyOffThresholds = map(float, cp.get_def('spectrum', 'offThresholds').split(','))

            self.frequencyBandOrder = map(int, cp.get_def('lights', 'channelOrder').split(','))
示例#2
0
from __future__ import print_function
import datetime
from weakref import ref

import RPi.GPIO as GPIO

from ConfigParserDefault import ConfigParserDefault
from mainLoop import QueueHandlerProcess
from songConfig import SongConfig


gcp = ConfigParserDefault()
gcp.read("config.ini")

delayBetweenUpdates = float(gcp.get_def("lights", "delayBetweenUpdates", 0.05))

pins = [0, 1, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21, 22, 23, 24, 25]


class LightController(object):
    def __init__(self, analyzer, config):
        self.analyzer = ref(analyzer)

        self.songConfig = SongConfig(config)

        GPIO.setmode(GPIO.BCM)
        for pin in pins:
            GPIO.setup(pin, GPIO.OUT)
            GPIO.output(pin, False)

        self.lastLightUpdate = datetime.datetime.now()
示例#3
0
from random import choice

try:
    import gobject
except ImportError:
    pass

import ansi

from ConfigParserDefault import ConfigParserDefault
import mainLoop
from sampleGen import SampleGen


gcp = ConfigParserDefault()
gcp.read('config.ini')

lightProcessNice = int(gcp.get_def('main', 'lightProcessNice', 0))
soundProcessNice = int(gcp.get_def('main', 'soundProcessNice', 0))

usePygame = gcp.get_def('output', 'usePygame', 'f').lower() not in ('f', 'false', 'n', 'no', '0', 'off')
useSFML = gcp.get_def('output', 'useSFML', 'f').lower() not in ('f', 'false', 'n', 'no', '0', 'off')

useGPIO = gcp.get_def('lights', 'useGPIO', 'f').lower() not in ('f', 'false', 'n', 'no', '0', 'off')

files = sys.argv[1:]


if soundProcessNice:
    os.nice(soundProcessNice)
示例#4
0
class BaseProcess(object):
    def __init__(self, nice=None):
        global currentProcess
        currentProcess = self

        self.config = ConfigParserDefault()
        self.config.read("config.ini")

        self.queuedCallbacks = collections.deque()

        if nice is not None:
            os.nice(nice)

    def quit(self, event=None):
        raise QuitApplication

    def eachLoop(self):
        pass

    def afterEachCallback(self):
        pass

    def onShutdown(self):
        pass

    def queueCall(self, funcOrSet, *args, **kwargs):
        if not funcOrSet:
            return

        if isinstance(funcOrSet, set):
            func = functools.partial(self.callCallbacks, funcOrSet, *args, **kwargs)
        else:
            func = functools.partial(self.callCallbacks, [funcOrSet], *args, **kwargs)

        self.queuedCallbacks.append(func)

    def callCallbacks(self, callbacks, *args, **kwargs):
        for cb in callbacks:
            try:
                cb(*args, **kwargs)
            except:
                print("Exception calling {!r}(*{!r}, **{!r}):".format(cb, args, kwargs), traceback.format_exc())

    def loop(self):
        ansi.info("Starting process run loop...")

        try:
            while True:
                self.eachLoop()

                # Process any queued callbacks.
                while self.queuedCallbacks:
                    callback = self.queuedCallbacks.popleft()
                    callback()

                    self.afterEachCallback()

        except QuitApplication:
            print()
            print("Exiting application.")

        except KeyboardInterrupt:
            print()
            print("User interrupted; exiting.")

        except Exception:
            print("Got Exception while looping:", traceback.format_exc())

        finally:
            ansi.info("Process shutting down...")

            self.onShutdown()

            ansi.done()