correct value calculation

This commit is contained in:
King Kévin 2015-11-10 12:30:30 +01:00
parent 3ac49be7fd
commit 7922e14807
1 changed files with 4 additions and 4 deletions

View File

@ -173,7 +173,7 @@ int main(void)
char str[5+1+3+1]; // store the value as string
switch (answer[0]) {
case 0xa0: // voltage
snprintf(str,sizeof(str),"%u.%u",(answer[1]<<8)+answer[2],answer[3]);
snprintf(str,sizeof(str),"%u.%u",((uint16_t)(answer[1])<<8)+answer[2],answer[3]);
voltage = atof(str);
cmd[0] = 0xb1; // query current
cmd[6] = 0x1b; // update checksum
@ -182,7 +182,7 @@ int main(void)
}
break;
case 0xa1: // current
snprintf(str,sizeof(str),"%u.%u",(answer[1]<<8)+answer[2],answer[3]);
snprintf(str,sizeof(str),"%u.%u",((uint16_t)(answer[1])<<8)+answer[2],answer[3]);
current = atof(str);
cmd[0] = 0xb2; // query power
cmd[6] = 0x1c; // update checksum
@ -191,7 +191,7 @@ int main(void)
}
break;
case 0xa2: // power
snprintf(str,sizeof(str),"%u.%u",(answer[1]<<8)+answer[2],answer[3]);
snprintf(str,sizeof(str),"%u.%u",((uint16_t)(answer[1])<<8)+answer[2],answer[3]);
power = atof(str);
cmd[0] = 0xb3; // query energy
cmd[6] = 0x1d; // update checksum
@ -200,7 +200,7 @@ int main(void)
}
break;
case 0xa3: // energy
energy = (((uint32_t)answer[1])<<16)+(answer[2]<<8)+answer[3];
energy = (((uint32_t)answer[1])<<16)+((uint32_t)(answer[2])<<8)+answer[3];
queried_pzem004 = true; // all have been queried
send_values = true; // this should be the last of the 4 values we requested. now send them
break;