Experimental Samsung support

This commit is contained in:
ToniA 2014-04-08 10:42:31 +03:00
parent 523cb80684
commit 69ae41a0c5
5 changed files with 202 additions and 4 deletions

View File

@ -41,8 +41,11 @@ void IRSender::setFrequency(int frequency)
OCR1A = pwmval16 / 3;
OCR1B = pwmval16 / 3;
break;
case 46: // Timer 5 on Arduino Mega
TCCR5A = _BV(WGM51);
case 44:
// Fall-through to 46, timer 5 controls pins 44, 45 and 46 on Arduino Mega
case 45:
case 46:
TCCR5A = _BV(WGM51) | _BV(WGM50);
TCCR5B = _BV(WGM53) | _BV(CS50);
ICR5 = pwmval16;
OCR5A = pwmval16 / 3;
@ -121,6 +124,12 @@ void IRSender::mark(int markLength)
case 10:
(TCCR2A |= _BV(COM2A1)); // Enable pin 11 PWM output
break;
case 44:
(TCCR5A |= _BV(COM5C1)); // Enable pin 44 PWM output on Arduino Mega
break;
case 45:
(TCCR5A |= _BV(COM5B1)); // Enable pin 45 PWM output on Arduino Mega
break;
case 46:
(TCCR5A |= _BV(COM5A1)); // Enable pin 46 PWM output on Arduino Mega
break;
@ -139,7 +148,7 @@ void IRSender::mark(int markLength)
(TCCR2A |= _BV(COM2A1)); // Enable pin 11 PWM output
break;
#endif
}
}
delayMicroseconds(markLength);
}
@ -163,6 +172,10 @@ void IRSender::space(int spaceLength)
case 10:
(TCCR2A &= ~(_BV(COM2A1))); // Disable pin 11 PWM output
break;
case 44:
(TCCR5A &= ~(_BV(COM5C1))); // Disable pin 44 PWM output on Arduino Mega
case 45:
(TCCR5A &= ~(_BV(COM5B1))); // Disable pin 45 PWM output on Arduino Mega
case 46:
(TCCR5A &= ~(_BV(COM5A1))); // Disable pin 46 PWM output on Arduino Mega
#else

138
SamsungHeatpumpIR.cpp Normal file
View File

@ -0,0 +1,138 @@
#include <Arduino.h>
#include <SamsungHeatpumpIR.h>
SamsungHeatpumpIR::SamsungHeatpumpIR() : HeatpumpIR()
{
static const prog_char model[] PROGMEM = "samsung";
static const prog_char info[] PROGMEM = "{\"mdl\":\"samsung\",\"dn\":\"Samsung\",\"mT\":16,\"xT\":27,\"fs\":4}";
_model = model;
_info = info;
}
void SamsungHeatpumpIR::send(IRSender& IR, byte powerModeCmd, byte operatingModeCmd, byte fanSpeedCmd, byte temperatureCmd, byte swingVCmd, byte swingHCmd)
{
// Sensible defaults for the heat pump mode
byte powerMode = SAMSUNG_AIRCON1_MODE_ON;
byte operatingMode = SAMSUNG_AIRCON1_MODE_HEAT;
byte fanSpeed = SAMSUNG_AIRCON1_FAN_AUTO;
byte temperature = 23;
if (powerModeCmd == POWER_OFF)
{
powerMode = SAMSUNG_AIRCON1_MODE_OFF;
}
else
{
switch (operatingModeCmd)
{
case MODE_AUTO:
operatingMode = SAMSUNG_AIRCON1_MODE_AUTO;
fanSpeedCmd = FAN_AUTO; // Fan speed is always 'AUTO' in AUTO mode
break;
case MODE_HEAT:
operatingMode = SAMSUNG_AIRCON1_MODE_HEAT;
break;
case MODE_COOL:
operatingMode = SAMSUNG_AIRCON1_MODE_COOL;
break;
case MODE_DRY:
operatingMode = SAMSUNG_AIRCON1_MODE_DRY;
fanSpeedCmd = FAN_AUTO; // Fan speed is always 'AUTO' in DRY mode
break;
case MODE_FAN:
operatingMode = SAMSUNG_AIRCON1_MODE_FAN;
if ( fanSpeedCmd == FAN_AUTO ) {
fanSpeedCmd = FAN_1; // Fan speed cannot be 'AUTO' in FAN mode
}
break;
}
}
switch (fanSpeedCmd)
{
case FAN_AUTO:
fanSpeed = SAMSUNG_AIRCON1_FAN_AUTO;
break;
case FAN_1:
fanSpeed = SAMSUNG_AIRCON1_FAN1;
break;
case FAN_2:
fanSpeed = SAMSUNG_AIRCON1_FAN2;
break;
case FAN_3:
fanSpeed = SAMSUNG_AIRCON1_FAN3;
break;
}
if ( temperatureCmd > 15 && temperatureCmd < 28)
{
temperature = temperatureCmd;
}
sendSamsung(IR, powerMode, operatingMode, fanSpeed, temperature);
}
// Send the Samsung code
void SamsungHeatpumpIR::sendSamsung(IRSender& IR, byte powerMode, byte operatingMode, byte fanSpeed, byte temperature)
{
byte SamsungTemplate[] = { 0x02, 0x92, 0x0F, 0x00, 0x00, 0x00, 0xF0, // Header part
0x01, 0xD2, 0x0F, 0x00, 0x00, 0x00, 0x00, // Always the same data on POWER messages
0x01, 0x00, 0xFE, 0x71, 0x00, 0x00, 0xF0 }; // The actual data is in this part, on bytes 14-20
// Set the power mode on the template message
SamsungTemplate[1] = powerMode;
// Set the fan speed and the operating mode on the template message
SamsungTemplate[19] = operatingMode | fanSpeed;
// Set the temperature on the template message
SamsungTemplate[18] = (temperature - 16) << 4;
// Byte 15 has some meaning on the protocol, it's one of these: 0xB2, 0xC2, 0xD2 or 0xE2
SamsungTemplate[15] = 0xE2;
// 40 kHz PWM frequency
IR.setFrequency(40);
// Header
IR.mark(SAMSUNG_AIRCON1_HDR_MARK);
IR.space(SAMSUNG_AIRCON1_HDR_SPACE);
// Payload header part
for (int i=0; i<7; i++) {
IR.sendIRByte(SamsungTemplate[i], SAMSUNG_AIRCON1_BIT_MARK, SAMSUNG_AIRCON1_ZERO_SPACE, SAMSUNG_AIRCON1_ONE_SPACE);
}
// Pause + new header
IR.mark(SAMSUNG_AIRCON1_BIT_MARK);
IR.space(SAMSUNG_AIRCON1_MSG_SPACE);
IR.mark(SAMSUNG_AIRCON1_HDR_MARK);
IR.space(SAMSUNG_AIRCON1_HDR_SPACE);
// Payload power message part
for (int i=7; i<14; i++) {
IR.sendIRByte(SamsungTemplate[i], SAMSUNG_AIRCON1_BIT_MARK, SAMSUNG_AIRCON1_ZERO_SPACE, SAMSUNG_AIRCON1_ONE_SPACE);
}
// Pause + new header
IR.mark(SAMSUNG_AIRCON1_BIT_MARK);
IR.space(SAMSUNG_AIRCON1_MSG_SPACE);
IR.mark(SAMSUNG_AIRCON1_HDR_MARK);
IR.space(SAMSUNG_AIRCON1_HDR_SPACE);
// Payload data message part
for (int i=14; i<21; i++) {
IR.sendIRByte(SamsungTemplate[i], SAMSUNG_AIRCON1_BIT_MARK, SAMSUNG_AIRCON1_ZERO_SPACE, SAMSUNG_AIRCON1_ONE_SPACE);
}
// End mark
IR.mark(SAMSUNG_AIRCON1_BIT_MARK);
IR.space(0);
}

43
SamsungHeatpumpIR.h Normal file
View File

@ -0,0 +1,43 @@
/*
Samsung xxx / yyy heatpump control (remote control P/N zzz)
*/
#ifndef SamsungHeatpumpIR_h
#define SamsungHeatpumpIR_h
#include <Arduino.h>
#include <IRSender.h>
#include <HeatpumpIR.h>
// Samsung timing constants
#define SAMSUNG_AIRCON1_HDR_MARK 3000
#define SAMSUNG_AIRCON1_HDR_SPACE 9000
#define SAMSUNG_AIRCON1_BIT_MARK 540
#define SAMSUNG_AIRCON1_ONE_SPACE 1500
#define SAMSUNG_AIRCON1_ZERO_SPACE 450
#define SAMSUNG_AIRCON1_MSG_SPACE 1600
// Samsung codes
#define SAMSUNG_AIRCON1_MODE_AUTO 0x00 // Operating mode
#define SAMSUNG_AIRCON1_MODE_HEAT 0x40
#define SAMSUNG_AIRCON1_MODE_COOL 0x10
#define SAMSUNG_AIRCON1_MODE_DRY 0x20
#define SAMSUNG_AIRCON1_MODE_FAN 0x30
#define SAMSUNG_AIRCON1_MODE_OFF 0xB2 // Power OFF
#define SAMSUNG_AIRCON1_MODE_ON 0x92 // Power ON
#define SAMSUNG_AIRCON1_FAN_AUTO 0x01 // Fan speed
#define SAMSUNG_AIRCON1_FAN1 0x05 // * low
#define SAMSUNG_AIRCON1_FAN2 0x09 // * med
#define SAMSUNG_AIRCON1_FAN3 0x0B // * high
class SamsungHeatpumpIR : public HeatpumpIR
{
public:
SamsungHeatpumpIR();
void send(IRSender& IR, byte powerModeCmd, byte operatingModeCmd, byte fanSpeedCmd, byte temperatureCmd, byte swingVCmd, byte swingHCmd);
private:
void sendSamsung(IRSender& IR, byte powerMode, byte operatingMode, byte fanSpeed, byte temperature);
};
#endif

View File

@ -6,13 +6,15 @@
#include <CarrierHeatpumpIR.h>
#include <MideaHeatpumpIR.h>
#include <MitsubishiHeatpumpIR.h>
#include <SamsungHeatpumpIR.h>
IRSender irSender(3); // IR led on Duemilanove digital pin 3
// Array with all supported heatpumps
HeatpumpIR *heatpumpIR[] = {new PanasonicCKPHeatpumpIR(), new PanasonicDKEHeatpumpIR(), new PanasonicJKEHeatpumpIR(),
new PanasonicNKEHeatpumpIR(), new CarrierHeatpumpIR(), new MideaHeatpumpIR(),
new FujitsuHeatpumpIR(), new MitsubishiFDHeatpumpIR(), new MitsubishiFEHeatpumpIR(), NULL};
new FujitsuHeatpumpIR(), new MitsubishiFDHeatpumpIR(), new MitsubishiFEHeatpumpIR(),
new SamsungHeatpumpIR(), NULL};
void setup()
{

View File

@ -1,4 +1,5 @@
HeatpumpIR KEYWORD1
PanasonicHeatpumpIR KEYWORD1
PanasonicCKPHeatpumpIR KEYWORD1
PanasonicDKEHeatpumpIR KEYWORD1
PanasonicJKEHeatpumpIR KEYWORD1
@ -9,6 +10,7 @@ FujitsuHeatpumpIR KEYWORD1
MitsubishiHeatpumpIR KEYWORD1
MitsubishiFDHeatpumpIR KEYWORD1
MitsubishiFEHeatpumpIR KEYWORD1
SamsungHeatpumpIR KEYWORD1
IRSender KEYWORD1