kopia lustrzana https://github.com/OpenRTX/OpenRTX
threads.c: Avoid reading keyboard status while display is rendering
rodzic
b5c06d5459
commit
3c00802330
|
@ -138,49 +138,52 @@ static void kbd_task(void *arg)
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
// Get currently pressed keys
|
if(!gfx_renderingInProgress())
|
||||||
keys = kbd_getKeys();
|
|
||||||
// Compare with previous keyboard status
|
|
||||||
if(keys != prev_keys)
|
|
||||||
{
|
{
|
||||||
bool long_press = false;
|
// Get currently pressed keys
|
||||||
bool send_event = false;
|
keys = kbd_getKeys();
|
||||||
now = OSTimeGet(&os_err);
|
// Compare with previous keyboard status
|
||||||
for(uint8_t k=0; k < kbd_num_keys; k++)
|
if(keys != prev_keys)
|
||||||
{
|
{
|
||||||
// Key has been pressed
|
bool long_press = false;
|
||||||
if(!(prev_keys & (1 << k)) && (keys & (1 << k)))
|
bool send_event = false;
|
||||||
|
now = OSTimeGet(&os_err);
|
||||||
|
for(uint8_t k=0; k < kbd_num_keys; k++)
|
||||||
{
|
{
|
||||||
// Save timestamp
|
// Key has been pressed
|
||||||
key_ts[k] = now;
|
if(!(prev_keys & (1 << k)) && (keys & (1 << k)))
|
||||||
|
{
|
||||||
|
// Save timestamp
|
||||||
|
key_ts[k] = now;
|
||||||
|
}
|
||||||
|
// Key has been released
|
||||||
|
else if((prev_keys & (1 << k)) && !(keys & (1 << k)))
|
||||||
|
{
|
||||||
|
send_event = true;
|
||||||
|
// Check timestamp
|
||||||
|
if((now - key_ts[k]) >= kbd_long_interval)
|
||||||
|
long_press = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Key has been released
|
if(send_event)
|
||||||
else if((prev_keys & (1 << k)) && !(keys & (1 << k)))
|
|
||||||
{
|
{
|
||||||
send_event = true;
|
kbd_msg_t msg;
|
||||||
// Check timestamp
|
msg.long_press = long_press;
|
||||||
if((now - key_ts[k]) >= kbd_long_interval)
|
// OR the saved key status with the current key status
|
||||||
long_press = true;
|
// Do this because the new key status is got when the
|
||||||
|
// key is lifted, and does not contain the pressed key anymore
|
||||||
|
msg.keys = keys | prev_keys;
|
||||||
|
// Send event_t as void * message to use with OSQPost
|
||||||
|
event_t event;
|
||||||
|
event.type = EVENT_KBD;
|
||||||
|
event.payload = msg.value;
|
||||||
|
// Send keyboard status in queue
|
||||||
|
OSQPost(&ui_queue, (void *)event.value, sizeof(event_t),
|
||||||
|
OS_OPT_POST_FIFO + OS_OPT_POST_NO_SCHED, &os_err);
|
||||||
}
|
}
|
||||||
|
// Save current keyboard state as previous
|
||||||
|
prev_keys = keys;
|
||||||
}
|
}
|
||||||
if(send_event)
|
|
||||||
{
|
|
||||||
kbd_msg_t msg;
|
|
||||||
msg.long_press = long_press;
|
|
||||||
// OR the saved key status with the current key status
|
|
||||||
// Do this because the new key status is got when the
|
|
||||||
// key is lifted, and does not contain the pressed key anymore
|
|
||||||
msg.keys = keys | prev_keys;
|
|
||||||
// Send event_t as void * message to use with OSQPost
|
|
||||||
event_t event;
|
|
||||||
event.type = EVENT_KBD;
|
|
||||||
event.payload = msg.value;
|
|
||||||
// Send keyboard status in queue
|
|
||||||
OSQPost(&ui_queue, (void *)event.value, sizeof(event_t),
|
|
||||||
OS_OPT_POST_FIFO + OS_OPT_POST_NO_SCHED, &os_err);
|
|
||||||
}
|
|
||||||
// Save current keyboard state as previous
|
|
||||||
prev_keys = keys;
|
|
||||||
}
|
}
|
||||||
// Read keyboard state at 20Hz
|
// Read keyboard state at 20Hz
|
||||||
OSTimeDlyHMSM(0u, 0u, 0u, 50u, OS_OPT_TIME_HMSM_STRICT, &os_err);
|
OSTimeDlyHMSM(0u, 0u, 0u, 50u, OS_OPT_TIME_HMSM_STRICT, &os_err);
|
||||||
|
|
Ładowanie…
Reference in New Issue