diff -r ec507c1f1df7 -r cdf68044adaf brewpanel/brewpanel.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/brewpanel/brewpanel.c Sat Nov 07 22:04:17 2015 +0100 @@ -0,0 +1,164 @@ +/***************************************************************************** + * Copyright (C) 2015 + * + * Michiel Broek + * + * This file is part of the mbsePi-apps + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * mbsePi-apps is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with ThermFerm; see the file COPYING. If not, write to the Free + * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + *****************************************************************************/ + +#include "brewpanel.h" +#include "sdlgui.h" +#include "dlgBrew.h" + + +int DebugPanel = FALSE; /* Logfile debugging */ +int debug = FALSE; /* Console debugging */ +int my_shutdown = FALSE; /* Shutdown requested */ +char *Paneltype = NULL; /* Panel to emulate */ +int PAN_x; /* Screen X size */ +int PAN_y; /* Screen Y size */ + +int LCD_fcol; /* LCD foreground color */ +int LCD_bcol; /* LCD background color */ + +SDL_Surface *PAN_surface = NULL; /* Main surface */ + + +void help(void) +{ + fprintf(stdout, "Usage: brewpanel [-d] [-h] [-p ]\n"); + fprintf(stdout, " -d --debug Debug on\n"); + fprintf(stdout, " -h --help Display this help\n"); + fprintf(stdout, " -p --paneltype Select machine, default last used\n"); +} + + + +void die(int onsig) +{ + switch (onsig) { + case SIGHUP: syslog(LOG_NOTICE, "Got SIGHUP, shutting down"); + break; + case SIGINT: syslog(LOG_NOTICE, "Keyboard interrupt, shutting down"); + break; + case SIGTERM: syslog(LOG_NOTICE, "Got SIGTERM, shutting down"); + break; + case SIGSEGV: syslog(LOG_NOTICE, "Got SIGSEGV, shutting down"); + my_shutdown = TRUE; + exit(SIGSEGV); + break; + default: syslog(LOG_NOTICE, "die() on signal %d", onsig); + } + + my_shutdown = TRUE; +} + + + +int main(int argc, char *argv[]) +{ + int i, rc = 0, c, max_x = 0, max_y = 0; + SDL_Rect **modes; + char title[81]; + + Paneltype = calloc(128, sizeof(char)); + + while (1) { + int option_index = 0; + static struct option long_options[] = { + {"debug", 0, 0, 'c'}, + {"help", 0, 0, 'h'}, + {"paneltype", 1, 0, 'p'}, + {0, 0, 0, 0} + }; + + c = getopt_long(argc, argv, "dhp:", long_options, &option_index); + if (c == -1) + break; + + switch (c) { + case 'd': DebugPanel = TRUE; + break; + case 'h': help(); + return 1; + case 'p': snprintf(Paneltype, 127, "%s", optarg); + break; + } + } + + openlog("brewpanel", LOG_PID|LOG_CONS|LOG_NOWAIT, LOG_USER); + syslog(LOG_NOTICE, "mbsePi-apps brewpanel v%s starting", VERSION); + if (debug) + fprintf(stdout, "mbsePi-apps brewpanel v%s starting\n", VERSION); + + /* + * Catch all the signals we can, and ignore the rest. Note that SIGKILL can't be ignored + * but that's live. This daemon should only be stopped by SIGTERM. + * Don't catch SIGCHLD. + */ + for (i = 0; i < NSIG; i++) { + if ((i != SIGCHLD) && (i != SIGKILL) && (i != SIGSTOP)) + signal(i, (void (*))die); + } + + /* + * Initialize defaults, Video and Audio + */ + if ((SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO) == -1)) { + syslog(LOG_NOTICE, "[main] could not initialize SDL: %s", SDL_GetError()); + exit(-1); + } + + modes = SDL_ListModes(NULL, SDL_FULLSCREEN); + if (modes != (SDL_Rect **)0) { + /* Check if our resolution is restricted */ + if (modes == (SDL_Rect **)-1) { + syslog(LOG_NOTICE, "SDL all resolutions available.\n"); + } else { + max_x = modes[0]->w; + max_y = modes[0]->h; + } + } + + PAN_x = 384; + PAN_y = 480; + +fprintf(stdout, "Screen max X*Y: %d*%d panel X*Y: %d*%d\n", max_x, max_y, PAN_x, PAN_y); + + PAN_surface = SDL_SetVideoMode( PAN_x, PAN_y, 32, SDL_SWSURFACE|SDL_DOUBLEBUF ); + if (PAN_surface == NULL) { + syslog(LOG_NOTICE, "Could not create main surface: %s", SDL_GetError()); + exit(-1); + } + + SDLGui_Init(); + snprintf(title, 80, "brewpanel v%s", VERSION); + SDL_WM_SetCaption(title, NULL); + + syslog(LOG_NOTICE, "Starting mainloop"); + Dialog_BrewDlg(); + syslog(LOG_NOTICE, "Out of mainloop, cleanup"); + + SDLGui_UnInit(); + SDL_FreeSurface(PAN_surface); + SDL_Quit(); + + syslog(LOG_NOTICE, "Finished, rc=%d", rc); + return 0; +} + +