Esempio n. 1
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. 2
0
    def __init__(self):
        self.targets_cache = LRU(1000)
        self.source_bits_cache = LRU(10)
        self.duration_bits_cache = LRU(10)

        self.cache = ProtocolColor.Meta.cache

        msg = TileMessages.SetState64(
              source = 0
            , sequence = 0
            , target = None
            , res_required = False
            , ack_required = True

            , tile_index = 0
            , length = 1
            , x = 0
            , y = 0
            , width = 8
            , duration = 0
            , colors = [{"hue": 0, "saturation": 0, "brightness": 0, "kelvin": 3500}]
            )

        self.frame_header_start = msg.frame_header.pack()[:-32]

        self.frame_address_with_acks_middle = msg.frame_address.pack()[64:-8]
        msg.ack_required = False
        self.frame_address_without_acks_middle = msg.frame_address.pack()[64:-8]

        self.protocol_header_packd = msg.protocol_header.pack()

        # tile_index, width, duration and colors are variable
        self.payload_middle = msg.payload.pack()[8:-8 -32 - (64 * 64)]

        self.uint8_bits = {val: self.bits(T.Uint8, val) for val in range(256)}

        self.width_bits = self.uint8_bits
        self.sequence_bits = self.uint8_bits
        self.tile_index_bits = self.uint8_bits