bobarry / m2tklib

Automatically exported from code.google.com/p/m2tklib
0 stars 0 forks source link

SWTCHS AS SHORTCUTS #120

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
When I was working with M2TKLIB some limitations appeared. One example of it 
was when I needed to use 6 switches as shortcuts to load data from e2prom. Each 
button when pressed should load (not implemented yet) configuration previously 
stored in e2prom. To store new configuration, I think keeping it pressed for 2 
or 3 seconds should be fine.

My inelegant solution:

uint8_t global_memoria = 0;
uint8_t FLAG_ATUALIZA_TELA = 0;

void desenha_tela_princial(void)
{
    if(m2_GetRoot() == &list_menu_principal)
    {
        u8g_DrawRFrame(&u8g, 0, 0, 128, 64, 2);
        u8g_DrawHLine(&u8g, 0, 8, 128);
        u8g_DrawHLine(&u8g, 0, 25, 128);

        char str_memoria [6][3] = { "M1", "M2", "M3", "M4", "M5", "M6" };

        int z;
        for(z=0; z<6; z++)
        {
            int x;

            x = 18 * (z+1);
            if(z == global_memoria)
            {
                u8g_DrawBox(&u8g, x-4, 1, 15, 7);
                u8g_SetColorIndex(&u8g, 0);
                u8g_DrawStr(&u8g, x, 7, str_memoria[z]);
                u8g_SetColorIndex(&u8g, 1);             
            } else {
                u8g_DrawStr(&u8g, x, 7, str_memoria[z]);                
            }
        }
        FLAG_ATUALIZA_TELA = 0;
    } else if (m2_GetRoot() == &centered_vlist_button) {
        u8g_DrawRFrame(&u8g, 18,0, 110, 64, 2);
    }   
}

void chk_btns(void){    
    if((PINA & (1<<PA0)) == 0){
        _delay_ms(BTBOUNCE);
        while((PINA & (1<<PA0)) == 0){};
        global_memoria = 5;
        FLAG_ATUALIZA_TELA = 1;
        _delay_ms(BTBOUNCE);
    }
    else if((PINA & (1<<PA1)) == 0){
        _delay_ms(BTBOUNCE);
        while((PINA & (1<<PA1)) == 0){};
        global_memoria = 4;
        FLAG_ATUALIZA_TELA = 1;
        _delay_ms(BTBOUNCE);
    }
    else if((PINA & (1<<PA2)) == 0){
        _delay_ms(BTBOUNCE);
        while((PINA & (1<<PA2)) == 0){};
        global_memoria = 3;
        FLAG_ATUALIZA_TELA = 1;
        _delay_ms(BTBOUNCE);
    }
    else if((PINA & (1<<PA3)) == 0){
        _delay_ms(BTBOUNCE);
        while((PINA & (1<<PA3)) == 0){};
        global_memoria = 2;
        FLAG_ATUALIZA_TELA = 1;
        _delay_ms(BTBOUNCE);
    }
    else if((PINA & (1<<PA4)) == 0){
        _delay_ms(BTBOUNCE);
        while((PINA & (1<<PA4)) == 0){};
        global_memoria = 1;
        FLAG_ATUALIZA_TELA = 1;
        _delay_ms(BTBOUNCE);
    }
    else if((PINA & (1<<PA5)) == 0){
        _delay_ms(BTBOUNCE);
        while((PINA & (1<<PA5)) == 0){};
        global_memoria = 0;
        FLAG_ATUALIZA_TELA = 1;
        _delay_ms(BTBOUNCE);
    }
}

int main(void)
{           
    DDRA &= ~((1<<PA0)|(1<<PA1)|(1<<PA2)|(1<<PA3)|(1<<PA4)|(1<<PA5)); //entrada
    PORTA |= ((1<<PA0)|(1<<PA1)|(1<<PA2)|(1<<PA3)|(1<<PA4)|(1<<PA5)); //pullup

    setup_m2();

    while(1)
    {       
        chk_btns();                     
        m2_CheckKey();      
        m2_CheckKey();
        if (m2_HandleKey() != 0 || FLAG_ATUALIZA_TELA != 0) {       
            // picture loop starts here
            u8g_FirstPage(&u8g);
            do {                                                    
                m2_Draw();
                desenha_tela_princial();
                m2_CheckKey();
                chk_btns();             
            } while(u8g_NextPage(&u8g));        
        }   
    }  
}

I'm not sure this would be the best way to do it. Maybe it could be achieved 
using M2TK in the future. That would be great! Thanks for your amazing work! 
I'm having so much fun!

Link to the video: http://www.youtube.com/watch?v=hEpLMWon8_A

Original issue reported on code.google.com by will...@curitiba.org on 18 Oct 2013 at 2:30

GoogleCodeExporter commented 8 years ago
i think this is implemented with issue 114, it has not been release, but if you 
could send me an e-mail (see source code), then i can send you a prerelease 
with issue 114 implemented.

Current implementation only includes 4 quick keys, but i could extend this to 6 
also.
Just let me know if this is solution will work for you.

Idea is to add format options like this "q1r1" to a button/root element: read 
only but selectable with quick key Q1. That means you can connect M2_KEY_Q1 
with some input button.

Original comment by olikr...@gmail.com on 18 Oct 2013 at 6:15

GoogleCodeExporter commented 8 years ago
6 quick keys are implemented.

Will close this issue, quick keys will be handled in issue 114

Original comment by olikr...@gmail.com on 31 Oct 2013 at 4:55

GoogleCodeExporter commented 8 years ago
That's nice. Thank you, Oliver.

Original comment by will...@curitiba.org on 31 Oct 2013 at 5:02