This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Function runs perfectly when click the board button but doesnt work correctly if the function is called programmatically

Hi!!! we are developing bluetooth mesh, we have a function that send a message to nodes when we press a board button (nrf52 dk), all works fine,

but if we call the same function programmatically the function is also called but doesnt work correctly. (We use the generic onoff client example project)

There is anyway to simulate pressing button?

a part of my code on main.c...

static void sendMessage(generic_onoff_set_params_t set_params, model_transition_t transition_params){
    uint32_t status = NRF_SUCCESS;
    (void)access_model_reliable_cancel(m_clients[0].model_handle);
    generic_onoff_set_params_t p = set_params;
    status = generic_onoff_client_set(&m_clients[0], &p, &transition_params);
}

static generic_onoff_set_params_t getParams(void){
    generic_onoff_set_params_t set_params;
    static uint8_t tid = 0;
    globalTid = tid;
    int aux = (tid++) + 1;
    sendIndex++;
    set_params.tid = sendIndex+1;
    set_params.from_g = true;
    set_params.ginfo.update_flag=false;
    set_params.ginfo.beacons_length=5;
    set_params.on_off = APP_STATE_ON;
    return set_params;
}

static model_transition_t getTransitionParams(void){
    model_transition_t transition_params;
    transition_params.delay_ms = APP_CONFIG_ONOFF_DELAY_MS;
    transition_params.transition_time_ms = APP_CONFIG_ONOFF_TRANSITION_TIME_MS;
    return transition_params;
}

 

static void breq (){
    generic_onoff_set_params_t p = getParams();
    uint32_t status = NRF_SUCCESS;
    p.b->mac[0]='#';
    sendMessage(p,getTransitionParams());
}

 

static void button_event_handler(uint32_t button_number){
    switch (button_number){
        case 0:
            break;
        case 1:
             breq(); // <----------------------This is the function that we call programmatycally and doesnt work if the function is not called by pressing button
             break;
    }
}

Thank you 

Parents
  • You don't need to 'simulate button pressing', you need to work out why the function isn't working when you call it directly. There's nothing magic about a button, pressing it just calls you and you call the function. How are you calling it yourself, in what context, from a timer, randomly, when receiving data? In what way is it 'not working'? 

Reply
  • You don't need to 'simulate button pressing', you need to work out why the function isn't working when you call it directly. There's nothing magic about a button, pressing it just calls you and you call the function. How are you calling it yourself, in what context, from a timer, randomly, when receiving data? In what way is it 'not working'? 

Children
No Data
Related