comparison Discovery/Src/t7.c @ 859:d32901746950 Evo_2_23

Improvment battery charger visualization: In the previous version the green flash (charge complete) was shown even battery had not reached 100% charge. Root cause was that the pin signaling the end of charge could be raised for other reasons then a full battery. The new version will show the green flash only in case the battery is rated as full. In addition the graph visualization has been updated to continously progress. In the previous version it only progressed in case the charge value changed. Especially at charging start the charger is doing some battery evaluation which does not increase the charge state. In such a case the graph seemed to be frozen.
author Ideenmodellierer
date Tue, 07 May 2024 21:20:33 +0200
parents ba1aebc6d5af
children db92692c014f
comparison
equal deleted inserted replaced
858:08ea8e9d6cfe 859:d32901746950
4503 } 4503 }
4504 else 4504 else
4505 { 4505 {
4506 level = 10; 4506 level = 10;
4507 } 4507 }
4508 if(curIndex > 1)
4509 {
4510 level = (level + ChargerLog[curIndex - 1]) / 2; /* smooth small jumps */
4511 }
4508 if(curIndex < 59) 4512 if(curIndex < 59)
4509 { 4513 {
4510 ChargerLog[curIndex++] = level; 4514 ChargerLog[curIndex++] = level;
4511 } 4515 }
4512 else 4516 else
4513 { 4517 {
4514 memcpy (&ChargerLog[0],&ChargerLog[1],sizeof(ChargerLog) - 1); 4518 memcpy (&ChargerLog[0],&ChargerLog[1],sizeof(ChargerLog) - 1);
4515 ChargerLog[curIndex] = level; 4519 ChargerLog[curIndex] = level;
4516 } 4520 }
4517 if(curIndex > 1) 4521 if(curIndex > 1) /* estimate time til charging is complete */
4518 { 4522 {
4519 averageSpeed = ((averageSpeed * (curIndex-1)) + charge) / curIndex; 4523 averageSpeed = ((averageSpeed * (curIndex-1)) + charge) / curIndex;
4520 completeSec = (100.0 - stateUsed->lifeData.battery_charge) / averageSpeed; 4524 completeSec = (100.0 - stateUsed->lifeData.battery_charge) / averageSpeed;
4521 } 4525 }
4522 else 4526 else
4569 localCharge *= -1.0; 4573 localCharge *= -1.0;
4570 } 4574 }
4571 4575
4572 if(stateUsed->chargeStatus != CHARGER_off) 4576 if(stateUsed->chargeStatus != CHARGER_off)
4573 { 4577 {
4574 if(lastCharge != localCharge) 4578 curTick = HAL_GetTick();
4575 { 4579 deltatime = (curTick - lastTick);
4576 curTick = HAL_GetTick(); 4580
4577 deltatime = (curTick - lastTick); 4581 if((deltatime > 3000) || (lastCharge != localCharge)) /* Charge value update is expected every 2 second. */
4578 lastTick = curTick; 4582 { /* Added timeout to keep graph moving in case charger is temporary idle */
4579 if(lastCharge < localCharge) 4583 if(lastCharge != localCharge)
4580 { 4584 {
4581 speed = (localCharge - lastCharge) * 1000.0 / deltatime; 4585 if(lastCharge < localCharge)
4586 {
4587 speed = (localCharge - lastCharge) * 1000.0 / deltatime;
4588 }
4589
4590 if(localCharge > 100.0)
4591 {
4592 localCharge = 100.0;
4593 }
4594 lastCharge = localCharge;
4582 } 4595 }
4583
4584 if(localCharge > 100.0)
4585 {
4586 localCharge = 100.0;
4587 }
4588
4589 lastCharge = localCharge;
4590 }
4591
4592
4593 if(deltatime > 1000)
4594 {
4595 deltatime = 0; 4596 deltatime = 0;
4596 remainingSec = LogDeltaCharge(speed); 4597 remainingSec = LogDeltaCharge(speed);
4597 speed = 0; 4598 speed = 0;
4599 lastTick = curTick;
4598 } 4600 }
4599 } 4601 }
4600 textpointer += snprintf(&text[textpointer],50,"\n\r"); 4602 textpointer += snprintf(&text[textpointer],50,"\n\r");
4601 textpointer += snprintf(&text[textpointer],50,"\001%c\n\r",TXT_ChargeHour); 4603 textpointer += snprintf(&text[textpointer],50,"\001%c\n\r",TXT_ChargeHour);
4602 4604