|
1 /***************************************************************************** |
|
2 * Copyright (C) 2015 |
|
3 * |
|
4 * Michiel Broek <mbroek at mbse dot eu> |
|
5 * |
|
6 * This file is part of the mbsePi-apps |
|
7 * |
|
8 * This is free software; you can redistribute it and/or modify it |
|
9 * under the terms of the GNU General Public License as published by the |
|
10 * Free Software Foundation; either version 2, or (at your option) any |
|
11 * later version. |
|
12 * |
|
13 * mbsePi-apps is distributed in the hope that it will be useful, but |
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
16 * General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with ThermFerm; see the file COPYING. If not, write to the Free |
|
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
21 *****************************************************************************/ |
|
22 |
|
23 #include "brewpanel.h" |
|
24 #include "sdlgui.h" |
|
25 #include "dlgBrew.h" |
|
26 |
|
27 |
|
28 int DebugPanel = FALSE; /* Logfile debugging */ |
|
29 int debug = FALSE; /* Console debugging */ |
|
30 int my_shutdown = FALSE; /* Shutdown requested */ |
|
31 char *Paneltype = NULL; /* Panel to emulate */ |
|
32 int PAN_x; /* Screen X size */ |
|
33 int PAN_y; /* Screen Y size */ |
|
34 |
|
35 int LCD_fcol; /* LCD foreground color */ |
|
36 int LCD_bcol; /* LCD background color */ |
|
37 |
|
38 SDL_Surface *PAN_surface = NULL; /* Main surface */ |
|
39 |
|
40 |
|
41 void help(void) |
|
42 { |
|
43 fprintf(stdout, "Usage: brewpanel [-d] [-h] [-p <paneltype>]\n"); |
|
44 fprintf(stdout, " -d --debug Debug on\n"); |
|
45 fprintf(stdout, " -h --help Display this help\n"); |
|
46 fprintf(stdout, " -p --paneltype <ferm|brew> Select machine, default last used\n"); |
|
47 } |
|
48 |
|
49 |
|
50 |
|
51 void die(int onsig) |
|
52 { |
|
53 switch (onsig) { |
|
54 case SIGHUP: syslog(LOG_NOTICE, "Got SIGHUP, shutting down"); |
|
55 break; |
|
56 case SIGINT: syslog(LOG_NOTICE, "Keyboard interrupt, shutting down"); |
|
57 break; |
|
58 case SIGTERM: syslog(LOG_NOTICE, "Got SIGTERM, shutting down"); |
|
59 break; |
|
60 case SIGSEGV: syslog(LOG_NOTICE, "Got SIGSEGV, shutting down"); |
|
61 my_shutdown = TRUE; |
|
62 exit(SIGSEGV); |
|
63 break; |
|
64 default: syslog(LOG_NOTICE, "die() on signal %d", onsig); |
|
65 } |
|
66 |
|
67 my_shutdown = TRUE; |
|
68 } |
|
69 |
|
70 |
|
71 |
|
72 int main(int argc, char *argv[]) |
|
73 { |
|
74 int i, rc = 0, c, max_x = 0, max_y = 0; |
|
75 SDL_Rect **modes; |
|
76 char title[81]; |
|
77 |
|
78 Paneltype = calloc(128, sizeof(char)); |
|
79 |
|
80 while (1) { |
|
81 int option_index = 0; |
|
82 static struct option long_options[] = { |
|
83 {"debug", 0, 0, 'c'}, |
|
84 {"help", 0, 0, 'h'}, |
|
85 {"paneltype", 1, 0, 'p'}, |
|
86 {0, 0, 0, 0} |
|
87 }; |
|
88 |
|
89 c = getopt_long(argc, argv, "dhp:", long_options, &option_index); |
|
90 if (c == -1) |
|
91 break; |
|
92 |
|
93 switch (c) { |
|
94 case 'd': DebugPanel = TRUE; |
|
95 break; |
|
96 case 'h': help(); |
|
97 return 1; |
|
98 case 'p': snprintf(Paneltype, 127, "%s", optarg); |
|
99 break; |
|
100 } |
|
101 } |
|
102 |
|
103 openlog("brewpanel", LOG_PID|LOG_CONS|LOG_NOWAIT, LOG_USER); |
|
104 syslog(LOG_NOTICE, "mbsePi-apps brewpanel v%s starting", VERSION); |
|
105 if (debug) |
|
106 fprintf(stdout, "mbsePi-apps brewpanel v%s starting\n", VERSION); |
|
107 |
|
108 /* |
|
109 * Catch all the signals we can, and ignore the rest. Note that SIGKILL can't be ignored |
|
110 * but that's live. This daemon should only be stopped by SIGTERM. |
|
111 * Don't catch SIGCHLD. |
|
112 */ |
|
113 for (i = 0; i < NSIG; i++) { |
|
114 if ((i != SIGCHLD) && (i != SIGKILL) && (i != SIGSTOP)) |
|
115 signal(i, (void (*))die); |
|
116 } |
|
117 |
|
118 /* |
|
119 * Initialize defaults, Video and Audio |
|
120 */ |
|
121 if ((SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO) == -1)) { |
|
122 syslog(LOG_NOTICE, "[main] could not initialize SDL: %s", SDL_GetError()); |
|
123 exit(-1); |
|
124 } |
|
125 |
|
126 modes = SDL_ListModes(NULL, SDL_FULLSCREEN); |
|
127 if (modes != (SDL_Rect **)0) { |
|
128 /* Check if our resolution is restricted */ |
|
129 if (modes == (SDL_Rect **)-1) { |
|
130 syslog(LOG_NOTICE, "SDL all resolutions available.\n"); |
|
131 } else { |
|
132 max_x = modes[0]->w; |
|
133 max_y = modes[0]->h; |
|
134 } |
|
135 } |
|
136 |
|
137 PAN_x = 384; |
|
138 PAN_y = 480; |
|
139 |
|
140 fprintf(stdout, "Screen max X*Y: %d*%d panel X*Y: %d*%d\n", max_x, max_y, PAN_x, PAN_y); |
|
141 |
|
142 PAN_surface = SDL_SetVideoMode( PAN_x, PAN_y, 32, SDL_SWSURFACE|SDL_DOUBLEBUF ); |
|
143 if (PAN_surface == NULL) { |
|
144 syslog(LOG_NOTICE, "Could not create main surface: %s", SDL_GetError()); |
|
145 exit(-1); |
|
146 } |
|
147 |
|
148 SDLGui_Init(); |
|
149 snprintf(title, 80, "brewpanel v%s", VERSION); |
|
150 SDL_WM_SetCaption(title, NULL); |
|
151 |
|
152 syslog(LOG_NOTICE, "Starting mainloop"); |
|
153 Dialog_BrewDlg(); |
|
154 syslog(LOG_NOTICE, "Out of mainloop, cleanup"); |
|
155 |
|
156 SDLGui_UnInit(); |
|
157 SDL_FreeSurface(PAN_surface); |
|
158 SDL_Quit(); |
|
159 |
|
160 syslog(LOG_NOTICE, "Finished, rc=%d", rc); |
|
161 return 0; |
|
162 } |
|
163 |
|
164 |