plugins/fans/scrFans.c

00001 /*
00002  * Copyright Ian Burnett 2005, 2006.
00003  *
00004  * This file is part of Ian's Interactive LCD controller (IILC).
00005  * 
00006  * IILC is free software; you can redistribute it and/or modify it under
00007  * the terms of the GNU General Public License as published by the Free
00008  * Software Foundation; either version 2 of the License, or (at your
00009  * option) any later version.
00010  *
00011  * IILC is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00014  * for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License along
00017  * with IILC; if not, write to the Free Software Foundation, Inc.,
00018  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
00019  */
00020 
00021 #include <time.h>
00022 #include <string.h>
00023 
00024 #if !defined(_WIN32)
00025 #   include <strings.h>
00026 #endif
00027 
00028 #include "lcd.h"
00029 #include "module.h"
00030 #include "screen.h"
00031 #include "trace.h"
00032 
00033 #define IILC_MODULE MODULE_TYPE_DISPLAY
00034 
00035 LCD_API int ModuleCreate(int handle,
00036                          void ** context,
00037                          LPMODULE_FN_ARRAY pFnArray);
00038 
00039 LCD_API int ModuleDestroy(void * context);
00040 
00041 
00042 LCD_API int GetDisplayData(void * context,
00043                            int row,
00044                            int nWidth,
00045                            char * buf);
00046 
00047 
00048 typedef struct _tag_screen_fans
00049 {
00051     unsigned int nFanCount;
00052 
00054     unsigned int * rpmList;
00055 
00057     char ** pszOutput;
00058 
00059 } SCREEN_FANS, * LPSCREEN_FANS;
00060 
00061 
00062 /* ----- Internal function definitions ----- */
00063 
00064 
00065 void fanSpeedReport(void * context, 
00066                     unsigned int fan_id, 
00067                     unsigned int fan_speed,
00068                     const char * pszName);
00069 
00070 
00071 /* ----- Implementation ----- */
00072 
00073 
00074 
00075 int ModuleCreate(int handle, void ** context, LPMODULE_FN_ARRAY pFnArray)
00076 {
00077     int rc = 0;
00078 
00079     LPSCREEN_FANS pInst = NULL;
00080 
00081     /* Create our own scratch space */
00082     pInst = malloc(sizeof(SCREEN_FANS));
00083     if (pInst == NULL) {
00084         printf("malloc() failed in Fans module create");
00085         rc = -1;
00086         goto end_of_function;
00087     }
00088 
00089     /* Default to looking after four fans */
00090     pInst->nFanCount = 4;
00091 
00092     /* Zero out the array contents */
00093     pInst->rpmList = calloc(pInst->nFanCount, sizeof(unsigned int));
00094 
00095     /* --- Populate the function array data --- */
00096 
00097     /* We can use fn array version 1 */
00098     pFnArray->version = 1;
00099 
00100     /* Setup our various functions */
00101     pFnArray->pfnTextData = GetDisplayData;
00102     pFnArray->pfnFanSpeedReport = fanSpeedReport;
00103 
00104     /* --- */
00105 
00106     /* Return context data back to the caller */
00107     *context = pInst;
00108 
00109 end_of_function:
00110 
00111     return rc;
00112 }
00113 
00114 
00115 int ModuleDestroy(void * context)
00116 {
00117     LPSCREEN_FANS pInst = (LPSCREEN_FANS) context;
00118 
00119     free(pInst);
00120 
00121     return 0;
00122 }
00123 
00124 
00125 void temperatureReport(void * context, unsigned int sensor_id, double degrees_c, const char * pszName)
00126 {
00127     IILC_TRACE_ENTRY(IILC_MODULE, T_temperatureReport);
00128 
00129     traceInfo(IILC_TRACE_CONTEXT, "(FANS) Temperature report for sensor [%10s] at %.0fC", pszName, degrees_c);
00130 
00131     IILC_TRACE_EXIT;
00132 }
00133 
00134 
00135 
00136 void fanSpeedReport(void * context, unsigned int fan_id, unsigned int fan_speed, const char * pszName)
00137 {
00138     LPSCREEN_FANS pInst = NULL;
00139         
00140     IILC_TRACE_ENTRY(IILC_MODULE, T_fanSpeedReport);
00141 
00142     /* Grab the instance data */
00143     pInst = (LPSCREEN_FANS) context;
00144 
00145     switch (fan_speed) {
00146     case 0:
00147     case 1:
00148     case 0xFFFFFFFF:
00149         pInst->rpmList[fan_id] = fan_speed;
00150         break;
00151 
00152     /* Save the RPM data in some shared storage (round to nearest 100) */
00153     default:
00154         pInst->rpmList[fan_id] = fan_speed - ((fan_speed - 50) % 100) + 50;
00155         break;
00156     }
00157 
00158     traceInfo(IILC_TRACE_CONTEXT, "(FANS) Fan speed report of sensor    [%10s] at %u RPM", pszName, fan_speed);
00159     
00160     IILC_TRACE_EXIT;
00161 }
00162 
00163 
00164 
00165 int GetDisplayData(void * context, int row, int nWidth, char * buf)
00166 {
00167     /* Return code */
00168     int rc = 0;
00169 
00170     /* This module instance */
00171     LPSCREEN_FANS pInstance = (LPSCREEN_FANS) context;
00172 
00173     switch (pInstance->rpmList[row]) {
00174 
00175     case 0: /* Stopped */
00176         sprintf(buf, "FAN %u: STOPPED", row);
00177         break;
00178 
00179     case 1: /* Below measurable limits */
00180         sprintf(buf, "FAN %u: SLOW", row);
00181         break;
00182 
00183     case 0xFFFFFFFF: /* Over-limit */
00184         sprintf(buf, "FAN %u: ---- RPM", row);
00185         break;
00186 
00187     default:
00188         sprintf(buf, "FAN %u: %4u RPM", row, pInstance->rpmList[row]);
00189         break;
00190     }
00191 
00192     return rc;
00193 }

Generated on Mon Jul 17 01:36:11 2006 for IILC by  doxygen 1.4.6