コード例 #1
0
def interpret_string(raw_code: str,
                     *,
                     context: dict = {},
                     callbacks: list = []) -> dict:
    if not context:
        context['groups'] = {}  # group name: laumios in the group
        context['laumios'] = tuple(Laumio.init_all('mpd.lan'))
        # context['laumios'] = Laumio.init_all()
        context['get laumio'] = lambda *a, **k: laumio_from_name_or_id(
            *a, **k, context=context)

        def call_callbacks(context, callbacks):
            print('calling callbacks…')
            for condition, subcommands in callbacks:
                if condition(context, callbacks)():
                    for command in subcommands:
                        command.execute(context, callbacks)

        context['call callbacks'] = call_callbacks
    try:
        raw_model = METAMODEL.model_from_str(raw_code)
    except textx.exceptions.TextXSyntaxError as err:
        raise DSLSyntaxError(*error_message_from_err(err, raw_code))
    for command in raw_model.commands:
        command.execute(context, callbacks)
        # print('CALLBACKS:', callbacks)
        context['call callbacks'](context, callbacks)
コード例 #2
0
ファイル: storm.py プロジェクト: Aluriak/24h2019
def main(server,port):
    allLaumio = Laumio.init_all(servername=server, port=port)
    for l in allLaumio:
        l.fill([25,25,112])
    
    client = utils.create_client(server,port)
    laumios = randomLaumio(client)
    
	for z in range(10):
	    for i in range(0,10):
	        laumios.laumio1.fill('white')
	        time.sleep(0.02)
	        laumios.laumio1.fill('black')
	    for i in range(0,10):
	        laumios.laumio2.fill('white')
	        time.sleep(0.02)
	        laumios.laumio2.fill('black')
	    for i in range(0,10):
	        laumios.laumio3.fill('white')
	        time.sleep(0.02)
	        laumios.laumio3.fill('black')
	    for i in range(0,10):    
	        laumios.laumio4.fill('white')
	        time.sleep(0.02)
	        laumios.laumio4.fill('black')
コード例 #3
0
def main(server, port):
    laumios = Laumio.init_all(servername=server, port=port)
    client = utils.create_client('mpd.lan', 1883)
    dictColor = {
        'red': sensors.get_bp_button_status(client, 1),
        'blue': sensors.get_bp_button_status(client, 2),
        'yellow': sensors.get_bp_button_status(client, 3),
        'green': sensors.get_bp_button_status(client, 4)
    }

    while True:
        for k, v in dictColor.values():
            if v:
                for l in laumios:
                    l.fill(k)
コード例 #4
0
import sensors
from laumio import Laumio

for laumio in Laumio.init_all('mpd.lan', 1883):
    print(sensors.get_atmos(laumio.client))
    break
コード例 #5
0
ファイル: mqtt_proxy.py プロジェクト: Aluriak/24h2019
            json.dumps({
                'idx': conf.BUTTONS_IDX['SwitchBlue'],
                'nvalue': nvalue.get(green, None),
            }))


#    def set_selector_switch(self):
#        """
#        """

if __name__ == "__main__":

    # MPD.lan server
    #allLaumio = Laumio.init_all(servername="mpd.lan")
    # Local test server
    allLaumio = Laumio.init_all(servername="localhost")
    all_proxy = [ProxyLaumio(laumio) for laumio in allLaumio]

    # TODO: do not instantiate all laumios because only 1 is needed
    # TODO: make a loop_forever with callbacks instead of a time.sleep...
    # TODO: Some messages are lost (see paho-mqtt limitations), it is better to
    # use callbacks like on_publish()
    i = 0
    while True:
        prox = all_proxy[0]
        if i % 15 == 0:
            # Avoid flooding the topic
            # Get atmos/distance sensors every few seconds
            prox.atmos()
            prox.distance()
        # Get and broadcast LED settings as soon as possible
コード例 #6
0
ファイル: laumio_group.py プロジェクト: Aluriak/24h2019

if __name__ == '__main__':
    if len(sys.argv) == 1:
        servername = 'localhost'
        port = 1883
    elif len(sys.argv) == 2:
        servername = sys.argv[1]
        port = 1883
    elif len(sys.argv) == 3:
        servername = sys.argv[1]
        port = sys.argv[2]
    else:
        print(__doc__)

    from laumio import Laumio
    group = Laumio.init_all(servername=servername, port=port)
    laumios = tuple(group)
    laumio = laumios[0]
    laumio.off()
    time.sleep(1)
    laumio.red()
    time.sleep(1)
    if laumio.temperature < 10:
        laumio.all_blue()
    if laumio.temperature > 20:
        laumio.fill('red')
        laumio.bottom_ring([255, 255, 255])
    else:
        laumio.fill('green')
コード例 #7
0
                6] or laumio.name == conf.SPATIAL_POSITION[5]:
            laumio.fill('gold')
        elif laumio.name == conf.SPATIAL_POSITION[
                3] or laumio.name == conf.SPATIAL_POSITION[4]:
            laumio.fill('orange')
        elif laumio.name == conf.SPATIAL_POSITION[2]:
            laumio.bottom_ring('orange')
            laumio.middle_ring('orange')
            laumio.top_ring('darkorange')
        else:
            laumio.fill('darkorange')
    time.sleep(3)
    for laumio in laumios:
        laumio.off()
    time.sleep(2)


if __name__ == "__main__":
    if len(sys.argv) == 1:
        servername = 'localhost'
        port = 1883
    elif len(sys.argv) == 2:
        servername = sys.argv[1]
        port = 1883
    elif len(sys.argv) == 3:
        servername = sys.argv[1]
        port = sys.argv[2]
    else:
        print(__doc__)
    main(Laumio.init_all(servername=servername, port=port))
コード例 #8
0
ファイル: radiator.py プロジェクト: Aluriak/24h2019
Stops when it's hot enough.

The more laptops are making this, the best.

usage:
        python radiator.py <target temperature>

"""

import sys
import multiprocessing
from multiprocessing import Pool
from laumio import Laumio

# laumios = list(Laumio.init_all(servername='localhost'))
laumios = list(Laumio.init_all(servername='mpd.lan'))


TARGET = 30  # °C
NB_CPU = multiprocessing.cpu_count()

def make_heat_with_one_CPU(x):
    for _ in range(2**32):
        pass  # make heat

def make_heat_with_all_CPU():
    with Pool(NB_CPU) as p:
        p.map(make_heat_with_one_CPU, [1] * NB_CPU)

def make_heat_by_lighting():
    for laumio in laumios:
コード例 #9
0
    def top_ring(self, color):
        self.print('COLOR TOP WITH:', color)
    def middle_ring(self, color):
        self.print('COLOR MIDDLE WITH:', color)
    def bottom_ring(self, color):
        self.print('COLOR BOTTOM WITH:', color)
    def color_wipe(self, duration, color):
        self.print('COLOR BOTTOM WITH:', duration, color)

    @staticmethod
    def init_all(*args, **kwargs):
        for name_or_id in SPATIAL_POSITION:
            if isinstance(name_or_id, str):  # it's a name
                yield Laumio(name_or_id)

laumios = Laumio.init_all(servername='mpd.lan', port=1883)
available_at = {l: 0 for l in laumios}

def laumio_of_name(name:str):
    global laumios
    for laumio in laumios:
        print('NAMING:', laumio.name, name)
        if laumio.name == name:
            return laumio

def render(data:dict):
    print('DATA: ', data)
    laumio = random.choice(tuple(l for l, at in tuple(available_at.items()) if time.time() > at))
    change_size = data['change_size']
    if data['is_bot']:
        laumio.top_ring('red')