447 lines
14 KiB
C
447 lines
14 KiB
C
/* Copyright (c) 2012-2013 The Linux Foundation. All rights reserved.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 and
|
|
* only version 2 as published by the Free Software Foundation.
|
|
*
|
|
* 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.
|
|
*
|
|
*/
|
|
|
|
/*
|
|
* High Level description:
|
|
* http://www.ti.com/lit/ds/symlink/bq28400.pdf
|
|
* Thechnical Reference:
|
|
* http://www.ti.com/lit/ug/sluu431/sluu431.pdf
|
|
*/
|
|
|
|
#ifdef CONSOLE_DEBUG
|
|
|
|
#include "includes.h"
|
|
#include "display_status.h"
|
|
#include "device_param.h"
|
|
#include "asutil.h"
|
|
#include "can_comm.h"
|
|
#include "delay.h"
|
|
#include "io.h"
|
|
#include "alarm.h"
|
|
|
|
void DisplayMsg(u16 x, u16 y, u16 data, u8 bit, u8 *msg)
|
|
{
|
|
if ((data & BIT(bit)))
|
|
RedOutXY(x, y, msg);
|
|
else
|
|
GreenOutXY(x, y, msg);
|
|
}
|
|
|
|
void DisplayMsg1(u16 x, u16 y, u16 data, u8 bit, u8 *msg)
|
|
{
|
|
if ((data & BIT(bit)))
|
|
YellowOutXY(x, y, msg);
|
|
else
|
|
GreenOutXY(x, y, msg);
|
|
}
|
|
|
|
void ODisplayBatteryStatus(u8 p)
|
|
{
|
|
u16 x;
|
|
|
|
if (p ||(dis_device_status.battery_status.value != device_status.battery_status.value))
|
|
{
|
|
x = 28;
|
|
DisplayMsg(x, 3, device_status.battery_status.value, 15, (u8 *)"ACB"); x += 4;
|
|
DisplayMsg(x, 3, device_status.battery_status.value, 14, (u8 *)"TCA"); x += 4;
|
|
DisplayMsg(x, 3, device_status.battery_status.value, 13, (u8 *)"TDA"); x += 4;
|
|
DisplayMsg(x, 3, device_status.battery_status.value, 12, (u8 *)"AFE"); x += 4;
|
|
x += 4;
|
|
DisplayMsg(x, 3, device_status.battery_status.value, 10, (u8 *)"ZVC"); x += 4;
|
|
DisplayMsg(x, 3, device_status.battery_status.value, 9, (u8 *)"F-C"); x += 4;
|
|
DisplayMsg(x, 3, device_status.battery_status.value, 8, (u8 *)"F-D"); x += 4;
|
|
|
|
x = 28;
|
|
DisplayMsg(x, 4, device_status.battery_status.value, 7, (u8 *)"INI"); x += 4;
|
|
DisplayMsg(x, 4, device_status.battery_status.value, 6, (u8 *)"MD "); x += 4;
|
|
DisplayMsg(x, 4, device_status.battery_status.value, 5, (u8 *)"FC "); x += 4;
|
|
DisplayMsg(x, 4, device_status.battery_status.value, 4, (u8 *)"FD "); x += 4;
|
|
DisplayMsg(x, 4, device_status.battery_status.value, 3, (u8 *)"RXM"); x += 4;
|
|
DisplayMsg(x, 4, device_status.battery_status.value, 2, (u8 *)"ZVC"); x += 4;
|
|
DisplayMsg(x, 4, device_status.battery_status.value, 1, (u8 *)"F-C"); x += 4;
|
|
DisplayMsg(x, 4, device_status.battery_status.value, 0, (u8 *)"F-D"); x += 4;
|
|
|
|
dis_device_status.battery_status.value = device_status.battery_status.value;
|
|
}
|
|
}
|
|
|
|
void ODisplayWarningStatus(u8 p)
|
|
{
|
|
u16 x;
|
|
|
|
if (p ||(dis_device_status.warning.value != device_status.warning.value))
|
|
{
|
|
x = 28;
|
|
x += 4;
|
|
x += 4;
|
|
x += 4;
|
|
DisplayMsg1(x, 6, device_status.warning.value, 12, (u8 *)"L-C"); x += 4;
|
|
DisplayMsg1(x, 6, device_status.warning.value, 11, (u8 *)"LTD"); x += 4;
|
|
DisplayMsg1(x, 6, device_status.warning.value, 10, (u8 *)"LTC"); x += 4;
|
|
DisplayMsg1(x, 6, device_status.warning.value, 9, (u8 *)"HTD"); x += 4;
|
|
DisplayMsg1(x, 6, device_status.warning.value, 8, (u8 *)"HTC"); x += 4;
|
|
|
|
x = 28;
|
|
x += 4;
|
|
x += 4;
|
|
DisplayMsg1(x, 7, device_status.warning.value, 5, (u8 *)"OCD"); x += 4;
|
|
DisplayMsg1(x, 7, device_status.warning.value, 4, (u8 *)"OCC"); x += 4;
|
|
DisplayMsg1(x, 7, device_status.warning.value, 3, (u8 *)"CUV"); x += 4;
|
|
DisplayMsg1(x, 7, device_status.warning.value, 2, (u8 *)"SUV"); x += 4;
|
|
DisplayMsg1(x, 7, device_status.warning.value, 1, (u8 *)"COV"); x += 4;
|
|
DisplayMsg1(x, 7, device_status.warning.value, 0, (u8 *)"SOV"); x += 4;
|
|
|
|
dis_device_status.warning.value = device_status.warning.value;
|
|
}
|
|
}
|
|
|
|
void ODisplayProtectStatus(u8 p)
|
|
{
|
|
u16 x;
|
|
|
|
if (p ||(dis_device_status.protection.value != device_status.protection.value))
|
|
{
|
|
x = 28;
|
|
DisplayMsg(x, 9, device_status.protection.value, 15, (u8 *)"AFE"); x += 4;
|
|
x += 4;
|
|
DisplayMsg(x, 9, device_status.protection.value, 13, (u8 *)"SC "); x += 4;
|
|
x += 4;
|
|
DisplayMsg(x, 9, device_status.protection.value, 11, (u8 *)"LTD"); x += 4;
|
|
DisplayMsg(x, 9, device_status.protection.value, 10, (u8 *)"LTC"); x += 4;
|
|
DisplayMsg(x, 9, device_status.protection.value, 9, (u8 *)"HTD"); x += 4;
|
|
DisplayMsg(x, 9, device_status.protection.value, 8, (u8 *)"HTC"); x += 4;
|
|
|
|
x = 28;
|
|
x += 4;
|
|
x += 4;
|
|
DisplayMsg(x, 10, device_status.protection.value, 5, (u8 *)"OCD"); x += 4;
|
|
DisplayMsg(x, 10, device_status.protection.value, 4, (u8 *)"OCC"); x += 4;
|
|
DisplayMsg(x, 10, device_status.protection.value, 3, (u8 *)"CUV"); x += 4;
|
|
DisplayMsg(x, 10, device_status.protection.value, 2, (u8 *)"SUV"); x += 4;
|
|
DisplayMsg(x, 10, device_status.protection.value, 1, (u8 *)"COV"); x += 4;
|
|
DisplayMsg(x, 10, device_status.protection.value, 0, (u8 *)"SOV"); x += 4;
|
|
|
|
dis_device_status.protection.value = device_status.protection.value;
|
|
}
|
|
}
|
|
|
|
void ODisplayOperatingStatus(u8 p)
|
|
{
|
|
u8 text[20];
|
|
|
|
if (p ||(dis_device_status.op_status != device_status.op_status))
|
|
{
|
|
switch (device_status.op_status)
|
|
{
|
|
case 0: // Stand by
|
|
GreenOutXY(11, 13, (u8 *)"STAND BY ");
|
|
break;
|
|
case 1: // Charging
|
|
GreenOutXY(11, 13, (u8 *)"CHARGING ");
|
|
break;
|
|
case 2: // Discharging
|
|
GreenOutXY(11, 13, (u8 *)"DISCHARGING");
|
|
break;
|
|
case 3: // Float
|
|
GreenOutXY(11, 13, (u8 *)"FLOAT ");
|
|
break;
|
|
case 4: // Float
|
|
GreenOutXY(11, 13, (u8 *)"WARMING UP ");
|
|
break;
|
|
default:
|
|
sprintf((char *)text, "UNKNOWN(%d)", device_status.op_status);
|
|
GreenOutXY(11, 13, text);
|
|
break;
|
|
}
|
|
dis_device_status.op_status = device_status.op_status;
|
|
}
|
|
}
|
|
|
|
void ODisplayAlarmStatus(u8 p)
|
|
{
|
|
if (p ||(dis_device_status.alarm_status != device_status.alarm_status))
|
|
{
|
|
switch (device_status.alarm_status)
|
|
{
|
|
case 0: // Normal
|
|
GreenOutXY (11, 14, (u8 *)"NORMAL ");
|
|
break;
|
|
case 1: // Warning
|
|
YellowOutXY(11, 14, (u8 *)"WARNING ");
|
|
break;
|
|
case 2: // Protection
|
|
RedOutXY (11, 14, (u8 *)"PROTECTION");
|
|
break;
|
|
case 3: // WarmingUp
|
|
GreenOutXY (11, 14, (u8 *)"WARMING UP");
|
|
break;
|
|
}
|
|
dis_device_status.alarm_status = device_status.alarm_status;
|
|
}
|
|
}
|
|
|
|
void ODisplayDeviceLiveStatus(u8 p)
|
|
{
|
|
// Device ID
|
|
if (p)
|
|
{
|
|
float aParam = (float)GetDevAddrIO();
|
|
FloatNormalOutIntXY( 15, 2, aParam, 3, 0);
|
|
}
|
|
|
|
// Heartbeat
|
|
if (p || (dis_device_value.Heartbeat != device_value.Heartbeat))
|
|
{
|
|
float aParam = (float)device_value.Heartbeat;
|
|
FloatNormalOutIntXY( 11, 4, aParam, 7, 0);
|
|
dis_device_value.Heartbeat = device_value.Heartbeat;
|
|
}
|
|
}
|
|
|
|
void ODisplayDeviceValue(u8 p)
|
|
{
|
|
float aParam;
|
|
static int mcount = 0;
|
|
|
|
if (p|| (mcount == 0))
|
|
{
|
|
// Battery Voltage
|
|
if (p || (dis_device_value.BatVoltage != device_value.BatVoltage))
|
|
{
|
|
aParam = (float)device_value.BatVoltage / 100;
|
|
FloatNormalOutIntXY(12, 6, aParam, 6, 1);
|
|
dis_device_value.BatVoltage = device_value.BatVoltage;
|
|
}
|
|
// Current
|
|
if (p || (dis_device_value.Current != device_value.Current))
|
|
{
|
|
aParam = (float)device_value.Current / 10;
|
|
FloatNormalOutIntXY(12, 7, aParam, 6, 1);
|
|
dis_device_value.Current = device_value.Current;
|
|
}
|
|
// RelativeStateOfCharge
|
|
if (p || (dis_device_value.RelativeStateOfCharge != device_value.RelativeStateOfCharge))
|
|
{
|
|
aParam = (float)device_value.RelativeStateOfCharge / 10;
|
|
FloatNormalOutIntXY(13, 8, aParam, 5, 1);
|
|
dis_device_value.RelativeStateOfCharge = device_value.RelativeStateOfCharge;
|
|
}
|
|
// FullChargeCapacity
|
|
if (p || (dis_device_param.sbs.data.Full_Charge_Capacity != device_param.sbs.data.Full_Charge_Capacity))
|
|
{
|
|
aParam = (float)device_param.sbs.data.Full_Charge_Capacity / 100;
|
|
FloatNormalOutIntXY(13, 11, aParam, 5, 1);
|
|
dis_device_param.sbs.data.Full_Charge_Capacity = device_param.sbs.data.Full_Charge_Capacity;
|
|
}
|
|
mcount = 20;
|
|
}
|
|
mcount--;
|
|
}
|
|
|
|
void ODisplayDeviceStatus(u8 p)
|
|
{
|
|
u8 text[20];
|
|
|
|
// OP Status
|
|
ODisplayAlarmStatus(p);
|
|
ODisplayBatteryStatus(p);
|
|
ODisplayOperatingStatus(p);
|
|
|
|
// Warning Status
|
|
if (p || (dis_device_status.warning.value != device_status.warning.value))
|
|
{
|
|
ODisplayWarningStatus(true);
|
|
|
|
sprintf((char *)text, "%04X", *(u16 *)&device_status.warning.value);
|
|
GreenOutXY(72, 3, text);
|
|
dis_device_status.warning.value = device_status.warning.value;
|
|
}
|
|
// Protection Status
|
|
if (p || (dis_device_status.protection.value != device_status.protection.value))
|
|
{
|
|
ODisplayProtectStatus(true);
|
|
|
|
sprintf((char *)text, "%04X", *(u16 *)&device_status.protection.value);
|
|
GreenOutXY(72, 4, text);
|
|
dis_device_status.protection.value = device_status.protection.value;
|
|
}
|
|
|
|
static u8 disSleepMode = 0;
|
|
|
|
if (p || (disSleepMode != GetSleepMode()))
|
|
{
|
|
switch (GetSleepMode())
|
|
{
|
|
case 0: // Normal
|
|
GreenOutXY (53, 16, (u8 *)"NORM ");
|
|
break;
|
|
case 1: // Sleep
|
|
RedOutXY (53, 16, (u8 *)"SLEEP");
|
|
break;
|
|
}
|
|
disSleepMode = GetSleepMode();
|
|
}
|
|
}
|
|
|
|
void SDisplayInfo(u8 p)
|
|
{
|
|
u8 text[20];
|
|
|
|
// Manufacturer Name Size
|
|
if (p || (dis_device_param.info.ManufacturerNameSize != device_param.info.ManufacturerNameSize))
|
|
{
|
|
sprintf((char *)text, "%2d", device_param.info.ManufacturerNameSize);
|
|
GreenOutXY(64, 18, text);
|
|
dis_device_param.info.ManufacturerNameSize = device_param.info.ManufacturerNameSize;
|
|
}
|
|
// Manufacturer Name
|
|
if (p || (memcmp(dis_device_param.info.ManufacturerName, device_param.info.ManufacturerName, 11) != 0))
|
|
{
|
|
memcpy(text, device_param.info.ManufacturerName, 11);
|
|
text[11] = 0x00;
|
|
GreenOutXY(68, 18, text);
|
|
memcpy(dis_device_param.info.ManufacturerName, device_param.info.ManufacturerName, 11);
|
|
}
|
|
// Device Name Size
|
|
if (p || (dis_device_param.info.DeviceNameSize != device_param.info.DeviceNameSize))
|
|
{
|
|
sprintf((char *)text, "%2d", device_param.info.DeviceNameSize);
|
|
GreenOutXY(64, 19, text);
|
|
dis_device_param.info.DeviceNameSize = device_param.info.DeviceNameSize;
|
|
}
|
|
// Device Name
|
|
if (p || (memcmp(dis_device_param.info.DeviceName, device_param.info.DeviceName, 7) != 0))
|
|
{
|
|
memcpy(text, device_param.info.DeviceName, 7);
|
|
text[7] = 0x00;
|
|
GreenOutXY(68, 19, text);
|
|
memcpy(dis_device_param.info.DeviceName, device_param.info.DeviceName, 7);
|
|
}
|
|
// Device Chemistry Size
|
|
if (p || (dis_device_param.info.DeviceChemistrySize != device_param.info.DeviceChemistrySize))
|
|
{
|
|
sprintf((char *)text, "%2d", device_param.info.DeviceChemistrySize);
|
|
GreenOutXY(64, 20, text);
|
|
dis_device_param.info.DeviceChemistrySize = device_param.info.DeviceChemistrySize;
|
|
}
|
|
// Device Chemistry
|
|
if (p || (memcmp(dis_device_param.info.DeviceChemistry, device_param.info.DeviceChemistry, 4) != 0))
|
|
{
|
|
memcpy(text, device_param.info.DeviceChemistry, 4);
|
|
text[4] = 0x00;
|
|
GreenOutXY(68, 20, text);
|
|
memcpy(dis_device_param.info.DeviceChemistry, device_param.info.DeviceChemistry, 4);
|
|
}
|
|
}
|
|
|
|
void ODisplayCellStatus(u8 p)
|
|
{
|
|
u16 i, x, y;
|
|
float aParam;
|
|
static int vcount = 10;
|
|
|
|
if (p || (vcount == 0))
|
|
{
|
|
for (i = 0; i < DEVICE_MAX_CELL; i++)
|
|
{
|
|
x = 3 + ((i / 5)* 7);
|
|
y = 17 + (i % 5);
|
|
|
|
if (p ||(dis_device_value.Cell.voltage[i] != device_value.Cell.voltage[i])
|
|
||((dis_device_status.cellbalance.value >> i)& 0x0001) != ((device_status.cellbalance.value >> i)& 0x0001))
|
|
{
|
|
aParam = (float)device_value.Cell.voltage[i] / 1000;
|
|
FloatColorOutIntXY(DISPLAY_GREEN, x, y, aParam, 5, 3);
|
|
if ((device_status.cellbalance.value >> i)& 0x0001)
|
|
FloatColorOutIntXY(DISPLAY_YELLOW, x, y, aParam, 5, 3);
|
|
else
|
|
FloatColorOutIntXY(DISPLAY_GREEN, x, y, aParam, 5, 3);
|
|
|
|
dis_device_value.Cell.voltage[i] = device_value.Cell.voltage[i];
|
|
}
|
|
}
|
|
dis_device_status.cellbalance.value = device_status.cellbalance.value;
|
|
vcount = 2;
|
|
}
|
|
vcount--;
|
|
}
|
|
|
|
void ODisplayAvgValue(u8 p)
|
|
{
|
|
float aParam;
|
|
|
|
// Cell Voltage Max, Min, Avg
|
|
if (p || (dis_device_value.Cell.avg.Max.value != device_value.Cell.avg.Max.value)) {
|
|
aParam = (float)device_value.Cell.avg.Max.value / 1000;
|
|
FloatNormalOutIntXY(71, 6 , aParam, 5, 3);
|
|
dis_device_value.Cell.avg.Max.value = device_value.Cell.avg.Max.value;
|
|
}
|
|
if (p || (dis_device_value.Cell.avg.avg != device_value.Cell.avg.avg)) {
|
|
aParam = (float)device_value.Cell.avg.avg / 1000;
|
|
FloatNormalOutIntXY(71, 7 , aParam, 5, 3);
|
|
dis_device_value.Cell.avg.avg = device_value.Cell.avg.avg;
|
|
}
|
|
if (p || (dis_device_value.Cell.avg.Min.value != device_value.Cell.avg.Min.value)) {
|
|
aParam = (float)device_value.Cell.avg.Min.value / 1000;
|
|
FloatNormalOutIntXY(71, 8 , aParam, 5, 3);
|
|
dis_device_value.Cell.avg.Min.value = device_value.Cell.avg.Min.value;
|
|
}
|
|
if (p || (dis_device_value.Cell.avg.diff != device_value.Cell.avg.diff)) {
|
|
aParam = (float)device_value.Cell.avg.diff / 1000;
|
|
FloatNormalOutIntXY(71, 9 , aParam, 5, 3);
|
|
dis_device_value.Cell.avg.diff = device_value.Cell.avg.diff;
|
|
}
|
|
// Temp Max, Min, Avg
|
|
if (p || (dis_device_value.Temp.avg.Max.value != device_value.Temp.avg.Max.value))
|
|
{
|
|
aParam = (float)device_value.Temp.avg.Max.value / 10;
|
|
FloatNormalOutIntXY(71, 13, aParam, 5, 1);
|
|
|
|
dis_device_value.Temp.avg.Max.value = device_value.Temp.avg.Max.value;
|
|
}
|
|
if (p || (dis_device_value.Temp.avg.avg != device_value.Temp.avg.avg))
|
|
{
|
|
aParam = (float)device_value.Temp.avg.avg / 10;
|
|
FloatNormalOutIntXY(71, 14, aParam, 5, 1);
|
|
|
|
dis_device_value.Temp.avg.avg = device_value.Temp.avg.avg;
|
|
}
|
|
if (p || (dis_device_value.Temp.avg.Min.value != device_value.Temp.avg.Min.value))
|
|
{
|
|
aParam = (float)device_value.Temp.avg.Min.value / 10;
|
|
FloatNormalOutIntXY(71, 15, aParam, 5, 1);
|
|
|
|
dis_device_value.Temp.avg.Min.value = device_value.Temp.avg.Min.value;
|
|
}
|
|
if (p || (dis_device_value.Temp.avg.diff != device_value.Temp.avg.diff))
|
|
{
|
|
aParam = (float)device_value.Temp.avg.diff / 10;
|
|
FloatNormalOutIntXY(71, 16, aParam, 5, 1);
|
|
|
|
dis_device_value.Temp.avg.diff = device_value.Temp.avg.diff;
|
|
}
|
|
}
|
|
|
|
void ODisplayDevice(u8 p)
|
|
{
|
|
ODisplayDeviceLiveStatus(p);
|
|
ODisplayDeviceStatus(p);
|
|
ODisplayDeviceValue(p);
|
|
ODisplayCellStatus(p);
|
|
ODisplayAvgValue(p);
|
|
}
|
|
|
|
#endif // #ifdef CONSOLE_DEBUG
|
|
|
|
|