Kaibz wrote: ↑Hey RolfMonster,
I've been studying your code, and thanks again for sharing it, i must admit that i'm not as good with C as you are. The thing is, i want to use a RGB LCD to output layer number as a color (and may be custom layer names later) so of course i'm really really trying to understand how you've managed to incorporate your code inside Tmk firmware. Fist may i ask you for how long you've been studying C or general programming?
From the beginning of page 4 to the end you seem to have completely changed your method, you said you remove backlight.c dependency, and it fixed the problem, and that using ACTION_FUNCTION was the way to go...but could you please elaborate on your general method for people like me who are beginners at programming ?
I know i should ask you once i have a much better understanding of C but the problem is that may be you won't be looking at this thread in a few months or years so that's why i'm asking now if that's ok?
I'm by no means an expert in C, I just study it as part of my engineering class for the past couple of years, and a bit earlier in school.
I just use existing libraries such as the ones I linked for the WS2812B strip and the tmk keyboard firmware collection.
Take a look here in the keymap framework:
https://github.com/tmk/tmk_keyboard/blo ... /keymap.md
It shows you how layers work and how they're programmed, it also has a bunch of examples.
In my case, I have a single pin connected to the 'DATA' pin on the LED strip, which outputs a certain data according to the light_ws2812 library (you can take a look in the datasheet of the strip itself if that interests you). I made a simple function called 'showColor' which writes RGB to the whole strip which is basically a loop that goes for <number of LEDs> times and writes the same values for LED #1, LED #2, and so on and so on.
But back on topic. The tmk firmware has a certain API to handle backlight, and it's having 'levels' of backlighting, as I understand it (Keep in mind that I can be wrong, I'm not an expert or anything). For example in my first post in the page I had 7 (FN1 through 7) levels, each has a different value. If you look in backlight.c in the common folder you'll see all the function that you saw earlier in keymap.md that I linked above which are increase (level=level+1), decrease (level=level-1), step (level=level+1 until level==number of levels, then go back to 0), toggle, and simply level (level= input), all of which work only with values with a single bit in them. (Hence the 0b0001,0b0010,etc.)
I'm not sure what went wrong when I assigned different values to each backlight level, or why it worked fine when I used 'step' (i.e. cycle through all levels), but I needed a different approach, and tmk came up with a way to run custom functions (like my 'showColor') when a button is pressed.
So when you use 'ACTION_FUNCTION(id)', it send to the function 'void action_function()' the value that is 'id', which after that can be used however you like. You also have the option of sending another value, 'opt', to whatever purpose.
In my case when you press FN4, i.e. [4]=ACTION_FUNCTION(BACKLIGHT_MODE4), it will send whichever value 'BACKLIGHT_MODE4' is (in my case, well, 4.) to the function that I mentioned above.
The 'switch(id)' is checking which of the following conditions is met, and acts accordingly. If 'id' is 1, then run this, if it's 2, run that, and so on. You get to 'case BACKLIGHT_MODE4:', and it runs the 'showColor' function and exits.
Now you want to have an LCD. Basically what you will need to do is find (or make) a library that writes to the LCD. I don't know which LCD you have, but if you mean the Arduino one (
http://arduino.cc/en/Tutorial/LiquidCrystal) or the RGB one from Adafruit (
http://www.adafruit.com/product/714) then you have lots of resources all over the web. Here's an example for the RGB one:
https://github.com/adafruit/Adafruit-RG ... ld-Library
In the 'hello world' example you see it uses the 'lcd.print()' function to print and 'lcd.setBacklight()' function to set the backlight color, so your firmware will look something like this:
Code: Select all
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
{
switch (id)
{
case FN1:
lcd.print("FN1 pressed");
break;
case FN2:
lcd.setbacklight(RED);
break;
......
Luckily the Teensy has I2C pins, so if you can spare a couple of pins besides your matrix, you're golden.
Add the library header ('Adafruit_RGBLCDShield.h' for example) to your code, and you're good to go.
If you want some specific advice, me and the rest of the people here in the thread will be glad to help you.
Bonus pic:
http://imgur.com/xM5uzx1