From da61b09a05e3c8af937a5020dea6c1ef9cb34d98 Mon Sep 17 00:00:00 2001 From: Artem Popov Date: Tue, 1 May 2018 03:37:24 +0700 Subject: [PATCH 1/2] support varibright translation for 40h --- src/monobright.c | 27 ++++++++++++++++ src/private/monobright.h | 20 ++++++++++++ src/proto/40h.c | 68 +++++++++++++++++++++++++++++++++++++++- src/proto/series.c | 17 +++------- src/wscript | 1 + 5 files changed, 119 insertions(+), 14 deletions(-) create mode 100644 src/monobright.c create mode 100644 src/private/monobright.h diff --git a/src/monobright.c b/src/monobright.c new file mode 100644 index 0000000..6e025e4 --- /dev/null +++ b/src/monobright.c @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2011 William Light + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "internal.h" + +uint8_t reduce_levels_to_bitmask(const uint8_t *levels) { + /* levels is expected to be uint8_t[8] */ + uint_t i; + uint8_t byte = 0; + for (i = 0; i < 8; i++) { + byte |= ((levels[i] > 7) & 0x01) << i; + } + return byte; +} diff --git a/src/private/monobright.h b/src/private/monobright.h new file mode 100644 index 0000000..3a0e19f --- /dev/null +++ b/src/private/monobright.h @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2011 William Light + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "internal.h" + +#define reduce_level_to_bit(level) (level > 7) +uint8_t reduce_levels_to_bitmask(const uint8_t *levels); \ No newline at end of file diff --git a/src/proto/40h.c b/src/proto/40h.c index 6026679..ad7f9cf 100644 --- a/src/proto/40h.c +++ b/src/proto/40h.c @@ -23,6 +23,7 @@ #include "internal.h" #include "platform.h" #include "rotation.h" +#include "monobright.h" #include "40h.h" @@ -143,6 +144,71 @@ static monome_led_functions_t proto_40h_led_functions = { .intensity = proto_40h_intensity }; +/** + * led level functions + */ +static int proto_40h_led_level_set(monome_t *monome, uint_t x, uint_t y, + uint_t level) { + return proto_40h_led_set(monome, x, y, reduce_level_to_bit(level)); +} + +static int proto_40h_led_level_all(monome_t *monome, uint_t level) { + return proto_40h_led_all(monome, reduce_level_to_bit(level)); +} + +static int proto_40h_led_level_map(monome_t *monome, uint_t x_off, + uint_t y_off, const uint8_t *data) { + uint8_t levels[64]; + uint8_t masks[8]; + uint_t i; + + /* don't rotate coords here like you would in mext, since rotate happens + * in the call to the normal led_map function + */ + ROTSPEC(monome).level_map_cb(monome, levels, data); + + /* reduce the level data into a bitmask */ + for (i = 0; i < 8; ++i) { + masks[i] = reduce_levels_to_bitmask(&levels[i * 8]); + }; + return proto_40h_led_map(monome, x_off, y_off, masks); +} + + +static int proto_40h_led_level_row(monome_t *monome, uint_t x_off, + uint_t row, size_t count, const uint8_t *data) { + uint_t i, chunks; + uint8_t masks[2]; + + chunks = count / 8; + for (i = 0; i < chunks; ++i) { + masks[i] = reduce_levels_to_bitmask(&data[i*8]); + } + + return proto_40h_led_row(monome, x_off, row, chunks, masks); +} + +static int proto_40h_led_level_col(monome_t *monome, uint_t col, + uint_t y_off, size_t count, const uint8_t *data) { + uint_t i, chunks; + uint8_t masks[2]; + + chunks = count / 8; + for (i = 0; i < chunks; ++i) { + masks[i] = reduce_levels_to_bitmask(&data[i*8]); + } + + return proto_40h_led_col(monome, col, y_off, chunks, masks); +} + +static monome_led_level_functions_t proto_40h_led_level_functions = { + .set = proto_40h_led_level_set, + .all = proto_40h_led_level_all, + .map = proto_40h_led_level_map, + .row = proto_40h_led_level_row, + .col = proto_40h_led_level_col +}; + /** * tilt functions * @@ -248,7 +314,7 @@ monome_t *monome_protocol_new(void) { monome->next_event = proto_40h_next_event; monome->led = &proto_40h_led_functions; - monome->led_level = NULL; + monome->led_level = &proto_40h_led_level_functions; monome->led_ring = NULL; monome->tilt = &proto_40h_tilt_functions; diff --git a/src/proto/series.c b/src/proto/series.c index eac3320..6cdbff1 100644 --- a/src/proto/series.c +++ b/src/proto/series.c @@ -23,6 +23,7 @@ #include "internal.h" #include "platform.h" #include "rotation.h" +#include "monobright.h" #include "series.h" @@ -261,29 +262,19 @@ static monome_led_functions_t proto_series_led_functions = { static int proto_series_led_level_set(monome_t *monome, uint_t x, uint_t y, uint_t level) { - return proto_series_led_set(monome, x, y, (level > 7)); + return proto_series_led_set(monome, x, y, reduce_level_to_bit(level)); } static int proto_series_led_level_all(monome_t *monome, uint_t level) { - return proto_series_led_all(monome, (level > 7)); + return proto_series_led_all(monome, reduce_level_to_bit(level)); } -static uint8_t reduce_levels_to_bitmask(const uint8_t *levels) { - /* levels is expected to be uint8_t[8] */ - uint_t i; - uint8_t byte = 0; - for (i = 0; i < 8; i++) { - byte |= ((levels[i] > 7) & 0x01) << i; - } - return byte; -}; - static int proto_series_led_level_map(monome_t *monome, uint_t x_off, uint_t y_off, const uint8_t *data) { uint8_t levels[64]; uint8_t masks[8]; uint_t i; - + /* don't rotate coords here like you would in mext, since rotate happens * in the call to the normal led_map function */ diff --git a/src/wscript b/src/wscript index e3ab98a..14def52 100644 --- a/src/wscript +++ b/src/wscript @@ -103,6 +103,7 @@ def build(bld): # obj("rotation.c") + obj("monobright.c") obj("libmonome.c") if bld.env.DEST_OS == "win32": From cf2723c29bccb5f479d550c4b97bcf561a033882 Mon Sep 17 00:00:00 2001 From: Artem Popov Date: Tue, 1 May 2018 03:41:33 +0700 Subject: [PATCH 2/2] bump version to 1.4.2 --- wscript | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wscript b/wscript index 264ce95..bcf2eda 100644 --- a/wscript +++ b/wscript @@ -10,7 +10,7 @@ out = "build" # change this stuff APPNAME = "libmonome" -VERSION = "1.4.1" +VERSION = "1.4.2" # # dep checking functions