Skip to content

Commit 14aa95a

Browse files
authored
Merge pull request #61 from monome/monobright-40h
support varibright translation for 40h
2 parents 3f1c851 + cf2723c commit 14aa95a

File tree

6 files changed

+120
-15
lines changed

6 files changed

+120
-15
lines changed

src/monobright.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright (c) 2011 William Light <[email protected]>
3+
*
4+
* Permission to use, copy, modify, and/or distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
#include "internal.h"
18+
19+
uint8_t reduce_levels_to_bitmask(const uint8_t *levels) {
20+
/* levels is expected to be uint8_t[8] */
21+
uint_t i;
22+
uint8_t byte = 0;
23+
for (i = 0; i < 8; i++) {
24+
byte |= ((levels[i] > 7) & 0x01) << i;
25+
}
26+
return byte;
27+
}

src/private/monobright.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* Copyright (c) 2011 William Light <[email protected]>
3+
*
4+
* Permission to use, copy, modify, and/or distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
#include "internal.h"
18+
19+
#define reduce_level_to_bit(level) (level > 7)
20+
uint8_t reduce_levels_to_bitmask(const uint8_t *levels);

src/proto/40h.c

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "internal.h"
2424
#include "platform.h"
2525
#include "rotation.h"
26+
#include "monobright.h"
2627

2728
#include "40h.h"
2829

@@ -143,6 +144,71 @@ static monome_led_functions_t proto_40h_led_functions = {
143144
.intensity = proto_40h_intensity
144145
};
145146

147+
/**
148+
* led level functions
149+
*/
150+
static int proto_40h_led_level_set(monome_t *monome, uint_t x, uint_t y,
151+
uint_t level) {
152+
return proto_40h_led_set(monome, x, y, reduce_level_to_bit(level));
153+
}
154+
155+
static int proto_40h_led_level_all(monome_t *monome, uint_t level) {
156+
return proto_40h_led_all(monome, reduce_level_to_bit(level));
157+
}
158+
159+
static int proto_40h_led_level_map(monome_t *monome, uint_t x_off,
160+
uint_t y_off, const uint8_t *data) {
161+
uint8_t levels[64];
162+
uint8_t masks[8];
163+
uint_t i;
164+
165+
/* don't rotate coords here like you would in mext, since rotate happens
166+
* in the call to the normal led_map function
167+
*/
168+
ROTSPEC(monome).level_map_cb(monome, levels, data);
169+
170+
/* reduce the level data into a bitmask */
171+
for (i = 0; i < 8; ++i) {
172+
masks[i] = reduce_levels_to_bitmask(&levels[i * 8]);
173+
};
174+
return proto_40h_led_map(monome, x_off, y_off, masks);
175+
}
176+
177+
178+
static int proto_40h_led_level_row(monome_t *monome, uint_t x_off,
179+
uint_t row, size_t count, const uint8_t *data) {
180+
uint_t i, chunks;
181+
uint8_t masks[2];
182+
183+
chunks = count / 8;
184+
for (i = 0; i < chunks; ++i) {
185+
masks[i] = reduce_levels_to_bitmask(&data[i*8]);
186+
}
187+
188+
return proto_40h_led_row(monome, x_off, row, chunks, masks);
189+
}
190+
191+
static int proto_40h_led_level_col(monome_t *monome, uint_t col,
192+
uint_t y_off, size_t count, const uint8_t *data) {
193+
uint_t i, chunks;
194+
uint8_t masks[2];
195+
196+
chunks = count / 8;
197+
for (i = 0; i < chunks; ++i) {
198+
masks[i] = reduce_levels_to_bitmask(&data[i*8]);
199+
}
200+
201+
return proto_40h_led_col(monome, col, y_off, chunks, masks);
202+
}
203+
204+
static monome_led_level_functions_t proto_40h_led_level_functions = {
205+
.set = proto_40h_led_level_set,
206+
.all = proto_40h_led_level_all,
207+
.map = proto_40h_led_level_map,
208+
.row = proto_40h_led_level_row,
209+
.col = proto_40h_led_level_col
210+
};
211+
146212
/**
147213
* tilt functions
148214
*
@@ -248,7 +314,7 @@ monome_t *monome_protocol_new(void) {
248314
monome->next_event = proto_40h_next_event;
249315

250316
monome->led = &proto_40h_led_functions;
251-
monome->led_level = NULL;
317+
monome->led_level = &proto_40h_led_level_functions;
252318
monome->led_ring = NULL;
253319
monome->tilt = &proto_40h_tilt_functions;
254320

src/proto/series.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "internal.h"
2424
#include "platform.h"
2525
#include "rotation.h"
26+
#include "monobright.h"
2627

2728
#include "series.h"
2829

@@ -261,29 +262,19 @@ static monome_led_functions_t proto_series_led_functions = {
261262

262263
static int proto_series_led_level_set(monome_t *monome, uint_t x, uint_t y,
263264
uint_t level) {
264-
return proto_series_led_set(monome, x, y, (level > 7));
265+
return proto_series_led_set(monome, x, y, reduce_level_to_bit(level));
265266
}
266267

267268
static int proto_series_led_level_all(monome_t *monome, uint_t level) {
268-
return proto_series_led_all(monome, (level > 7));
269+
return proto_series_led_all(monome, reduce_level_to_bit(level));
269270
}
270271

271-
static uint8_t reduce_levels_to_bitmask(const uint8_t *levels) {
272-
/* levels is expected to be uint8_t[8] */
273-
uint_t i;
274-
uint8_t byte = 0;
275-
for (i = 0; i < 8; i++) {
276-
byte |= ((levels[i] > 7) & 0x01) << i;
277-
}
278-
return byte;
279-
};
280-
281272
static int proto_series_led_level_map(monome_t *monome, uint_t x_off,
282273
uint_t y_off, const uint8_t *data) {
283274
uint8_t levels[64];
284275
uint8_t masks[8];
285276
uint_t i;
286-
277+
287278
/* don't rotate coords here like you would in mext, since rotate happens
288279
* in the call to the normal led_map function
289280
*/

src/wscript

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def build(bld):
103103
#
104104

105105
obj("rotation.c")
106+
obj("monobright.c")
106107
obj("libmonome.c")
107108

108109
if bld.env.DEST_OS == "win32":

wscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ out = "build"
1010
# change this stuff
1111

1212
APPNAME = "libmonome"
13-
VERSION = "1.4.1"
13+
VERSION = "1.4.2"
1414

1515
#
1616
# dep checking functions

0 commit comments

Comments
 (0)