Skip to content

Instantly share code, notes, and snippets.

@jaka
Created January 10, 2017 21:51
Show Gist options
  • Select an option

  • Save jaka/231d49c3c847b2f273ced3f987748f35 to your computer and use it in GitHub Desktop.

Select an option

Save jaka/231d49c3c847b2f273ced3f987748f35 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdint.h>
uint8_t pack_temp(uint8_t *scratchpad) {
uint8_t v;
if ( *(scratchpad + 1) & 0x80 ) {
*(scratchpad + 1) ^= 0xff;
*scratchpad ^= 0xff;
if ( *scratchpad == 0xff )
(*(scratchpad + 1))++;
(*scratchpad)++;
v = (*(scratchpad + 1) << 5) | (*scratchpad >> 3);
if ( v > 56 )
v = 56;
v = 56 - v;
}
else {
v = (*(scratchpad + 1) << 5) | (*scratchpad >> 3);
if ( v > 199 )
v = 199;
v += 56;
}
return v;
}
int main(int argc, char **argv) {
uint8_t x[2] = {0x90, 0xfc};
printf("%d\n", pack_temp(x));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment