Skip to content

Commit 314947c

Browse files
committed
Merge 'Scale for SMART1500LCDT' commit from pull #122
So far, the 3016 protocol units all seem to have this scaling issue.
2 parents 51675ab + ee25d33 commit 314947c

File tree

1 file changed

+59
-8
lines changed

1 file changed

+59
-8
lines changed

drivers/tripplite-hid.c

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
*/
4141
static double battery_scale = 1.0;
4242

43+
static double io_voltage_scale = 1.0;
44+
static double io_frequency_scale = 1.0;
45+
static double io_current_scale = 1.0;
46+
4347
/* Specific handlers for USB device matching */
4448
static void *battery_scale_1dot0(USBDevice_t *device)
4549
{
@@ -52,6 +56,14 @@ static void *battery_scale_0dot1(USBDevice_t *device)
5256
battery_scale = 0.1;
5357
return NULL;
5458
}
59+
static void *smart1500lcdt_scale(USBDevice_t *device)
60+
{
61+
battery_scale = 100000.0;
62+
io_voltage_scale = 100000.0;
63+
io_frequency_scale = 0.01;
64+
io_current_scale = 0.01;
65+
return NULL;
66+
}
5567

5668
/* TrippLite */
5769
#define TRIPPLITE_VENDORID 0x09ae
@@ -96,7 +108,7 @@ static usb_device_id_t tripplite_usb_device_table[] = {
96108
/* e.g. ? */
97109
{ USB_DEVICE(TRIPPLITE_VENDORID, 0x3015), battery_scale_1dot0 },
98110
/* e.g. TrippLite Smart1500LCD (newer unit) */
99-
{ USB_DEVICE(TRIPPLITE_VENDORID, 0x3016), battery_scale_1dot0 },
111+
{ USB_DEVICE(TRIPPLITE_VENDORID, 0x3016), smart1500lcdt_scale },
100112
/* e.g. TrippLite SmartOnline SU1500RTXL2UA (older unit?) */
101113
{ USB_DEVICE(TRIPPLITE_VENDORID, 0x4001), battery_scale_1dot0 },
102114
/* e.g. TrippLite SmartOnline SU6000RT4U? */
@@ -175,6 +187,45 @@ static info_lkp_t tripplite_battvolt[] = {
175187
{ 0, NULL, tripplite_battvolt_fun }
176188
};
177189

190+
static const char *tripplite_iovolt_fun(double value)
191+
{
192+
static char buf[8];
193+
194+
snprintf(buf, sizeof(buf), "%.1f", io_voltage_scale * value);
195+
196+
return buf;
197+
}
198+
199+
static info_lkp_t tripplite_iovolt[] = {
200+
{ 0, NULL, tripplite_iovolt_fun }
201+
};
202+
203+
static const char *tripplite_iofreq_fun(double value)
204+
{
205+
static char buf[8];
206+
207+
snprintf(buf, sizeof(buf), "%.1f", io_frequency_scale * value);
208+
209+
return buf;
210+
}
211+
212+
static info_lkp_t tripplite_iofreq[] = {
213+
{ 0, NULL, tripplite_iofreq_fun }
214+
};
215+
216+
static const char *tripplite_ioamp_fun(double value)
217+
{
218+
static char buf[8];
219+
220+
snprintf(buf, sizeof(buf), "%.1f", io_current_scale * value);
221+
222+
return buf;
223+
}
224+
225+
static info_lkp_t tripplite_ioamp[] = {
226+
{ 0, NULL, tripplite_ioamp_fun }
227+
};
228+
178229
/* --------------------------------------------------------------- */
179230
/* Vendor-specific usage table */
180231
/* --------------------------------------------------------------- */
@@ -363,9 +414,9 @@ static hid_info_t tripplite_hid2nut[] = {
363414

364415
/* Input page */
365416
{ "input.voltage.nominal", 0, 0, "UPS.PowerSummary.Input.ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL },
366-
{ "input.voltage", 0, 0, "UPS.PowerSummary.Input.Voltage", NULL, "%.1f", 0, NULL },
367-
{ "input.voltage", 0, 0, "UPS.PowerConverter.Input.Voltage", NULL, "%.1f", 0, NULL },
368-
{ "input.frequency", 0, 0, "UPS.PowerConverter.Input.Frequency", NULL, "%.1f", 0, NULL },
417+
{ "input.voltage", 0, 0, "UPS.PowerSummary.Input.Voltage", NULL, "%s", 0, tripplite_iovolt },
418+
{ "input.voltage", 0, 0, "UPS.PowerConverter.Input.Voltage", NULL, "%s", 0, tripplite_iovolt },
419+
{ "input.frequency", 0, 0, "UPS.PowerConverter.Input.Frequency", NULL, "%s", 0, tripplite_iofreq },
369420
{ "input.transfer.low", ST_FLAG_RW | ST_FLAG_STRING, 5, "UPS.PowerConverter.Output.LowVoltageTransfer", NULL, "%.1f", HU_FLAG_SEMI_STATIC, NULL },
370421
{ "input.transfer.low.max", 0, 0, "UPS.PowerConverter.Output.TLLowVoltageTransferMax", NULL, "%.0f", HU_FLAG_STATIC, NULL },
371422
{ "input.transfer.low.min", 0, 0, "UPS.PowerConverter.Output.TLLowVoltageTransferMin", NULL, "%.0f", HU_FLAG_STATIC, NULL },
@@ -375,11 +426,11 @@ static hid_info_t tripplite_hid2nut[] = {
375426

376427
/* Output page */
377428
{ "output.voltage.nominal", 0, 0, "UPS.Flow.ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL },
378-
{ "output.voltage", 0, 0, "UPS.PowerConverter.Output.Voltage", NULL, "%.1f", 0, NULL },
379-
{ "output.voltage", 0, 0, "UPS.PowerSummary.Voltage", NULL, "%.1f", 0, NULL },
380-
{ "output.current", 0, 0, "UPS.PowerConverter.Output.Current", NULL, "%.2f", 0, NULL },
429+
{ "output.voltage", 0, 0, "UPS.PowerConverter.Output.Voltage", NULL, "%s", 0, tripplite_iovolt },
430+
{ "output.voltage", 0, 0, "UPS.PowerSummary.Voltage", NULL, "%s", 0, tripplite_iovolt },
431+
{ "output.current", 0, 0, "UPS.PowerConverter.Output.Current", NULL, "%s", 0, tripplite_ioamp },
381432
{ "output.frequency.nominal", 0, 0, "UPS.Flow.ConfigFrequency", NULL, "%.0f", HU_FLAG_STATIC, NULL },
382-
{ "output.frequency", 0, 0, "UPS.PowerConverter.Output.Frequency", NULL, "%.1f", 0, NULL },
433+
{ "output.frequency", 0, 0, "UPS.PowerConverter.Output.Frequency", NULL, "%s", 0, tripplite_iofreq },
383434

384435
/* instant commands. */
385436
{ "test.battery.start.quick", 0, 0, "UPS.BatterySystem.Test", NULL, "1", HU_TYPE_CMD, NULL }, /* reported to work on OMNI1000 */

0 commit comments

Comments
 (0)