aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
blob: bac0cd6466c020f5fd1b3ad1834f373e01d6a11e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "display.h"
#include "clock.h"
#include "logger.h"
#include "system.h"
#include "signal.h"
#include "strings33.h"
#include "ui33.h"

static void _term_sighandler( int sig );


int main(int argc, char *argv[])
{
  Size fps, FPS;
  long timeOld, time;

  if( e33_set_signal( SIGHUP, _term_sighandler ) == -1 ) { logw( "SIGHUP not handled"); }
  if( e33_set_signal( SIGINT, _term_sighandler ) == -1 ) { logw( "SIGINT not handled"); }
  if( e33_set_signal( SIGTERM, _term_sighandler ) == -1 ) { logw( "SIGTERM not handled"); }

  timeOld = clock_get_us();
  time = 0;
  fps = 0;
  FPS = 0;

  if( logger_init() ) {
    return EXIT_FAILURE;
  }

  if( display_init() ) {
    return EXIT_FAILURE;
  }

  logd( "This is a test." );

  while(1)
  {
    display_vtswitcher_poll(1);


    if( __display.active )
    {
      qsuprintf( 5, 5, "fps: %d", FPS-1 );

      ui_draw_messages();

      display_flip();
    }


    time += clock_get_us() - timeOld;
    timeOld = clock_get_us();

    if(time >= 1000000)
    {
      FPS = fps;
      time = 0;
      fps = 0;
    }
    ++fps;
  }

  display_term();
  logger_term();


  return EXIT_SUCCESS;
}


static void _term_sighandler( int sig )
{
  display_term();
  logger_term();
  exit(0);
}