Esempio n. 1
0
async def tile_dice(target, serials, afr, **kwargs):
    canvas = Canvas()

    def default_color_func(i, j):
        if j == -3:
            return Color(0, 1, 0.4, 3500)
        return Color(0, 0, 0, 3500)

    canvas.set_default_color_func(default_color_func)

    numbers = ["1", "2", "3", "4", "5"]
    characters = [dice[n] for n in numbers]
    color = Color(100, 1, 1, 3500)
    put_characters_on_canvas(canvas, characters, coords_for_horizontal_line, color)

    orientations = {}
    async for pkt, _, _ in target.script(TileMessages.GetDeviceChain()).run_with(
        serials, afr, **kwargs
    ):
        if pkt | TileMessages.StateDeviceChain:
            orientations[pkt.serial] = orientations_from(pkt)

    made, _ = make_rgb_and_color_pixels(canvas, 5)

    msgs = []
    for serial in serials:
        os = orientations.get(serial)
        for msg in canvas_to_msgs(
            canvas, coords_for_horizontal_line, duration=1, acks=True, orientations=os
        ):
            msg.target = serial
            msgs.append(msg)

    await target.script(msgs).run_with_all(None, afr, **kwargs)
    return made
Esempio n. 2
0
async def get_device_chain(collector, target, reference, **kwargs):
    """
    Get the devices in your chain
    """
    async for pkt, _, _ in target.script(
            TileMessages.GetDeviceChain()).run_with(reference):
        if pkt | TileMessages.StateDeviceChain:
            print(pkt.serial)
            for tile in tiles_from(pkt):
                print("   ", repr(tile))
Esempio n. 3
0
async def get_tile_positions(collector, target, reference, **kwargs):
    """
    Get the positions of the tiles in your chain.

    ``lan:get_tile_positions d073d5f09124``
    """
    async for pkt, _, _ in target.script(
            TileMessages.GetDeviceChain()).run_with(reference):
        print(pkt.serial)
        for tile in tiles_from(pkt):
            print(f"\tuser_x: {tile.user_x}, user_y: {tile.user_y}")
        print("")
Esempio n. 4
0
async def apply_tile(applier, target, afr, serial, theme, overrides):
    from photons_tile_paint.orientation import Orientation as O, reorient
    from photons_tile_paint.animation import orientations_from

    chain = []
    orientations = {}
    async for pkt, _, _ in target.script(
            TileMessages.GetDeviceChain()).run_with(serial, afr):
        if pkt | TileMessages.StateDeviceChain:
            for tile in tiles_from(pkt):
                chain.append(tile)
            orientations = orientations_from(pkt)

    if chain is None:
        log.warning(
            hp.lc("Couldn't work out how many tiles the light had",
                  serial=serial))
        return

    coords_and_sizes = [((t.user_x, t.user_y), (t.width, t.height))
                        for t in chain]

    messages = []
    for i, (hsbks, coords_and_size) in enumerate(
            zip(
                applier.from_user_coords(coords_and_sizes).apply_theme(theme),
                coords_and_sizes)):
        colors = [{
            "hue": overrides.get("hue", hsbk.hue),
            "saturation": overrides.get("saturation", hsbk.saturation),
            "brightness": overrides.get("brightness", hsbk.brightness),
            "kelvin": overrides.get("kelvin", hsbk.kelvin)
        } for hsbk in hsbks]

        colors = reorient(colors, orientations.get(i, O.RightSideUp))

        messages.append(
            TileMessages.SetState64(tile_index=i,
                                    length=1,
                                    x=0,
                                    y=0,
                                    width=coords_and_size[1][0],
                                    duration=overrides.get("duration", 1),
                                    colors=colors,
                                    res_required=False,
                                    ack_required=True))

    set_power = LightMessages.SetLightPower(level=65535,
                                            duration=overrides.get(
                                                "duration", 1))
    pipeline = Pipeline(*messages, spread=0.005)
    await target.script([set_power, pipeline]).run_with_all(serial, afr)
Esempio n. 5
0
    async def fill(self, random_orientations=False):
        msgs = []
        if self.background_option.type == "current":
            msgs.append(
                TileMessages.GetState64.empty_normalise(tile_index=0,
                                                        length=255,
                                                        x=0,
                                                        y=0,
                                                        width=8))

        msgs.append(TileMessages.GetDeviceChain())

        async for pkt, _, _ in self.target.script(msgs).run_with(
                self.serials, self.afr):
            serial = pkt.serial

            if pkt | TileMessages.State64:
                self.info_by_serial[serial].states.append(
                    (pkt.tile_index, pkt))

            elif pkt | TileMessages.StateDeviceChain:
                if self.coords is None:
                    coords = []
                    for tile in tiles_from(pkt):
                        coords.append(((tile.user_x, tile.user_y),
                                       (tile.width, tile.height)))
                    self.info_by_serial[
                        serial].coords = user_coords_to_pixel_coords(coords)

                orientations = orientations_from(pkt)
                if random_orientations:
                    self.info_by_serial[serial].orientations = {
                        i: random.choice(list(O.__members__.values()))
                        for i in orientations
                    }
                else:
                    self.info_by_serial[serial].orientations = orientations
Esempio n. 6
0
            got = await self.gather(sender, serials, "colors")

            assert got[switch.serial][1]["colors"] is Skip
            assert got[light1.serial][1]["colors"] == tile_expected
            assert got[light2.serial][1]["colors"] == [[hp.Color(100, 0.5, 0.8, 2500)]]
            assert got[striplcm1.serial][1]["colors"] == [expectedlcm1]
            assert got[striplcm2extended.serial][1]["colors"] == [expectedlcm2]

            expected = {
                clean: [],
                switch: [DeviceMessages.GetHostFirmware(), DeviceMessages.GetVersion()],
                light1: [
                    DeviceMessages.GetHostFirmware(),
                    DeviceMessages.GetVersion(),
                    TileMessages.GetDeviceChain(),
                    TileMessages.Get64(length=255, tile_index=0, width=8, x=0, y=0),
                ],
                light2: [
                    DeviceMessages.GetHostFirmware(),
                    DeviceMessages.GetVersion(),
                    LightMessages.GetColor(),
                ],
                striplcm1: [
                    DeviceMessages.GetHostFirmware(),
                    DeviceMessages.GetVersion(),
                    MultiZoneMessages.GetColorZones(start_index=0, end_index=255),
                ],
                striplcm2noextended: [],
                striplcm2extended: [
                    DeviceMessages.GetHostFirmware(),
Esempio n. 7
0
 async def gen(reference, sender, **kwargs):
     ps = sender.make_plans("capability")
     async for serial, _, info in sender.gatherer.gather(
             ps, reference, **kwargs):
         if info["cap"].has_matrix:
             yield TileMessages.GetDeviceChain(target=serial)
Esempio n. 8
0
 def messages(self):
     if self.zones is Zones.MATRIX:
         return [TileMessages.GetDeviceChain()]
     return []
Esempio n. 9
0
 def messages(self):
     if self.zones is Zones.MATRIX:
         return [TileMessages.GetDeviceChain()]
     elif self.zones is Zones.LINEAR:
         return [MultiZoneMessages.GetColorZones(start_index=0, end_index=0)]
     return []