00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00063
00064
00065 void fanSpeedReport(void * context,
00066 unsigned int fan_id,
00067 unsigned int fan_speed,
00068 const char * pszName);
00069
00070
00071
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
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
00090 pInst->nFanCount = 4;
00091
00092
00093 pInst->rpmList = calloc(pInst->nFanCount, sizeof(unsigned int));
00094
00095
00096
00097
00098 pFnArray->version = 1;
00099
00100
00101 pFnArray->pfnTextData = GetDisplayData;
00102 pFnArray->pfnFanSpeedReport = fanSpeedReport;
00103
00104
00105
00106
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
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
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
00168 int rc = 0;
00169
00170
00171 LPSCREEN_FANS pInstance = (LPSCREEN_FANS) context;
00172
00173 switch (pInstance->rpmList[row]) {
00174
00175 case 0:
00176 sprintf(buf, "FAN %u: STOPPED", row);
00177 break;
00178
00179 case 1:
00180 sprintf(buf, "FAN %u: SLOW", row);
00181 break;
00182
00183 case 0xFFFFFFFF:
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 }