keybow-firmware icon indicating copy to clipboard operation
keybow-firmware copied to clipboard

Loading pattern broken?

Open jezdez opened this issue 5 years ago • 7 comments

Hey there! Maybe I'm missing something but trying the following on a Keybow mini didn't load the patterns as expected:

keybow.load_pattern("rainbow.png")
keybow.load_pattern("patterns/rainbow.png")
keybow.load_pattern("patterns/rainbow")
local pattern = require "patterns/rainbow.png"
keybow.load_pattern(pattern)

Could someone explain what the correct syntax is for this please?

jezdez avatar Aug 02 '19 20:08 jezdez

Near as I can tell, there's nothing wrong with what you're attempting and a cursory check over the code doesn't yield any obvious problems. I'll try and run a debug build and see if I can replicate.

Gadgetoid avatar Aug 20 '19 11:08 Gadgetoid

But to clarify, it's supposed to be keybow.load_pattern("patterns/rainbow.png") right?

jezdez avatar Aug 20 '19 12:08 jezdez

Ooof, lack of documentation hurts here- it should be:

keybow.load_pattern("patterns/rainbow")

The png part is, for better or worse, added automatically.

A quick local test shows this is at least not failing. Whereas if I try to load patterns/rainbow.png I get the expected:

[read_png_file] File patterns/rainbow.png.png could not be opened for reading

Gadgetoid avatar Aug 20 '19 12:08 Gadgetoid

Hi both!

This is my minimal working version:

require "keybow"

function handle_key_00(pressed)
    if pressed then
        load_new_pattern()
    end
end

function handle_key_01(pressed)
    if pressed then
        load_new_pattern()
    end
end

function handle_key_02(pressed)
    if pressed then
        load_new_pattern()
    end
end

function handle_key_03(pressed)
    if pressed then
        load_new_pattern()
    end
end

function handle_key_04(pressed)
    if pressed then
        load_new_pattern()
    end
end

function handle_key_05(pressed)
    if pressed then
        load_new_pattern()
    end
end

function handle_key_06(pressed)
    if pressed then
        load_new_pattern()
    end
end

function handle_key_07(pressed)
    if pressed then
        load_new_pattern()
    end
end

function handle_key_08(pressed)
    if pressed then
        load_new_pattern()
    end
end

function handle_key_09(pressed)
    if pressed then
        load_new_pattern()
    end
end

function handle_key_10(pressed)
    if pressed then
        load_new_pattern()
    end
end

function handle_key_11(pressed)
    if pressed then
        load_new_pattern()
    end
end

function load_new_pattern()
    keybow.load_pattern('patterns/rainbow')
end

It seemed like keybow.auto_lights(false) was doing something different to what I thought and wouldn't allow load_pattern after getting called.

Two quick Qs

  1. Would you like a pull request to add this as an example?
  2. It seems like patterns/tropical.png isn't right in the most recent release. Is it worth doing a new release?

FleaRex avatar Aug 21 '19 20:08 FleaRex

Clearly we need some comprehensive documentation on this functionality-

keybow.auto_lights(false) completely disables the image-based animation sequencing and light patterns in favour of setting individual LEDs manually.

Gadgetoid avatar Aug 27 '19 15:08 Gadgetoid

Thanks for confirming! Is the C code that the lua code calls around anywhere? It would be interesting to see what keybow.load_pattern and keybow.auto_lights really do. Either way I'm loving it and now that I know what I'm doing it's working really well.

FleaRex avatar Aug 28 '19 18:08 FleaRex

Absolutely- all the C source is here to browse: https://github.com/pimoroni/keybow-firmware/tree/master/keybow

Here's what keybow.load_pattern boils down to:

https://github.com/pimoroni/keybow-firmware/blob/7f359e567860eff871da96bbbad98a3eaac0377c/keybow/lua-config.c#L358-L374

Which, in turn, calls read_png_file in C:

https://github.com/pimoroni/keybow-firmware/blob/fd7b19a8818c11fd300d37ba20e83db542aac2ec/keybow/lights.c#L19-L84

And keybow.auto_lights:

https://github.com/pimoroni/keybow-firmware/blob/7f359e567860eff871da96bbbad98a3eaac0377c/keybow/lua-config.c#L301-L307

Gadgetoid avatar Nov 05 '19 14:11 Gadgetoid