예제 #1
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')
예제 #2
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)
예제 #3
0
 def __init__(self, client):
     from laumio import Laumio
     self._laumios = []
     # retrieving of the laumios' names
     laumios_names = discover_laumio(client)
     for name in laumios_names:
         laumio = Laumio(client, name)
         self._laumios.append(laumio)
예제 #4
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)
예제 #5
0
import sensors
from laumio import Laumio

for laumio in Laumio.init_all('mpd.lan', 1883):
    print(sensors.get_atmos(laumio.client))
    break
예제 #6
0
            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
예제 #7
0

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')
예제 #8
0
 def init_all(*args, **kwargs):
     for name_or_id in conf.SPATIAL_POSITION:
         if isinstance(name_or_id, str):  # it's a name
             yield Laumio(name_or_id)
예제 #9
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))
예제 #10
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:
예제 #11
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')
예제 #12
0
파일: storm.py 프로젝트: Aluriak/24h2019
def randomLaumio(client):
    Laumios = namedtuple('Laumios',['laumio1', 'laumio2', 'laumio3', 'laumio4'])
    return Laumios(laumio1=Laumio(client, conf.SPATIAL_POSITION[random.randint(0,1)]),
            laumio2=Laumio(client, conf.SPATIAL_POSITION[random.randint(2,4)]),
            laumio3=Laumio(client, conf.SPATIAL_POSITION[random.randint(5,7)]),
            laumio4=Laumio(client, conf.SPATIAL_POSITION[random.randint(8,9)]))