123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #include <stdio.h>
- #include <unistd.h>
- #include <malloc.h>
- #include <string.h>
- #ifdef __arm__
- #include <wiringPi.h>
- #else
- #define LOW 0
- #define HIGH 1
- #define INPUT 0
- #define OUTPUT 1
- int wiringPiSetup(void) {return 0;}
- void pinMode (int a, int b) {a=b;}
- void delayMicroseconds(unsigned int a) {a=a;}
- void digitalWrite(int a, int b) {a=b;}
- int digitalRead(int a) {return a;}
- #endif
- #include "home_easy.h"
- #include "buffer.h"
- #include "utils.h"
- unsigned int portail_timings[3][2] = {
- {1140, 375}, // bit 0
- {400, 1140}, // bit 1
- {790, 790}, // start of data
- };
- extern unsigned char homeEasyPinOut;
- extern unsigned char homeEasyPinIn;
- unsigned char frame[5];
- unsigned int size = 0;
- /**
- * Create a complete command according to Chacon protocole
- *
- * @param id command id (refer to your remote)
- * @param section button section ('A' | 'B' | 'C' | 'D' | 'G')
- * @param nb button number(1, 2, 3, 4)
- * @param on boolean for on/off
- *
- * @return HomeEasy frame
- */
- void createPortailCommand(unsigned long int id, char section)
- {
- frame[0]=0xB6;
- frame[1]=0xF7;
- frame[2]=0x7B;
- frame[3]=0xA1;
- frame[4]=0x00;
- size = 36;
- return;
- }
- /**
- * Send n times a data frame
- *
- * @param frame the data to send
- * @param repeat number of repeatition
- */
- void sendPortailFrame(unsigned int repeat)
- {
- unsigned int i;
- // switch to real time
- cpuMode(REAL_TIME);
- // repeat the command
- for(i=0; i<repeat; i++) {
- sendPortailBit(START_OF_DATA);
- sendPortailBytes();
- sendPortailBit(BIT0);
- }
- digitalWrite(homeEasyPinOut, LOW);
- // Exit real time mode
- cpuMode(STANDARD);
- }
- /**
- * Send a complete command according to Chacon protocole
- *
- * @param id command id (refer to your remote)
- * @param section button section ('A' | 'B' | 'C' | 'D' | 'G')
- * @param nb button number(1, 2, 3, 4)
- * @param on boolean for on/off
- * @param repeat number of repeatition
- */
- void sendPortailCommand(unsigned int id, char button, unsigned char repeat)
- {
- unsigned long int command;
- // build the command
- createPortailCommand(id, button);
- // send data
- sendPortailFrame(repeat);
- // release the memory
- }
- /**
- * Send a bit to the RF transmitter
- *
- * @param bit the bit to transmit (0 | 1 | TRIGGER0 | TRIGGER1 | END_OF_FRAME)
- */
- void sendPortailBit(unsigned char bit)
- {
- digitalWrite(homeEasyPinOut, LOW);
- delayMicroseconds(portail_timings[bit][0]);
- digitalWrite(homeEasyPinOut, HIGH);
- delayMicroseconds(portail_timings[bit][1]);
- }
- /**
- * Send a byte to the RF transmitter
- *
- * @param byte the byte to transmit
- */
- void sendPortailByte(unsigned char byte, unsigned int bits)
- {
- int i;
- for(i=(0x01 << (bits-1));i>0; i>>=1) {
- sendPortailBit((byte & i) == i);
- }
- }
- /**
- * Send the content of a buffer to the RF transmitter
- *
- * @param buffer the buffer to transmit
- */
- void sendPortailBytes(void)
- {
- int i;
- for(i = 0; i < size; i+=8 ) {
- register unsigned int bits = (size - i >= 8) ? 8: (size - i);
- sendPortailByte(frame[i],bits);
- }
- }
|