From 4479ad454c28305040f0eb05bce332588efc547f Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Fri, 1 Feb 2019 15:20:27 -0500 Subject: Allow for clean quits. --- aldl_pi.c | 6 ++++-- sdldash.c | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/aldl_pi.c b/aldl_pi.c index c4a5ea7..2a74809 100644 --- a/aldl_pi.c +++ b/aldl_pi.c @@ -52,6 +52,8 @@ void delayfn(int ms) /* Main */ int main (int argc, char **argv) { + int run = 1; + /* Set up RPi GPIO */ wiringPiSetup(); @@ -65,8 +67,8 @@ int main (int argc, char **argv) if (init_dash()) return -1; - while(1) { - render_dash(); + while(run) { + run = render_dash(); sleep(1); } diff --git a/sdldash.c b/sdldash.c index 1f4ed69..3d5036b 100644 --- a/sdldash.c +++ b/sdldash.c @@ -146,6 +146,9 @@ int render_dash(void) { SDL_Rect DestR; char txtbuf[64]; + if (SDL_QuitRequested()) + return 0; + /* Clear with black */ SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); SDL_RenderClear(renderer); @@ -219,5 +222,6 @@ done: if (drawn_tex[i]) SDL_DestroyTexture(drawn_tex[i]); } - return 0; + + return 1; } -- cgit v1.2.3