/* Copyright (c) 2016 CurlyMo This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include #include #include #include #include #include "wiringx.h" int main() { if(wiringXSetup("raspberrypi3", NULL) == -1) { wiringXGC(); return -1; } pinMode(9, PINMODE_OUTPUT); digitalWrite(9, HIGH); pinMode(9, PINMODE_INPUT); pinMode(8, PINMODE_OUTPUT); while(1) { // start bit digitalWrite(8, HIGH); usleep(18000); digitalWrite(8, LOW); long int cycles = 0; int last_state = digitalRead(9); // ignore 2 bits: reaction on command + "official" start bit int bit = -2; char data[5]; memset(&data[0], 0, 5); while (cycles < 100000) { cycles++; if (last_state == digitalRead(9)) continue; if (last_state == 1) { if (bit >= 0) { if (cycles>400) { printf("1"); data[bit / 8] |= 1 << 7 - (bit % 8); } else printf("0"); if ((bit+1) % 8 == 0) printf(" "); } bit++; } cycles = 0; last_state = 1-last_state; } if ((bit == 40) && ((data[0]+data[1]+data[2]+data[3]-data[4]) % 255 == 0)) printf(" %f %f", data[0] + data[1]/256., data[2] + data[3]/256.); printf("\n\n"); sleep(2); } }