From 7ee3f98c49164a83a243dc9b812e8b795d01721e Mon Sep 17 00:00:00 2001 From: Mike Ryan Date: Sun, 4 Mar 2018 23:10:23 -0600 Subject: [PATCH 1/3] Update rgbmatrix, fix column calculation --- matrix.go | 8 ++++++-- vendor/rpi-rgb-led-matrix | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/matrix.go b/matrix.go index 8523004..b6673c5 100644 --- a/matrix.go +++ b/matrix.go @@ -37,6 +37,7 @@ import ( // DefaultConfig default WS281x configuration var DefaultConfig = HardwareConfig{ Rows: 32, + Cols: 32, ChainLength: 1, Parallel: 1, PWMBits: 11, @@ -49,6 +50,8 @@ var DefaultConfig = HardwareConfig{ type HardwareConfig struct { // Rows the number of rows supported by the display, so 32 or 16. Rows int + // Cols the number of columns supported by the display, so 32 or 64 . + Cols int // ChainLengthis the number of displays daisy-chained together // (output of one connected to input of next). ChainLength int @@ -82,12 +85,13 @@ type HardwareConfig struct { } func (c *HardwareConfig) geometry() (width, height int) { - return c.Rows * c.ChainLength, c.Rows * c.Parallel + return c.Cols * c.ChainLength, c.Rows * c.Parallel } func (c *HardwareConfig) toC() *C.struct_RGBLedMatrixOptions { o := &C.struct_RGBLedMatrixOptions{} o.rows = C.int(c.Rows) + o.cols = C.int(c.Cols) o.chain_length = C.int(c.ChainLength) o.parallel = C.int(c.Parallel) o.pwm_bits = C.int(c.PWMBits) @@ -132,7 +136,7 @@ func NewRGBLedMatrix(config *HardwareConfig) (c Matrix, err error) { } } }() - + if isMatrixEmulator() { return buildMatrixEmulator(config), nil } diff --git a/vendor/rpi-rgb-led-matrix b/vendor/rpi-rgb-led-matrix index 24ecf1d..0a4f8f9 160000 --- a/vendor/rpi-rgb-led-matrix +++ b/vendor/rpi-rgb-led-matrix @@ -1 +1 @@ -Subproject commit 24ecf1d8393d55880b013e068a7d3575c13ab8ac +Subproject commit 0a4f8f9a9ea46dbb74f068afea8d07b5aeb72244 From c5664a111c39b39045a95a524ab4abae97294e56 Mon Sep 17 00:00:00 2001 From: Mike Ryan Date: Sun, 4 Mar 2018 23:11:44 -0600 Subject: [PATCH 2/3] Add missing options - disable_hardware_pulsing - show_refresh_rate - inverse_colors - hardware_mapping --- matrix.go | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/matrix.go b/matrix.go index b6673c5..8b9ddf1 100644 --- a/matrix.go +++ b/matrix.go @@ -23,6 +23,18 @@ void led_matrix_swap(struct RGBLedMatrix *matrix, struct LedCanvas *offscreen_ca offscreen_canvas = led_matrix_swap_on_vsync(matrix, offscreen_canvas); } + +void set_show_refresh_rate(struct RGBLedMatrixOptions *o, int show_refresh_rate) { + o->show_refresh_rate = show_refresh_rate != 0 ? 1 : 0; +} + +void set_disable_hardware_pulsing(struct RGBLedMatrixOptions *o, int disable_hardware_pulsing) { + o->disable_hardware_pulsing = disable_hardware_pulsing != 0 ? 1 : 0; +} + +void set_inverse_colors(struct RGBLedMatrixOptions *o, int inverse_colors) { + o->inverse_colors = inverse_colors != 0 ? 1 : 0; +} */ import "C" import ( @@ -82,6 +94,9 @@ type HardwareConfig struct { ShowRefreshRate bool InverseColors bool + + // Name of GPIO mapping used + HardwareMapping string } func (c *HardwareConfig) geometry() (width, height int) { @@ -98,9 +113,25 @@ func (c *HardwareConfig) toC() *C.struct_RGBLedMatrixOptions { o.pwm_lsb_nanoseconds = C.int(c.PWMLSBNanoseconds) o.brightness = C.int(c.Brightness) o.scan_mode = C.int(c.ScanMode) - // o.disable_hardware_pulsing = c.DisableHardwarePulsing - // o.show_refresh_rate = c.ShowRefreshRate - // o.inverse_colors = c.InverseColors + o.hardware_mapping = C.CString(c.HardwareMapping) + + if c.ShowRefreshRate == true { + C.set_show_refresh_rate(o, C.int(1)) + } else { + C.set_show_refresh_rate(o, C.int(0)) + } + + if c.DisableHardwarePulsing == true { + C.set_disable_hardware_pulsing(o, C.int(1)) + } else { + C.set_disable_hardware_pulsing(o, C.int(0)) + } + + if c.InverseColors == true { + C.set_inverse_colors(o, C.int(1)) + } else { + C.set_inverse_colors(o, C.int(0)) + } return o } From 2843f6de381ed140ca8ad04f79e4dc6d4e58e5cb Mon Sep 17 00:00:00 2001 From: Mike Ryan Date: Mon, 5 Mar 2018 11:28:39 -0600 Subject: [PATCH 3/3] Add cli options to examples --- examples/animation/main.go | 18 ++++++++++++++---- examples/basic/main.go | 18 ++++++++++++++---- examples/image/main.go | 20 +++++++++++++++----- examples/rpc/server/main.go | 20 +++++++++++++++----- 4 files changed, 58 insertions(+), 18 deletions(-) diff --git a/examples/animation/main.go b/examples/animation/main.go index 66a9ae4..c9d69ed 100644 --- a/examples/animation/main.go +++ b/examples/animation/main.go @@ -11,18 +11,28 @@ import ( ) var ( - rows = flag.Int("led-rows", 32, "number of rows supported") - parallel = flag.Int("led-parallel", 1, "number of daisy-chained panels") - chain = flag.Int("led-chain", 2, "number of displays daisy-chained") - brightness = flag.Int("brightness", 100, "brightness (0-100)") + rows = flag.Int("led-rows", 32, "number of rows supported") + cols = flag.Int("led-cols", 32, "number of columns supported") + parallel = flag.Int("led-parallel", 1, "number of daisy-chained panels") + chain = flag.Int("led-chain", 2, "number of displays daisy-chained") + brightness = flag.Int("brightness", 100, "brightness (0-100)") + hardware_mapping = flag.String("led-gpio-mapping", "regular", "Name of GPIO mapping used.") + show_refresh = flag.Bool("led-show-refresh", false, "Show refresh rate.") + inverse_colors = flag.Bool("led-inverse", false, "Switch if your matrix has inverse colors on.") + disable_hardware_pulsing = flag.Bool("led-no-hardware-pulse", false, "Don't use hardware pin-pulse generation.") ) func main() { config := &rgbmatrix.DefaultConfig config.Rows = *rows + config.Cols = *cols config.Parallel = *parallel config.ChainLength = *chain config.Brightness = *brightness + config.HardwareMapping = *hardware_mapping + config.ShowRefreshRate = *show_refresh + config.InverseColors = *inverse_colors + config.DisableHardwarePulsing = *disable_hardware_pulsing m, err := rgbmatrix.NewRGBLedMatrix(config) fatal(err) diff --git a/examples/basic/main.go b/examples/basic/main.go index d04cb9c..fe5b3ee 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -9,18 +9,28 @@ import ( ) var ( - rows = flag.Int("led-rows", 32, "number of rows supported") - parallel = flag.Int("led-parallel", 1, "number of daisy-chained panels") - chain = flag.Int("led-chain", 2, "number of displays daisy-chained") - brightness = flag.Int("brightness", 100, "brightness (0-100)") + rows = flag.Int("led-rows", 32, "number of rows supported") + cols = flag.Int("led-cols", 32, "number of columns supported") + parallel = flag.Int("led-parallel", 1, "number of daisy-chained panels") + chain = flag.Int("led-chain", 2, "number of displays daisy-chained") + brightness = flag.Int("brightness", 100, "brightness (0-100)") + hardware_mapping = flag.String("led-gpio-mapping", "regular", "Name of GPIO mapping used.") + show_refresh = flag.Bool("led-show-refresh", false, "Show refresh rate.") + inverse_colors = flag.Bool("led-inverse", false, "Switch if your matrix has inverse colors on.") + disable_hardware_pulsing = flag.Bool("led-no-hardware-pulse", false, "Don't use hardware pin-pulse generation.") ) func main() { config := &rgbmatrix.DefaultConfig config.Rows = *rows + config.Cols = *cols config.Parallel = *parallel config.ChainLength = *chain config.Brightness = *brightness + config.HardwareMapping = *hardware_mapping + config.ShowRefreshRate = *show_refresh + config.InverseColors = *inverse_colors + config.DisableHardwarePulsing = *disable_hardware_pulsing m, err := rgbmatrix.NewRGBLedMatrix(config) fatal(err) diff --git a/examples/image/main.go b/examples/image/main.go index c8aeec9..95ec382 100644 --- a/examples/image/main.go +++ b/examples/image/main.go @@ -10,11 +10,16 @@ import ( ) var ( - rows = flag.Int("led-rows", 32, "number of rows supported") - parallel = flag.Int("led-parallel", 1, "number of daisy-chained panels") - chain = flag.Int("led-chain", 2, "number of displays daisy-chained") - brightness = flag.Int("brightness", 100, "brightness (0-100)") - img = flag.String("image", "", "image path") + rows = flag.Int("led-rows", 32, "number of rows supported") + cols = flag.Int("led-cols", 32, "number of columns supported") + parallel = flag.Int("led-parallel", 1, "number of daisy-chained panels") + chain = flag.Int("led-chain", 2, "number of displays daisy-chained") + brightness = flag.Int("brightness", 100, "brightness (0-100)") + hardware_mapping = flag.String("led-gpio-mapping", "regular", "Name of GPIO mapping used.") + show_refresh = flag.Bool("led-show-refresh", false, "Show refresh rate.") + inverse_colors = flag.Bool("led-inverse", false, "Switch if your matrix has inverse colors on.") + disable_hardware_pulsing = flag.Bool("led-no-hardware-pulse", false, "Don't use hardware pin-pulse generation.") + img = flag.String("image", "", "image path") rotate = flag.Int("rotate", 0, "rotate angle, 90, 180, 270") ) @@ -25,9 +30,14 @@ func main() { config := &rgbmatrix.DefaultConfig config.Rows = *rows + config.Cols = *cols config.Parallel = *parallel config.ChainLength = *chain config.Brightness = *brightness + config.HardwareMapping = *hardware_mapping + config.ShowRefreshRate = *show_refresh + config.InverseColors = *inverse_colors + config.DisableHardwarePulsing = *disable_hardware_pulsing m, err := rgbmatrix.NewRGBLedMatrix(config) fatal(err) diff --git a/examples/rpc/server/main.go b/examples/rpc/server/main.go index 7e634b2..7b9a232 100644 --- a/examples/rpc/server/main.go +++ b/examples/rpc/server/main.go @@ -8,18 +8,28 @@ import ( ) var ( - rows = flag.Int("led-rows", 32, "number of rows supported") - chain = flag.Int("led-chain", 2, "number of displays daisy-chained") - parallel = flag.Int("led-parallel", 1, "number of daisy-chained panels") - brightness = flag.Int("brightness", 100, "brightness (0-100)") + rows = flag.Int("led-rows", 32, "number of rows supported") + cols = flag.Int("led-cols", 32, "number of columns supported") + parallel = flag.Int("led-parallel", 1, "number of daisy-chained panels") + chain = flag.Int("led-chain", 2, "number of displays daisy-chained") + brightness = flag.Int("brightness", 100, "brightness (0-100)") + hardware_mapping = flag.String("led-gpio-mapping", "regular", "Name of GPIO mapping used.") + show_refresh = flag.Bool("led-show-refresh", false, "Show refresh rate.") + inverse_colors = flag.Bool("led-inverse", false, "Switch if your matrix has inverse colors on.") + disable_hardware_pulsing = flag.Bool("led-no-hardware-pulse", false, "Don't use hardware pin-pulse generation.") ) func main() { config := &rgbmatrix.DefaultConfig config.Rows = *rows + config.Cols = *cols + config.Parallel = *parallel config.ChainLength = *chain config.Brightness = *brightness - config.Parallel = *parallel + config.HardwareMapping = *hardware_mapping + config.ShowRefreshRate = *show_refresh + config.InverseColors = *inverse_colors + config.DisableHardwarePulsing = *disable_hardware_pulsing m, err := rgbmatrix.NewRGBLedMatrix(config) fatal(err)