예제 #1
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:
             for i, (user_x, user_y) in enumerate(positions):
                 yield TileMessages.SetUserPosition(
                     tile_index=i,
                     user_x=user_x,
                     user_y=user_y,
                     res_required=False,
                     target=serial,
                 )
예제 #2
0
    async def change(self, serial, tile_index, left_x, top_y, target, afr):
        if serial not in self.serials:
            return {"serial": serial, "data": None}

        user_x = (left_x + 4) / 8
        user_y = (top_y - 4) / 8

        msg = TileMessages.SetUserPosition(tile_index=tile_index,
                                           user_x=user_x,
                                           user_y=user_y,
                                           res_required=False)

        errors = []
        await target.script(msg).run_with_all(serial,
                                              afr,
                                              error_catcher=errors,
                                              message_timeout=5)
        hp.async_as_background(
            self.highlight(serial,
                           tile_index,
                           target,
                           afr,
                           error_catcher=[],
                           message_timeout=3))

        if errors:
            return {"serial": serial, "data": None}

        plans = make_plans(chain=ChainPlan(refresh=True))
        gatherer = Gatherer(target)

        got = await gatherer.gather_all(plans,
                                        serial,
                                        afr,
                                        error_catcher=errors,
                                        message_timeout=5)

        if serial in got and got[serial][0]:
            pixel_coords = user_coords_to_pixel_coords(
                got[serial][1]["chain"]["coords_and_sizes"])
            self.serials[serial]["coords"] = [xy for xy, _ in pixel_coords]

        return {"serial": serial, "data": self.info_for_browser(serial)}
예제 #3
0
파일: tile.py 프로젝트: mic159/photons-core
async def set_tile_positions(collector, target, reference, **kwargs):
    """
    Set the positions of the tiles in your chain.

    ``lan:set_tile_positions d073d5f09124 -- '[[0, 0], [-1, 0], [-1, 1]]'``
    """
    extra = collector.configuration["photons_app"].extra_as_json
    positions = sb.listof(sb.listof(sb.float_spec())).normalise(
        Meta.empty(), extra)
    if any(len(position) != 2 for position in positions):
        raise PhotonsAppError(
            "Please enter positions as a list of two item lists of user_x, user_y"
        )

    async with target.session() as afr:
        for i, (user_x, user_y) in enumerate(positions):
            msg = TileMessages.SetUserPosition(tile_index=i,
                                               user_x=user_x,
                                               user_y=user_y,
                                               res_required=False)
            await target.script(msg).run_with_all(reference, afr)
예제 #4
0
describe "Matrix":

    @pytest.fixture
    def device(self):
        device = devices["tile"]
        devices.store(device).assertAttrs(matrix_effect=TileEffectType.OFF)
        return device

    @pytest.fixture()
    def assertResponse(self, device, **attrs):
        return makeAssertResponse(device, **attrs)

    async it "responds to changing user position", device, assertResponse:
        await assertResponse(
            TileMessages.SetUserPosition(tile_index=1, user_x=0, user_y=1),
            [],
        )
        assert device.attrs.chain[1].user_x == 0
        assert device.attrs.chain[1].user_y == 1

        await assertResponse(
            TileMessages.SetUserPosition(tile_index=1, user_x=3, user_y=4),
            [],
        )
        assert device.attrs.chain[1].user_x == 3
        assert device.attrs.chain[1].user_y == 4

        await assertResponse(
            TileMessages.SetUserPosition(tile_index=2, user_x=4, user_y=5),
            [],