plugins/leds/scrLED.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 
00023 #if defined(_WIN32)
00024 #else
00025 #   include <strings.h>
00026 #endif
00027 
00028 #include "scrLED.h"
00029 
00030 typedef struct _tag_screen_fans
00031 {
00033     unsigned int fanCount;
00034 
00036     unsigned int * rpmList;
00037 
00038 } SCREEN_FANS, * LPSCREEN_FANS;
00039 
00040 
00041 /* ----- Internal function definitions ----- */
00042 
00043 
00044 int fanSpeedReport(void * context, 
00045                    unsigned int fan_id, 
00046                    unsigned int fan_speed);
00047 
00048 
00049 /* ----- Implementation ----- */
00050 
00051 
00052 
00053 int ModuleCreate(int handle, void ** context, LPMODULE_FN_ARRAY pFnArray)
00054 {
00055     int rc = 0;
00056 
00057     LPSCREEN_FANS pInst = NULL;
00058 
00059     /* Create our own scratch space */
00060     pInst = malloc(sizeof(SCREEN_FANS));
00061     if (pInst == NULL) {
00062         printf("malloc() failed in Fans module create");
00063         rc = -1;
00064         goto end_of_function;
00065     }
00066 
00067     /* Default to looking after one fan */
00068     pInst->fanCount = 1;
00069 
00070     /* Zero out the array contents */
00071     pInst->rpmList = calloc(pInst->fanCount, sizeof(unsigned int));
00072 
00073     /* --- Populate the function array data --- */
00074 
00075     /* We can use fn array version 1 */
00076     pFnArray->version = 1;
00077 
00078     /* Setup our various functions */
00079     pFnArray->pfnTextData = GetDisplayData;
00080     pFnArray->pfnReadLEDStatus = GetLEDStatus;
00081 
00082     /* --- */
00083 
00084     /* Return context data back to the caller */
00085     *context = pInst;
00086 
00087 end_of_function:
00088 
00089     return rc;
00090 }
00091 
00092 
00093 int ModuleDestroy(void * context)
00094 {
00095     LPSCREEN_FANS pInst = (LPSCREEN_FANS) context;
00096 
00097     free(pInst);
00098 
00099     return 0;
00100 }
00101 
00102 
00103 int GetDisplayData(void * context, LPSCREEN pScreen, char ** buf)
00104 {
00105     LPSCREEN_FANS pInstance = (LPSCREEN_FANS) context;
00106 
00107     char * lfChar = NULL;
00108  
00109     /* Grab the last fan report we received */
00110     sprintf(*buf, "FAN %u: %u RPM", 0, pInstance->rpmList[0]);
00111     
00112     return 0;
00113 }
00114 
00115 int GetLEDStatus(void * context, unsigned int led_id,
00116                  LPCOLOUR pColourOn, LPCOLOUR pColourOff,
00117                  unsigned int * pDutyCycle, unsigned int * pFreq)
00118 {
00119     SET_COLOUR(pColourOn, 100, 0, 0);
00120     SET_COLOUR(pColourOff,  0, 100, 0);
00121     
00122     /* Simple 50% on, 50% off */
00123     *pDutyCycle = 50;
00124 
00125     /* Reasonably slow flash rate (1 Hz) */
00126     *pFreq = 50 + (25 * led_id);
00127 
00128     return 0;
00129 }
00130 

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