Hi all,
Below is the sample code which i have used:
void run()
{
if(nBatteryCount==100)
{
status1="5";
status2="5";
status3="5";
QFile charger_status_file
("/sys/class/gpio/gpio51/value");
if(charger_status_file.
open(QIODevice::ReadOnly)) {
status1=charger_status_file.readAll();
}
else
{
}
charger_status_file.close();
status1=status1.trimmed();
QFile file1
("/sys/class/gpio/gpio22/value");
QFile file2
("/sys/class/gpio/gpio50/value");
{
status2=file1.readAll();
}
{
status3=file2.readAll();
}
file1.close();
file2.close();
status2=status2.trimmed();
status3=status3.trimmed();
if(status1 =="0" && status2 =="1" && status3=="1" && i1==0)
{
/** with charger with battery**/
emit batteryChargeStatus(eChargeStatus_CHARGING);
i1=1;
i2=0;
i3=0;
i4=0;
i5=0;
}
else if(status2 =="0" && status3=="1" && i2==0)
{
/** battery full **/
emit batteryChargeStatus(eChargeStatus_FULL);
i1=0;
i2=1;
i3=0;
i4=0;
i5=0;
}
else if(status1 =="0" && status2 =="0" && status3=="0" && i3==0)
{
/** Invalid charger/battery not available **/
emit batteryChargeStatus(eChargeStatus_NONE);
i1=0;
i2=0;
i3=1;
i4=0;
i5=0;
}
else if(status1 =="0" && status2 =="1" && status3=="0" && i4==0)
{
if(charger_count==10)
{
/** charging **/
emit batteryChargeStatus(eChargeStatus_CHARGING);
i1=0;
i2=0;
i3=0;
i4=1;
i5=0;
charger_count=0;
}
else
{
charger_count++;
}
}
else if(status1 =="1" && status2 =="1" && status3=="1")
{
/** ADC **/
if(i5==0)
{
emit batteryChargeStatus(eChargerStatus_NONE);
}
float adc;
batteryvoltage(adc);
i1=0;
i2=0;
i3=0;
i4=0;
i5=1;
}
nBatteryCount=0;
}
else
{
nBatteryCount++;
}
}
void run()
{
if(nBatteryCount==100)
{
QString status1,status2,status3;
status1="5";
status2="5";
status3="5";
QFile charger_status_file("/sys/class/gpio/gpio51/value");
if(charger_status_file.open(QIODevice::ReadOnly))
{
status1=charger_status_file.readAll();
}
else
{
}
charger_status_file.close();
status1=status1.trimmed();
QFile file1("/sys/class/gpio/gpio22/value");
QFile file2("/sys/class/gpio/gpio50/value");
if(file1.open(QIODevice::ReadWrite))
{
status2=file1.readAll();
}
if(file2.open(QIODevice::ReadWrite))
{
status3=file2.readAll();
}
file1.close();
file2.close();
status2=status2.trimmed();
status3=status3.trimmed();
if(status1 =="0" && status2 =="1" && status3=="1" && i1==0)
{
/** with charger with battery**/
emit batteryChargeStatus(eChargeStatus_CHARGING);
i1=1;
i2=0;
i3=0;
i4=0;
i5=0;
}
else if(status2 =="0" && status3=="1" && i2==0)
{
/** battery full **/
emit batteryChargeStatus(eChargeStatus_FULL);
i1=0;
i2=1;
i3=0;
i4=0;
i5=0;
}
else if(status1 =="0" && status2 =="0" && status3=="0" && i3==0)
{
/** Invalid charger/battery not available **/
emit batteryChargeStatus(eChargeStatus_NONE);
i1=0;
i2=0;
i3=1;
i4=0;
i5=0;
}
else if(status1 =="0" && status2 =="1" && status3=="0" && i4==0)
{
if(charger_count==10)
{
/** charging **/
emit batteryChargeStatus(eChargeStatus_CHARGING);
i1=0;
i2=0;
i3=0;
i4=1;
i5=0;
charger_count=0;
}
else
{
charger_count++;
}
}
else if(status1 =="1" && status2 =="1" && status3=="1")
{
/** ADC **/
if(i5==0)
{
emit batteryChargeStatus(eChargerStatus_NONE);
}
float adc;
batteryvoltage(adc);
i1=0;
i2=0;
i3=0;
i4=0;
i5=1;
}
nBatteryCount=0;
}
else
{
nBatteryCount++;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks