Skip to content

Commit

Permalink
Merge pull request #61 from monome/monobright-40h
Browse files Browse the repository at this point in the history
 support varibright translation for 40h
  • Loading branch information
tehn authored Apr 30, 2018
2 parents 3f1c851 + cf2723c commit 14aa95a
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 15 deletions.
27 changes: 27 additions & 0 deletions src/monobright.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (c) 2011 William Light <[email protected]>
*
* 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;
}
20 changes: 20 additions & 0 deletions src/private/monobright.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) 2011 William Light <[email protected]>
*
* 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);
68 changes: 67 additions & 1 deletion src/proto/40h.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "internal.h"
#include "platform.h"
#include "rotation.h"
#include "monobright.h"

#include "40h.h"

Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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;

Expand Down
17 changes: 4 additions & 13 deletions src/proto/series.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "internal.h"
#include "platform.h"
#include "rotation.h"
#include "monobright.h"

#include "series.h"

Expand Down Expand Up @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions src/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def build(bld):
#

obj("rotation.c")
obj("monobright.c")
obj("libmonome.c")

if bld.env.DEST_OS == "win32":
Expand Down
2 changes: 1 addition & 1 deletion wscript
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ out = "build"
# change this stuff

APPNAME = "libmonome"
VERSION = "1.4.1"
VERSION = "1.4.2"

#
# dep checking functions
Expand Down

0 comments on commit 14aa95a

Please sign in to comment.