Skip to content

Commit

Permalink
demo/high_res: remove bug causing 100% CPU utilization of one core
Browse files Browse the repository at this point in the history
Add delay while polling for the status of play/pause button in the audio thread

Signed-off-by: Divyansh Mittal <[email protected]>
  • Loading branch information
Divyansh Mittal committed Feb 3, 2025
1 parent 6c3f1ce commit 325872b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions demos/high_res/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ void *audio_play() {
pcm = snd_pcm_pause(pcm_handle, 1);
}
pthread_mutex_unlock(&playing_now_lock);
usleep(250000);
}

if (pcm = read(fd, buff, buff_size) == 0) {
Expand Down
22 changes: 11 additions & 11 deletions demos/high_res/button.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,17 @@ void *button_init(lv_demo_high_res_api_t * api)
int last_val=-1;
int curr_val=-1;
while (read(fd, &ie, sizeof(struct input_event))) {
if(ie.type != 1)
continue;
curr_val = ie.value;
if(curr_val==0 && last_val > 0){
fprintf(stderr, "Button Released!!\n");
lv_lock();
int lock_status = lv_subject_get_int(&api->subjects.locked);
lv_subject_set_int(&api->subjects.locked, !lock_status);
lv_unlock();
}
last_val = curr_val;
if(ie.type != 1)
continue;
curr_val = ie.value;
if(curr_val==0 && last_val > 0){
fprintf(stderr, "Button Released!!\n");
lv_lock();
int lock_status = lv_subject_get_int(&api->subjects.locked);
lv_subject_set_int(&api->subjects.locked, !lock_status);
lv_unlock();
}
last_val = curr_val;
}

close(fd);
Expand Down

0 comments on commit 325872b

Please sign in to comment.