• Hmm, tried to use timer. Something may be wrong in my understanding of jstExecuteFn
    Or, another option, I'm on the wrong train ?
    Short hint, addCharToNotif is called from jshUSARTKick

    [#define](https://forum.espruino.com/sea­rch/?q=%23define) notifBufferSize 10
    uint8_t notifBuffer[notifBufferSize];
    uint8_t notifBufferPnt = 0;
    bool inNotif = false;
    
    void sendNotifBuffer(){
    	if(uart_gatts_if != ESP_GATT_IF_NONE){
    		esp_ble_gatts_send_indicate(uart_gatts_i­f,0,uart_tx_handle,notifBufferPnt,notifB­uffer,false);
    	}
    	notifBufferPnt = 0;
    }
    void notifTimerCB(){
    	if(notifBufferPnt > 0) sendNotifBuffer();
    	jstStopExecuteFn(notifTimerCB,NULL);
    	inNotif = false;
    }
    void startNotifTimer(){
    	JsSysTime time = jshGetSystemTime();
    	inNotif = true;
    	jstExecuteFn(notifTimerCB, NULL, time , 10);//assumed that CB is called after 10 ms ??
    }
    void addCharToNotif(int c){
    	notifBuffer[notifBufferPnt] = (uint8_t)c;
    	notifBufferPnt++;
    	if(notifBufferPnt >= notifBufferSize) sendNotifBuffer();
    	if(!inNotif) startNotifTimer();
    }
    
About

Avatar for JumJum @JumJum started