Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
BuffyBox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
postmarketOS
BuffyBox
Commits
18b576f2
Commit
18b576f2
authored
1 week ago
by
Johannes Marbach
Browse files
Options
Downloads
Plain Diff
Merge branch 'main_loop' into 'master'
unl0kr: optimize the main loop See merge request
!38
parents
d5838377
3613ba4e
No related branches found
Branches containing commit
Tags
unl0kr-1.0.0
Tags containing commit
1 merge request
!38
unl0kr: optimize the main loop
Pipeline
#217808
passed
1 week ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
unl0kr/main.c
+26
-21
26 additions, 21 deletions
unl0kr/main.c
with
27 additions
and
21 deletions
CHANGELOG.md
+
1
−
0
View file @
18b576f2
...
...
@@ -22,6 +22,7 @@ If a change only affects particular applications, they are listed in parentheses
-
fix(unl0kr): Select an available DRM device instead of a hard-coded one (!35, thanks @Sorcus)
-
feat(unl0kr): Enable software rotation (!32, thanks @xs5871 & @craftyguy)
-
misc: do not hardcode endianess of a system (!41, thanks @vstoiakin)
-
misc(unl0kr): Optimize the main loop (!38, thanks @vstoiakin)
## 3.2.0 (2024-06-03)
...
...
This diff is collapsed.
Click to expand it.
unl0kr/main.c
+
26
−
21
View file @
18b576f2
...
...
@@ -18,7 +18,6 @@
#include
"lvgl/lvgl.h"
#include
<pthread.h>
#include
<signal.h>
#include
<stdio.h>
#include
<stdlib.h>
...
...
@@ -49,11 +48,9 @@ lv_obj_t *keyboard = NULL;
*/
/**
* Function to invoke in the tick generation thread.
*
* @param args unused
* Provides the number of milliseconds for LVGL timers
*/
static
void
*
tick_thread
(
void
*
args
);
static
uint32_t
millis
(
);
/**
* Handle LV_EVENT_CLICKED events from the theme toggle button.
...
...
@@ -201,13 +198,10 @@ static void sigaction_handler(int signum);
*/
static
void
*
tick_thread
(
void
*
args
)
{
LV_UNUSED
(
args
);
while
(
1
)
{
usleep
(
5
*
1000
);
/* Sleep for 5 millisecond */
lv_tick_inc
(
5
);
/* Tell LVGL that 5 milliseconds have elapsed */
}
return
NULL
;
static
uint32_t
millis
()
{
struct
timespec
ts
;
clock_gettime
(
CLOCK_MONOTONIC
,
&
ts
);
return
ts
.
tv_sec
*
1000
+
ts
.
tv_nsec
/
1000000
;
}
static
void
toggle_theme_btn_clicked_cb
(
lv_event_t
*
event
)
{
...
...
@@ -380,6 +374,13 @@ int main(int argc, char *argv[]) {
/* Announce ourselves */
bbx_log
(
BBX_LOG_LEVEL_VERBOSE
,
"unl0kr %s"
,
PROJECT_VERSION
);
/* Check that we have access to the clock */
struct
timespec
ts
;
if
(
clock_gettime
(
CLOCK_MONOTONIC
,
&
ts
)
==
-
1
)
{
bbx_log
(
BBX_LOG_LEVEL_ERROR
,
"Unable to read the clock"
);
exit
(
EXIT_FAILURE
);
}
/* Parse config files */
ul_config_init_opts
(
&
conf_opts
);
ul_config_parse_file
(
"/usr/share/unl0kr/unl0kr.conf"
,
&
conf_opts
);
...
...
@@ -399,10 +400,7 @@ int main(int argc, char *argv[]) {
/* Initialise LVGL and set up logging callback */
lv_init
();
lv_log_register_print_cb
(
bbx_log_print_cb
);
/* Start the tick thread */
pthread_t
ticker
;
pthread_create
(
&
ticker
,
NULL
,
tick_thread
,
NULL
);
lv_tick_set_cb
(
millis
);
/* Initialise display */
lv_display_t
*
disp
=
NULL
;
...
...
@@ -610,12 +608,19 @@ int main(int argc, char *argv[]) {
/* Periodically run timer / task handler */
uint32_t
timeout
=
conf_opts
.
general
.
timeout
*
1000
;
/* ms */
while
(
1
)
{
if
(
!
timeout
||
lv_disp_get_inactive_time
(
NULL
)
<
timeout
)
{
uint32_t
time_till_next
=
lv_timer_handler
();
usleep
(
time_till_next
*
1000
);
}
else
if
(
timeout
)
{
shutdown
();
uint32_t
time_till_next
=
lv_timer_handler
();
if
(
timeout
!=
0
)
{
uint32_t
time_idle
=
lv_display_get_inactive_time
(
NULL
);
if
(
time_idle
>=
timeout
)
shutdown
();
uint32_t
time_till_shutdown
=
timeout
-
time_idle
;
if
(
time_till_shutdown
<
time_till_next
)
time_till_next
=
time_till_shutdown
;
}
usleep
(
time_till_next
*
1000
);
}
return
0
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment