Skip to content

Commit 529b4e3

Browse files
authored
Fix Grid.rotation bug seen in #1888 (#1890)
* When rotated 90/270 degrees led's aren't set appropraitely When a `Grid.rotate()` is called with 1 or 3, the correct quadrant isn't chosen. The issue lies in the function `dev_monome_quad_idx`. This doesn't take into account rotation state, thus when called with something like: ```c dev_monome_quad_idx(md->m, 2, 12) ``` It returns quadrant 2. I think we technically want quadrant 1. We can read the rotation state from the monome device, and use that to correctly calculate the quadrant with a slightly different formula that both works for 128 and 256 grids. * Fix missing variable * We need to pass in the md reference * Possible fix for rows/cols not being reset after a rotation * Don't query grid for rotation status * Use Grid.update_devices * Respond to tehn's comments * Linter
1 parent fc76920 commit 529b4e3

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

lua/core/grid.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ function Grid.remove(dev) end
8888
-- @tparam integer val : rotation 0,90,180,270 as [0, 3]
8989
function Grid:rotation(val)
9090
_norns.grid_set_rotation(self.dev, val)
91+
self.rows = _norns.grid_rows(self.dev)
92+
self.cols = _norns.grid_cols(self.dev)
93+
Grid.update_devices()
9194
end
9295

93-
9496
--- enable/disable grid tilt.
9597
-- @tparam integer id : sensor
9698
-- @tparam integer val : off/on [0, 1]

matron/src/device/device_monome.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ int dev_monome_init(void *self) {
9494
}
9595

9696
// calculate quadrant number given x/y
97-
static inline uint8_t dev_monome_quad_idx(uint8_t x, uint8_t y) {
97+
static inline uint8_t dev_monome_quad_idx(struct dev_monome *md, uint8_t x, uint8_t y) {
98+
// are we a 16x8 grid AND rotated 90 or 270 degrees?
99+
if (md->quads == 2 && md->quad_yoff[1] == 8)
100+
return ((x > 7) << 1) | (y > 7);
98101
return ((y > 7) << 1) | (x > 7);
99102
}
100103
// calcalate offset into quad data given x/y
@@ -127,7 +130,7 @@ void dev_monome_tilt_disable(struct dev_monome *md, uint8_t sensor) {
127130

128131
// set a given LED value
129132
void dev_monome_grid_set_led(struct dev_monome *md, uint8_t x, uint8_t y, int8_t val, bool rel) {
130-
uint8_t q = dev_monome_quad_idx(x, y);
133+
uint8_t q = dev_monome_quad_idx(md, x, y);
131134
if (rel) {
132135
md->data[q][dev_monome_quad_offset(x, y)] =
133136
clamp_range(md->data[q][dev_monome_quad_offset(x, y)] + val, 0, 15);

0 commit comments

Comments
 (0)