2009-02-10 18:37:48 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004 Kimmo Pekkola
|
|
|
|
|
|
|
|
This program 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
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program 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 this program; if not, write to the Free Software
|
2012-01-23 06:36:15 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-02-10 18:37:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <windows.h>
|
2012-01-08 17:35:29 +00:00
|
|
|
#include <stdio.h>
|
2011-02-03 18:09:24 +00:00
|
|
|
#include "../../Library/Export.h" // Rainmeter's exported functions
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-02-03 18:09:24 +00:00
|
|
|
#include "../../Library/DisableThreadLibraryCalls.h" // contains DllMain entry point
|
2011-01-30 09:31:41 +00:00
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
#pragma pack(push, 1)
|
2011-03-29 19:21:57 +00:00
|
|
|
struct SpeedFanData
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
WORD version;
|
|
|
|
WORD flags;
|
|
|
|
INT MemSize;
|
|
|
|
DWORD handle;
|
|
|
|
WORD NumTemps;
|
|
|
|
WORD NumFans;
|
|
|
|
WORD NumVolts;
|
|
|
|
INT temps[32];
|
|
|
|
INT fans[32];
|
|
|
|
INT volts[32];
|
|
|
|
};
|
2012-01-08 17:35:29 +00:00
|
|
|
#pragma pack(pop)
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
enum SensorType
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
TYPE_TEMP,
|
|
|
|
TYPE_FAN,
|
|
|
|
TYPE_VOLT
|
|
|
|
};
|
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
enum ScaleType
|
2010-05-09 17:14:20 +00:00
|
|
|
{
|
2010-06-02 14:47:41 +00:00
|
|
|
SCALE_SOURCE,
|
2010-05-09 17:14:20 +00:00
|
|
|
SCALE_CENTIGRADE,
|
|
|
|
SCALE_FARENHEIT,
|
|
|
|
SCALE_KELVIN
|
|
|
|
};
|
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
struct MeasureData
|
|
|
|
{
|
|
|
|
SensorType type;
|
|
|
|
ScaleType scale;
|
|
|
|
UINT number;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
MeasureData() : type(TYPE_TEMP), scale(SCALE_SOURCE), number() {}
|
|
|
|
};
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
void ReadSharedData(SensorType type, ScaleType scale, UINT number, double* value);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-02-02 07:39:14 +00:00
|
|
|
PLUGIN_EXPORT void Initialize(void** data, void* rm)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
MeasureData* measure = new MeasureData;
|
|
|
|
*data = measure;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLUGIN_EXPORT void Reload(void* data, void* rm, double* maxValue)
|
|
|
|
{
|
|
|
|
MeasureData* measure = (MeasureData*)data;
|
|
|
|
|
|
|
|
LPCWSTR type = RmReadString(rm, L"SpeedFanType", L"TEMPERATURE");
|
|
|
|
if (_wcsicmp(L"TEMPERATURE", type) == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
measure->type = TYPE_TEMP;
|
2010-05-09 17:14:20 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
LPCWSTR scale = RmReadString(rm, L"SpeedFanScale", L"C");
|
|
|
|
if (_wcsicmp(L"C", scale) == 0)
|
|
|
|
{
|
|
|
|
measure->scale = SCALE_CENTIGRADE;
|
2011-03-29 19:21:57 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
else if (_wcsicmp(L"F", scale) == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
measure->scale = SCALE_FARENHEIT;
|
2011-03-29 19:21:57 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
else if (_wcsicmp(L"K", scale) == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
measure->scale = SCALE_KELVIN;
|
2011-03-29 19:21:57 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
else
|
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
WCHAR buffer[256];
|
|
|
|
_snwprintf_s(buffer, _TRUNCATE, L"SpeedFanPlugin.dll: SpeedFanScale=%s is not valid in [%s]", scale, RmGetMeasureName(rm));
|
|
|
|
RmLog(LOG_ERROR, buffer);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
else if (_wcsicmp(L"FAN", type) == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
measure->type = TYPE_FAN;
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
2012-01-08 17:35:29 +00:00
|
|
|
else if (_wcsicmp(L"VOLTAGE", type) == 0)
|
2010-06-02 14:47:41 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
measure->type = TYPE_VOLT;
|
2010-06-02 14:47:41 +00:00
|
|
|
}
|
|
|
|
else
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
WCHAR buffer[256];
|
|
|
|
_snwprintf_s(buffer, _TRUNCATE, L"SpeedFanPlugin.dll: SpeedFanType=%s is not valid in [%s]", type, RmGetMeasureName(rm));
|
|
|
|
RmLog(LOG_ERROR, buffer);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
measure->number = RmReadInt(rm, L"SpeedFanNumber", 0);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
PLUGIN_EXPORT double Update(void* data)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
MeasureData* measure = (MeasureData*)data;
|
|
|
|
double value = 0.0;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
ReadSharedData(measure->type, measure->scale, measure->number, &value);
|
2010-05-09 17:14:20 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
PLUGIN_EXPORT void Finalize(void* data)
|
|
|
|
{
|
|
|
|
MeasureData* measure = (MeasureData*)data;
|
|
|
|
delete measure;
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Get the data from shared memory.
|
|
|
|
*/
|
2012-01-08 17:35:29 +00:00
|
|
|
void ReadSharedData(SensorType type, ScaleType scale, UINT number, double* value)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
HANDLE hData = OpenFileMapping(FILE_MAP_READ, FALSE, L"SFSharedMemory_ALM");
|
|
|
|
if (hData == NULL) return;
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2012-01-08 17:35:29 +00:00
|
|
|
SpeedFanData* ptr = (SpeedFanData*)MapViewOfFile(hData, FILE_MAP_READ, 0, 0, 0);
|
2009-02-10 18:37:48 +00:00
|
|
|
if (ptr == 0)
|
|
|
|
{
|
|
|
|
CloseHandle(hData);
|
2012-01-08 17:35:29 +00:00
|
|
|
return;
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr->version == 1)
|
|
|
|
{
|
2011-03-29 19:21:57 +00:00
|
|
|
switch(type)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
case TYPE_TEMP:
|
|
|
|
if (number < ptr->NumTemps)
|
|
|
|
{
|
|
|
|
*value = ptr->temps[number];
|
|
|
|
*value /= 100.0;
|
2010-05-09 17:14:20 +00:00
|
|
|
|
|
|
|
if (scale == SCALE_FARENHEIT)
|
|
|
|
{
|
|
|
|
*value *= 1.8;
|
|
|
|
*value += 32.0;
|
|
|
|
}
|
|
|
|
else if (scale == SCALE_KELVIN)
|
|
|
|
{
|
|
|
|
*value += 273.15;
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_FAN:
|
|
|
|
if (number < ptr->NumTemps)
|
|
|
|
{
|
|
|
|
*value = ptr->fans[number];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TYPE_VOLT:
|
|
|
|
if (number < ptr->NumVolts)
|
|
|
|
{
|
|
|
|
*value = ptr->volts[number];
|
|
|
|
*value /= 100.0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-01-08 17:35:29 +00:00
|
|
|
RmLog(LOG_ERROR, L"SpeedFanPlugin.dll: Incorrect shared memory version");
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UnmapViewOfFile(ptr);
|
|
|
|
CloseHandle(hData);
|
|
|
|
}
|