Created
January 10, 2017 21:51
-
-
Save jaka/231d49c3c847b2f273ced3f987748f35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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