Last active
May 25, 2018 20:00
-
-
Save SkypLabs/d7bf68a44300b3432798ce8177b63629 to your computer and use it in GitHub Desktop.
Files used by the TV RC project described at https://blog.skyplabs.net/2012/06/10/telecommander-sa-television-et-ses-autres-appareils-a-infrarouge-depuis-son-smartphone/ (French)
This file contains 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
#!/bin/bash | |
# Returns the decimal value of the payload contained in NEC infrared frames. | |
# | |
# Uses the ouput of the mode2 tool from the LIRC project as input. | |
if [ -z "$1" ] | |
then | |
echo "Usage: $0 <LIRC decode file>" | |
exit 0 | |
fi | |
if [ ! -d "$1" ] | |
then | |
echo "Error: $1 doesn't exist" | |
exit 1 | |
fi | |
obc_code=0 | |
space_up=1650 | |
space_up2=1700 | |
bit1=$(/bin/cat $1 | /bin/awk 'NR==37 {print $2}') | |
bit2=$(/bin/cat $1 | /bin/awk 'NR==39 {print $2}') | |
bit3=$(/bin/cat $1 | /bin/awk 'NR==41 {print $2}') | |
bit4=$(/bin/cat $1 | /bin/awk 'NR==43 {print $2}') | |
bit5=$(/bin/cat $1 | /bin/awk 'NR==45 {print $2}') | |
bit6=$(/bin/cat $1 | /bin/awk 'NR==47 {print $2}') | |
bit7=$(/bin/cat $1 | /bin/awk 'NR==49 {print $2}') | |
bit8=$(/bin/cat $1 | /bin/awk 'NR==51 {print $2}') | |
if [ "$bit1" == "$space_up" ] || [ "$bit1" == "$space_up2" ] | |
then | |
obc_code=$(expr $obc_code + 1) | |
fi | |
if [ "$bit2" == "$space_up" ] || [ "$bit2" == "$space_up2" ] | |
then | |
obc_code=$(expr $obc_code + 2) | |
fi | |
if [ "$bit3" == "$space_up" ] || [ "$bit3" == "$space_up2" ] | |
then | |
obc_code=$(expr $obc_code + 4) | |
fi | |
if [ "$bit4" == "$space_up" ] || [ "$bit4" == "$space_up2" ] | |
then | |
obc_code=$(expr $obc_code + 8) | |
fi | |
if [ "$bit5" == "$space_up" ] || [ "$bit5" == "$space_up2" ] | |
then | |
obc_code=$(expr $obc_code + 16) | |
fi | |
if [ "$bit6" == "$space_up" ] || [ "$bit6" == "$space_up2" ] | |
then | |
obc_code=$(expr $obc_code + 32) | |
fi | |
if [ "$bit7" == "$space_up" ] || [ "$bit7" == "$space_up2" ] | |
then | |
obc_code=$(expr $obc_code + 64) | |
fi | |
if [ "$bit8" == "$space_up" ] || [ "$bit8" == "$space_up2" ] | |
then | |
obc_code=$(expr $obc_code + 128) | |
fi | |
echo $obc_code |
This file contains 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
// Original code by Lucas Eckels | |
// http://lucaseckels.com | |
// Edited by Skyper | |
// http://blog.skyplabs.net | |
// IR remote control emitter for NEC remote protocol as described at | |
// http://www.sbprojects.com/knowledge/ir/nec.htm. | |
// Tested on a Samsung LCD TV. | |
#include <util/delay.h> | |
#define IR_PIN 13 | |
// With CONTINOUS defined, the first command is repeated continuously until | |
// you reset the Arduino. Otherwise, it sends the code once, then waits for | |
// another command. | |
//#define CONTINUOUS | |
// Times are in microseconds | |
#define ON_START_TIME 4500 | |
#define OFF_START_TIME 4500 | |
#define ON_TIME 580 | |
#define OFF_TIME_ONE 1670 | |
#define OFF_TIME_ZERO 540 | |
void setup() | |
{ | |
pinMode(IR_PIN, OUTPUT); | |
digitalWrite(IR_PIN, LOW); | |
Serial.begin(9600); | |
delay(1000); | |
Serial.println("SkypLabs - TV Remote Control"); | |
} | |
byte command = 0; | |
byte address_1 = 0; | |
byte address_2 = 0; | |
int commandCount = 0; | |
int addressCount_1 = 0; | |
int addressCount_2 = 0; | |
bool commandReady = false; | |
void loop() | |
{ | |
if (commandReady) | |
{ | |
Serial.println("Command OK"); | |
writeStart(); | |
// Writing device code | |
writeByte(address_1); | |
writeByte(address_2); | |
// Writing command code | |
writeByte(command); | |
writeByte(~command); | |
writeEnd(); | |
delay(100); | |
#ifndef CONTINUOUS | |
commandReady = false; | |
command = 0; | |
address_1 = 0; | |
address_2 = 0; | |
commandCount = 0; | |
addressCount_1 = 0; | |
addressCount_2 = 0; | |
#endif | |
return; | |
} | |
if (Serial.available() > 0) | |
{ | |
byte incoming = Serial.read(); | |
if (incoming <= '9' || incoming >= '0') | |
{ | |
if (addressCount_1 != 3) | |
{ | |
address_1 *= 10; | |
address_1 += incoming - '0'; | |
++addressCount_1; | |
} | |
else if (addressCount_2 != 3) | |
{ | |
address_2 *= 10; | |
address_2 += incoming - '0'; | |
++addressCount_2; | |
} | |
else if (commandCount != 3) | |
{ | |
command *= 10; | |
command += incoming - '0'; | |
++commandCount; | |
} | |
if (commandCount == 3) | |
commandReady = true; | |
} | |
} | |
} | |
void writeStart() | |
{ | |
modulate(ON_START_TIME); | |
delayMicroseconds(OFF_START_TIME); | |
} | |
void writeEnd() | |
{ | |
modulate(ON_TIME); | |
} | |
void writeByte(byte val) | |
{ | |
// Starting with the LSB, write out the | |
for (int i = 0x01; i & 0xFF; i <<= 1) | |
{ | |
modulate(ON_TIME); | |
if (val & i) | |
delayMicroseconds(OFF_TIME_ONE); | |
else | |
delayMicroseconds(OFF_TIME_ZERO); | |
} | |
} | |
void modulate(int time) | |
{ | |
int count = time / 26; | |
byte portb = PORTB; | |
byte portbHigh = portb | 0x20; // Pin 13 is controlled by 0x20 on PORTB. | |
byte portbLow = portb & ~0x20; | |
for (int i = 0; i <= count; i++) | |
{ | |
PORTB = portbHigh; | |
_delay_loop_1(64); | |
PORTB = portbLow; | |
_delay_loop_1(64); | |
} | |
PORTB = portb; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment