update 2016-11-05 b2
1. formulated irda decoder source for BOARD_PC
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,5 +2,6 @@
|
|||||||
*/output/
|
*/output/
|
||||||
src/ir_decoder/.idea
|
src/ir_decoder/.idea
|
||||||
src/ir_encoder/.idea
|
src/ir_encoder/.idea
|
||||||
|
src/ir_decoder/out
|
||||||
files/
|
files/
|
||||||
files/*
|
files/*
|
||||||
@@ -1,9 +1,31 @@
|
|||||||
cmake_minimum_required(VERSION 3.2)
|
cmake_minimum_required(VERSION 3.2)
|
||||||
project(irda_decoder)
|
|
||||||
|
|
||||||
|
########################################################
|
||||||
|
project(irda_decoder)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||||
add_definitions(-DBOARD_PC)
|
add_definitions(-DBOARD_PC)
|
||||||
set(SOURCE_FILES
|
set(SOURCE_FILES_EXECUTABLE
|
||||||
|
irda_decode.c
|
||||||
|
include/irda_decode.h
|
||||||
|
irda_lib.c
|
||||||
|
include/irda_lib.h
|
||||||
|
irda_apply.c
|
||||||
|
include/irda_apply.h
|
||||||
|
include/irda_defs.h
|
||||||
|
irda_irframe.c
|
||||||
|
include/irda_irframe.h
|
||||||
|
irda_parse_ac_parameter.c
|
||||||
|
include/irda_parse_ac_parameter.h
|
||||||
|
irda_parse_forbidden_info.c
|
||||||
|
include/irda_parse_forbidden_info.h
|
||||||
|
irda_parse_frame_parameter.c
|
||||||
|
include/irda_parse_frame_parameter.h
|
||||||
|
irda_utils.c
|
||||||
|
include/irda_utils.h
|
||||||
|
irda_main.c
|
||||||
|
include/irda_main.h)
|
||||||
|
|
||||||
|
set(SOURCE_FILES_SHARED_LIB
|
||||||
irda_decode.c
|
irda_decode.c
|
||||||
include/irda_decode.h
|
include/irda_decode.h
|
||||||
irda_lib.c
|
irda_lib.c
|
||||||
@@ -22,4 +44,5 @@ set(SOURCE_FILES
|
|||||||
irda_utils.c
|
irda_utils.c
|
||||||
include/irda_utils.h)
|
include/irda_utils.h)
|
||||||
|
|
||||||
add_executable(irda_decoder ${SOURCE_FILES})
|
add_executable(irda_decoder ${SOURCE_FILES_EXECUTABLE})
|
||||||
|
#add_library(irda_decoder SHARED ${SOURCE_FILES_SHARED_LIB})
|
||||||
|
|||||||
@@ -31,9 +31,7 @@ Revision log:
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (defined BOARD_PC) || (defined BOARD_ANDROID)
|
|
||||||
#define EXPECTED_MEM_SIZE 1024
|
#define EXPECTED_MEM_SIZE 1024
|
||||||
#endif
|
|
||||||
|
|
||||||
#define TAG_INVALID 0xffff
|
#define TAG_INVALID 0xffff
|
||||||
#define MAX_DELAYCODE_NUM 16
|
#define MAX_DELAYCODE_NUM 16
|
||||||
@@ -510,19 +508,8 @@ typedef INT8 (*lp_apply_ac_parameter) (remote_ac_status_t ac_status, UINT8 funct
|
|||||||
#define TAG_BC_KEY_14_CMD 214
|
#define TAG_BC_KEY_14_CMD 214
|
||||||
|
|
||||||
// definition about size
|
// definition about size
|
||||||
#if (defined BOARD_PC) || (defined BOARD_ANDROID)
|
|
||||||
#define PROTOCOL_SIZE (sizeof(protocol))
|
#define PROTOCOL_SIZE (sizeof(protocol))
|
||||||
#define BC_PROTOCOL_SIZE (sizeof(t_bc_protocol))
|
|
||||||
#elif defined BOARD_EMBEDDED
|
|
||||||
#define PROTOCOL_SIZE 850
|
|
||||||
#define BC_PROTOCOL_SIZE (sizeof(t_bc_protocol))
|
|
||||||
#elif defined BOARD_FREE_RTOS
|
|
||||||
#define PROTOCOL_SIZE (sizeof(protocol)) //1168
|
|
||||||
#define BC_PROTOCOL_SIZE (sizeof(t_bc_protocol))
|
|
||||||
#else
|
|
||||||
#define PROTOCOL_SIZE 0
|
|
||||||
#define BC_PROTOCOL_SIZE 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* exported variables */
|
/* exported variables */
|
||||||
extern UINT8* ir_hex_code;
|
extern UINT8* ir_hex_code;
|
||||||
@@ -619,6 +606,15 @@ extern INT8 irda_tv_lib_parse(UINT8 irda_hex_encode);
|
|||||||
* return: length of wave code array
|
* return: length of wave code array
|
||||||
*/
|
*/
|
||||||
extern UINT16 irda_tv_lib_control(UINT8 key_code, UINT16 * l_user_data);
|
extern UINT16 irda_tv_lib_control(UINT8 key_code, UINT16 * l_user_data);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* function irda_tv_lib_close
|
||||||
|
*
|
||||||
|
* parameters:
|
||||||
|
*
|
||||||
|
* return: IR_DECODE_SUCCEEDED / IR_DECODE_FAILED
|
||||||
|
*/
|
||||||
|
extern UINT16 irda_tv_lib_close();
|
||||||
#endif
|
#endif
|
||||||
///////////////////////////////////////////////// TV End /////////////////////////////////////////////////
|
///////////////////////////////////////////////// TV End /////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
@@ -8,14 +8,6 @@ Description: This file provides algorithms for IR decode
|
|||||||
Revision log:
|
Revision log:
|
||||||
* 2016-10-01: created by strawmanbobi
|
* 2016-10-01: created by strawmanbobi
|
||||||
**************************************************************************************************/
|
**************************************************************************************************/
|
||||||
#if defined BOARD_EMBEDDED
|
|
||||||
#include "osal.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined BOARD_FREE_RTOS
|
|
||||||
#include "wmstdio.h"
|
|
||||||
#include "wm_os.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined BOARD_ANDROID
|
#if defined BOARD_ANDROID
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
@@ -39,17 +31,13 @@ typedef signed short INT16;
|
|||||||
typedef unsigned char BOOL;
|
typedef unsigned char BOOL;
|
||||||
|
|
||||||
#if defined BOARD_EMBEDDED
|
#if defined BOARD_EMBEDDED
|
||||||
#define irda_malloc(A) osal_mem_alloc(A)
|
#define irda_malloc(A) malloc(A)
|
||||||
#define irda_free(A) osal_mem_free(A)
|
#define irda_free(A) free(A)
|
||||||
#define irda_memcpy(A, B, C) osal_memcpy(A, B, C)
|
#define irda_memcpy(A, B, C) memcpy(A, B, C)
|
||||||
#define irda_memset(A, B, C) osal_memset(A, B, C)
|
#define irda_memset(A, B, C) memcpy(A, B, C)
|
||||||
#define irda_strlen(A) osal_strlen(A)
|
#define irda_strlen(A) strlen(A)
|
||||||
#define IR_PRINTF(A)
|
#define IR_PRINTF(...)
|
||||||
|
#define USER_DATA_SIZE 1536
|
||||||
#if !defined BOARD_EMBEDDED
|
|
||||||
#define USER_DATA_SIZE IRDA_USER_DATA_SIZE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#elif defined BOARD_FREE_RTOS
|
#elif defined BOARD_FREE_RTOS
|
||||||
#define irda_malloc(A) os_mem_alloc(A)
|
#define irda_malloc(A) os_mem_alloc(A)
|
||||||
#define irda_free(A) os_mem_free(A)
|
#define irda_free(A) os_mem_free(A)
|
||||||
@@ -57,8 +45,8 @@ typedef unsigned char BOOL;
|
|||||||
#define irda_memset(A, B, C) memset(A, B, C)
|
#define irda_memset(A, B, C) memset(A, B, C)
|
||||||
#define irda_strlen(A) strlen(A)
|
#define irda_strlen(A) strlen(A)
|
||||||
#define IR_PRINTF(A)
|
#define IR_PRINTF(A)
|
||||||
// temporarily define USER_DATA_SIZE as 1200 for BOARD_FREE_RTOS
|
// temporarily define USER_DATA_SIZE as 1536 for BOARD_FREE_RTOS
|
||||||
#define USER_DATA_SIZE 1200
|
#define USER_DATA_SIZE 1536
|
||||||
#elif defined BOARD_PC
|
#elif defined BOARD_PC
|
||||||
#define irda_malloc(A) malloc(A)
|
#define irda_malloc(A) malloc(A)
|
||||||
#define irda_free(A) free(A)
|
#define irda_free(A) free(A)
|
||||||
|
|||||||
22
src/ir_decoder/include/irda_main.h
Normal file
22
src/ir_decoder/include/irda_main.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
/**************************************************************************************************
|
||||||
|
Filename: irda_main.h
|
||||||
|
Revised: Date: 2016-11-05
|
||||||
|
Revision: Revision: 1.0
|
||||||
|
|
||||||
|
Description: This file provides main entry for irda decoder
|
||||||
|
|
||||||
|
Revision log:
|
||||||
|
* 2016-11-05: created by strawmanbobi
|
||||||
|
**************************************************************************************************/
|
||||||
|
|
||||||
|
#ifndef IRDA_DECODER_IRDA_MAIN_H
|
||||||
|
#define IRDA_DECODER_IRDA_MAIN_H
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif //IRDA_DECODER_IRDA_MAIN_H
|
||||||
@@ -42,13 +42,11 @@ UINT16 tag_head_offset = 0;
|
|||||||
|
|
||||||
UINT16 global_mem_consume = 0;
|
UINT16 global_mem_consume = 0;
|
||||||
|
|
||||||
#if (defined BOARD_PC) || (defined BOARD_ANDROID)
|
|
||||||
UINT8 byteArray[PROTOCOL_SIZE] = {0};
|
UINT8 byteArray[PROTOCOL_SIZE] = {0};
|
||||||
UINT16 user_data[USER_DATA_SIZE] = {0};
|
UINT16 user_data[USER_DATA_SIZE] = {0};
|
||||||
UINT8 tv_bin[EXPECTED_MEM_SIZE] = {0};
|
UINT8 tv_bin[EXPECTED_MEM_SIZE] = {0};
|
||||||
UINT16 tv_bin_length = 0;
|
UINT16 tv_bin_length = 0;
|
||||||
remote_ac_status_t ac_status;
|
remote_ac_status_t ac_status;
|
||||||
#endif
|
|
||||||
|
|
||||||
// 2016-10-06 protocol version minor change: parse TAG 1009 instead of TAG 304
|
// 2016-10-06 protocol version minor change: parse TAG 1009 instead of TAG 304
|
||||||
const UINT16 tag_index[TAG_COUNT_FOR_PROTOCOL] =
|
const UINT16 tag_index[TAG_COUNT_FOR_PROTOCOL] =
|
||||||
@@ -1304,237 +1302,4 @@ UINT16 irda_tv_lib_close()
|
|||||||
// no need to close tv binary
|
// no need to close tv binary
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
///////////////////////////////////////////////// TV End /////////////////////////////////////////////////
|
||||||
///////////////////////////////////////////////// TV End /////////////////////////////////////////////////
|
|
||||||
|
|
||||||
///////////////////////////////////////////////// Decode Test Begin /////////////////////////////////////////////////
|
|
||||||
#if (defined BOARD_PC) || (defined BOARD_ANDROID)
|
|
||||||
|
|
||||||
UINT8 decode_as_ac(char *file_name)
|
|
||||||
{
|
|
||||||
// keyboard input
|
|
||||||
int in_char = 0;
|
|
||||||
int count = 0;
|
|
||||||
BOOL op_match = TRUE;
|
|
||||||
UINT8 function_code = AC_FUNCTION_MAX;
|
|
||||||
|
|
||||||
// get status
|
|
||||||
UINT8 supported_mode = 0x00;
|
|
||||||
UINT8 min_temperature = 0;
|
|
||||||
UINT8 max_temperature = 0;
|
|
||||||
UINT8 supported_speed = 0x00;
|
|
||||||
UINT8 supported_swing = 0x00;
|
|
||||||
|
|
||||||
BOOL need_control = TRUE;
|
|
||||||
|
|
||||||
// init air conditioner status
|
|
||||||
ac_status.acDisplay = 0;
|
|
||||||
ac_status.acSleep = 0;
|
|
||||||
ac_status.acTimer = 0;
|
|
||||||
ac_status.acPower = AC_POWER_OFF;
|
|
||||||
ac_status.acMode = AC_MODE_COOL;
|
|
||||||
ac_status.acTemp = AC_TEMP_20;
|
|
||||||
ac_status.acWindDir = AC_SWING_ON;
|
|
||||||
ac_status.acWindSpeed = AC_WS_AUTO;
|
|
||||||
|
|
||||||
if (IR_DECODE_FAILED == irda_ac_lib_open(file_name))
|
|
||||||
{
|
|
||||||
irda_ac_lib_close();
|
|
||||||
return IR_DECODE_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no need to verify return value
|
|
||||||
irda_context_init();
|
|
||||||
|
|
||||||
if (IR_DECODE_FAILED == irda_ac_lib_parse())
|
|
||||||
{
|
|
||||||
IR_PRINTF("\nac lib parse failed\n");
|
|
||||||
irda_ac_lib_close();
|
|
||||||
return IR_DECODE_FAILED;
|
|
||||||
}
|
|
||||||
do
|
|
||||||
{
|
|
||||||
in_char = getchar();
|
|
||||||
op_match = TRUE;
|
|
||||||
need_control = TRUE;
|
|
||||||
switch(in_char)
|
|
||||||
{
|
|
||||||
case 'w':
|
|
||||||
case 'W':
|
|
||||||
// temperature plus
|
|
||||||
ac_status.acTemp = (ac_status.acTemp == AC_TEMP_30) ? AC_TEMP_30 : (ac_status.acTemp + 1);
|
|
||||||
function_code = AC_FUNCTION_TEMPERATURE_UP;
|
|
||||||
break;
|
|
||||||
case 's':
|
|
||||||
case 'S':
|
|
||||||
ac_status.acTemp = (ac_status.acTemp == AC_TEMP_16) ? AC_TEMP_16 : (ac_status.acTemp - 1);
|
|
||||||
function_code = AC_FUNCTION_TEMPERATURE_DOWN;
|
|
||||||
// temperature minus
|
|
||||||
break;
|
|
||||||
case 'a':
|
|
||||||
case 'A':
|
|
||||||
++ac_status.acWindSpeed;
|
|
||||||
ac_status.acWindSpeed = ac_status.acWindSpeed % AC_WS_MAX;
|
|
||||||
function_code = AC_FUNCTION_WIND_SPEED;
|
|
||||||
// wind speed loop
|
|
||||||
break;
|
|
||||||
case 'd':
|
|
||||||
case 'D':
|
|
||||||
ac_status.acWindDir = (ac_status.acWindDir == 0) ? 1 : 0;
|
|
||||||
function_code = AC_FUNCTION_WIND_SWING;
|
|
||||||
// wind swing loop
|
|
||||||
break;
|
|
||||||
case 'q':
|
|
||||||
case 'Q':
|
|
||||||
++ac_status.acMode;
|
|
||||||
ac_status.acMode = ac_status.acMode % AC_MODE_MAX;
|
|
||||||
function_code = AC_FUNCTION_MODE;
|
|
||||||
break;
|
|
||||||
case '1':
|
|
||||||
// turn on
|
|
||||||
ac_status.acPower = AC_POWER_ON;
|
|
||||||
function_code = AC_FUNCTION_POWER;
|
|
||||||
break;
|
|
||||||
case '2':
|
|
||||||
// turn off
|
|
||||||
ac_status.acPower = AC_POWER_OFF;
|
|
||||||
// FUNCTION MAX refers to power off
|
|
||||||
// function_code = AC_FUNCTION_POWER;
|
|
||||||
break;
|
|
||||||
case '3':
|
|
||||||
if (IR_DECODE_SUCCEEDED == get_supported_mode(&supported_mode))
|
|
||||||
{
|
|
||||||
IR_PRINTF("\nsupported mode = %02X\n", supported_mode);
|
|
||||||
}
|
|
||||||
need_control = FALSE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '4':
|
|
||||||
if (IR_DECODE_SUCCEEDED == get_supported_swing(ac_status.acMode, &supported_swing))
|
|
||||||
{
|
|
||||||
IR_PRINTF("\nsupported swing in %d = %02X\n", ac_status.acMode, supported_swing);
|
|
||||||
}
|
|
||||||
need_control = FALSE;
|
|
||||||
break;
|
|
||||||
case '5':
|
|
||||||
if (IR_DECODE_SUCCEEDED == get_supported_wind_speed(ac_status.acMode, &supported_speed))
|
|
||||||
{
|
|
||||||
IR_PRINTF("\nsupported wind speed in %d = %02X\n", ac_status.acMode, supported_speed);
|
|
||||||
}
|
|
||||||
need_control = FALSE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '6':
|
|
||||||
if (IR_DECODE_SUCCEEDED == get_temperature_range(ac_status.acMode, &min_temperature, &max_temperature))
|
|
||||||
{
|
|
||||||
IR_PRINTF("\nsupported temperature range in mode %d = %d, %d\n", ac_status.acMode, min_temperature, max_temperature);
|
|
||||||
}
|
|
||||||
need_control = FALSE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
op_match = FALSE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(TRUE == op_match && TRUE == need_control)
|
|
||||||
{
|
|
||||||
IR_PRINTF("switch AC to power = %d, mode = %d, temp = %d, speed = %d, swing = %d\n",
|
|
||||||
ac_status.acPower,
|
|
||||||
ac_status.acMode,
|
|
||||||
ac_status.acTemp,
|
|
||||||
ac_status.acWindSpeed,
|
|
||||||
ac_status.acWindDir
|
|
||||||
);
|
|
||||||
|
|
||||||
irda_ac_lib_control(ac_status, user_data, function_code, TRUE);
|
|
||||||
}
|
|
||||||
} while('0' != in_char);
|
|
||||||
|
|
||||||
irda_ac_lib_close();
|
|
||||||
|
|
||||||
return IR_DECODE_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
UINT8 decode_as_tv(char *file_name, UINT8 irda_hex_encode)
|
|
||||||
{
|
|
||||||
// keyboard input
|
|
||||||
int in_char = 0;
|
|
||||||
int key_code = -1;
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
if (IR_DECODE_FAILED == irda_tv_lib_open(file_name))
|
|
||||||
{
|
|
||||||
return IR_DECODE_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (IR_DECODE_FAILED == irda_tv_lib_parse(irda_hex_encode))
|
|
||||||
{
|
|
||||||
return IR_DECODE_FAILED;
|
|
||||||
}
|
|
||||||
do
|
|
||||||
{
|
|
||||||
in_char = getchar();
|
|
||||||
if (in_char >= '0' && in_char <= '9')
|
|
||||||
{
|
|
||||||
key_code = in_char - '0';
|
|
||||||
irda_tv_lib_control(key_code, user_data);
|
|
||||||
}
|
|
||||||
else if (in_char >= 'a' && in_char <= 'f')
|
|
||||||
{
|
|
||||||
key_code = 10 + (in_char - 'a');
|
|
||||||
irda_tv_lib_control(key_code, user_data);
|
|
||||||
}
|
|
||||||
else if (in_char == 'q')
|
|
||||||
{
|
|
||||||
irda_tv_lib_close();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
} while('Q' != in_char);
|
|
||||||
|
|
||||||
return IR_DECODE_SUCCEEDED;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined BOARD_PC
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
char function = '0';
|
|
||||||
UINT8 irda_hex_encode = 0;
|
|
||||||
|
|
||||||
if (4 != argc)
|
|
||||||
{
|
|
||||||
IR_PRINTF("number of args error !\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function = argv[1][0];
|
|
||||||
irda_hex_encode = (UINT8)(argv[3][0] - '0');
|
|
||||||
IR_PRINTF("decode functionality = %c\n", function);
|
|
||||||
|
|
||||||
switch (function)
|
|
||||||
{
|
|
||||||
case '0':
|
|
||||||
IR_PRINTF("decode binary file as AC\n");
|
|
||||||
decode_as_ac(argv[2]);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '1':
|
|
||||||
IR_PRINTF("decode binary file as TV : %d\n", irda_hex_encode);
|
|
||||||
decode_as_tv(argv[2], irda_hex_encode);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
IR_PRINTF("decode functionality error !\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
///////////////////////////////////////////////// Decode Test End /////////////////////////////////////////////////
|
|
||||||
241
src/ir_decoder/irda_main.c
Normal file
241
src/ir_decoder/irda_main.c
Normal file
@@ -0,0 +1,241 @@
|
|||||||
|
/**************************************************************************************************
|
||||||
|
Filename: irda_main.c
|
||||||
|
Revised: Date: 2016-11-05
|
||||||
|
Revision: Revision: 1.0
|
||||||
|
|
||||||
|
Description: This file provides main entry for irda decoder
|
||||||
|
|
||||||
|
Revision log:
|
||||||
|
* 2016-11-05: created by strawmanbobi
|
||||||
|
**************************************************************************************************/
|
||||||
|
|
||||||
|
#include "./include/irda_decode.h"
|
||||||
|
|
||||||
|
#if (defined BOARD_PC) || (defined BOARD_ANDROID)
|
||||||
|
|
||||||
|
UINT8 decode_as_ac(char *file_name)
|
||||||
|
{
|
||||||
|
// keyboard input
|
||||||
|
int in_char = 0;
|
||||||
|
int count = 0;
|
||||||
|
BOOL op_match = TRUE;
|
||||||
|
UINT8 function_code = AC_FUNCTION_MAX;
|
||||||
|
|
||||||
|
// get status
|
||||||
|
UINT8 supported_mode = 0x00;
|
||||||
|
UINT8 min_temperature = 0;
|
||||||
|
UINT8 max_temperature = 0;
|
||||||
|
UINT8 supported_speed = 0x00;
|
||||||
|
UINT8 supported_swing = 0x00;
|
||||||
|
|
||||||
|
BOOL need_control = TRUE;
|
||||||
|
|
||||||
|
// init air conditioner status
|
||||||
|
ac_status.acDisplay = 0;
|
||||||
|
ac_status.acSleep = 0;
|
||||||
|
ac_status.acTimer = 0;
|
||||||
|
ac_status.acPower = AC_POWER_OFF;
|
||||||
|
ac_status.acMode = AC_MODE_COOL;
|
||||||
|
ac_status.acTemp = AC_TEMP_20;
|
||||||
|
ac_status.acWindDir = AC_SWING_ON;
|
||||||
|
ac_status.acWindSpeed = AC_WS_AUTO;
|
||||||
|
|
||||||
|
if (IR_DECODE_FAILED == irda_ac_lib_open(file_name))
|
||||||
|
{
|
||||||
|
irda_ac_lib_close();
|
||||||
|
return IR_DECODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
// no need to verify return value
|
||||||
|
irda_context_init();
|
||||||
|
|
||||||
|
if (IR_DECODE_FAILED == irda_ac_lib_parse())
|
||||||
|
{
|
||||||
|
IR_PRINTF("\nac lib parse failed\n");
|
||||||
|
irda_ac_lib_close();
|
||||||
|
return IR_DECODE_FAILED;
|
||||||
|
}
|
||||||
|
do
|
||||||
|
{
|
||||||
|
in_char = getchar();
|
||||||
|
op_match = TRUE;
|
||||||
|
need_control = TRUE;
|
||||||
|
switch(in_char)
|
||||||
|
{
|
||||||
|
case 'w':
|
||||||
|
case 'W':
|
||||||
|
// temperature plus
|
||||||
|
ac_status.acTemp = (ac_status.acTemp == AC_TEMP_30) ? AC_TEMP_30 : (ac_status.acTemp + 1);
|
||||||
|
function_code = AC_FUNCTION_TEMPERATURE_UP;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
case 'S':
|
||||||
|
ac_status.acTemp = (ac_status.acTemp == AC_TEMP_16) ? AC_TEMP_16 : (ac_status.acTemp - 1);
|
||||||
|
function_code = AC_FUNCTION_TEMPERATURE_DOWN;
|
||||||
|
// temperature minus
|
||||||
|
break;
|
||||||
|
case 'a':
|
||||||
|
case 'A':
|
||||||
|
++ac_status.acWindSpeed;
|
||||||
|
ac_status.acWindSpeed = ac_status.acWindSpeed % AC_WS_MAX;
|
||||||
|
function_code = AC_FUNCTION_WIND_SPEED;
|
||||||
|
// wind speed loop
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
case 'D':
|
||||||
|
ac_status.acWindDir = (ac_status.acWindDir == 0) ? 1 : 0;
|
||||||
|
function_code = AC_FUNCTION_WIND_SWING;
|
||||||
|
// wind swing loop
|
||||||
|
break;
|
||||||
|
case 'q':
|
||||||
|
case 'Q':
|
||||||
|
++ac_status.acMode;
|
||||||
|
ac_status.acMode = ac_status.acMode % AC_MODE_MAX;
|
||||||
|
function_code = AC_FUNCTION_MODE;
|
||||||
|
break;
|
||||||
|
case '1':
|
||||||
|
// turn on
|
||||||
|
ac_status.acPower = AC_POWER_ON;
|
||||||
|
function_code = AC_FUNCTION_POWER;
|
||||||
|
break;
|
||||||
|
case '2':
|
||||||
|
// turn off
|
||||||
|
ac_status.acPower = AC_POWER_OFF;
|
||||||
|
// FUNCTION MAX refers to power off
|
||||||
|
// function_code = AC_FUNCTION_POWER;
|
||||||
|
break;
|
||||||
|
case '3':
|
||||||
|
if (IR_DECODE_SUCCEEDED == get_supported_mode(&supported_mode))
|
||||||
|
{
|
||||||
|
IR_PRINTF("\nsupported mode = %02X\n", supported_mode);
|
||||||
|
}
|
||||||
|
need_control = FALSE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '4':
|
||||||
|
if (IR_DECODE_SUCCEEDED == get_supported_swing(ac_status.acMode, &supported_swing))
|
||||||
|
{
|
||||||
|
IR_PRINTF("\nsupported swing in %d = %02X\n", ac_status.acMode, supported_swing);
|
||||||
|
}
|
||||||
|
need_control = FALSE;
|
||||||
|
break;
|
||||||
|
case '5':
|
||||||
|
if (IR_DECODE_SUCCEEDED == get_supported_wind_speed(ac_status.acMode, &supported_speed))
|
||||||
|
{
|
||||||
|
IR_PRINTF("\nsupported wind speed in %d = %02X\n", ac_status.acMode, supported_speed);
|
||||||
|
}
|
||||||
|
need_control = FALSE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '6':
|
||||||
|
if (IR_DECODE_SUCCEEDED == get_temperature_range(ac_status.acMode, &min_temperature, &max_temperature))
|
||||||
|
{
|
||||||
|
IR_PRINTF("\nsupported temperature range in mode %d = %d, %d\n", ac_status.acMode, min_temperature, max_temperature);
|
||||||
|
}
|
||||||
|
need_control = FALSE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
op_match = FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(TRUE == op_match && TRUE == need_control)
|
||||||
|
{
|
||||||
|
IR_PRINTF("switch AC to power = %d, mode = %d, temp = %d, speed = %d, swing = %d\n",
|
||||||
|
ac_status.acPower,
|
||||||
|
ac_status.acMode,
|
||||||
|
ac_status.acTemp,
|
||||||
|
ac_status.acWindSpeed,
|
||||||
|
ac_status.acWindDir
|
||||||
|
);
|
||||||
|
|
||||||
|
irda_ac_lib_control(ac_status, user_data, function_code, TRUE);
|
||||||
|
}
|
||||||
|
} while('0' != in_char);
|
||||||
|
|
||||||
|
irda_ac_lib_close();
|
||||||
|
|
||||||
|
return IR_DECODE_SUCCEEDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT8 decode_as_tv(char *file_name, UINT8 irda_hex_encode)
|
||||||
|
{
|
||||||
|
// keyboard input
|
||||||
|
int in_char = 0;
|
||||||
|
int key_code = -1;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
if (IR_DECODE_FAILED == irda_tv_lib_open(file_name))
|
||||||
|
{
|
||||||
|
return IR_DECODE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (IR_DECODE_FAILED == irda_tv_lib_parse(irda_hex_encode))
|
||||||
|
{
|
||||||
|
return IR_DECODE_FAILED;
|
||||||
|
}
|
||||||
|
do
|
||||||
|
{
|
||||||
|
in_char = getchar();
|
||||||
|
if (in_char >= '0' && in_char <= '9')
|
||||||
|
{
|
||||||
|
key_code = in_char - '0';
|
||||||
|
irda_tv_lib_control(key_code, user_data);
|
||||||
|
}
|
||||||
|
else if (in_char >= 'a' && in_char <= 'f')
|
||||||
|
{
|
||||||
|
key_code = 10 + (in_char - 'a');
|
||||||
|
irda_tv_lib_control(key_code, user_data);
|
||||||
|
}
|
||||||
|
else if (in_char == 'q')
|
||||||
|
{
|
||||||
|
irda_tv_lib_close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
} while('Q' != in_char);
|
||||||
|
|
||||||
|
return IR_DECODE_SUCCEEDED;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined BOARD_PC
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
char function = '0';
|
||||||
|
UINT8 irda_hex_encode = 0;
|
||||||
|
|
||||||
|
if (4 != argc)
|
||||||
|
{
|
||||||
|
IR_PRINTF("number of args error !\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function = argv[1][0];
|
||||||
|
irda_hex_encode = (UINT8)(argv[3][0] - '0');
|
||||||
|
IR_PRINTF("decode functionality = %c\n", function);
|
||||||
|
|
||||||
|
switch (function)
|
||||||
|
{
|
||||||
|
case '0':
|
||||||
|
IR_PRINTF("decode binary file as AC\n");
|
||||||
|
decode_as_ac(argv[2]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case '1':
|
||||||
|
IR_PRINTF("decode binary file as TV : %d\n", irda_hex_encode);
|
||||||
|
decode_as_tv(argv[2], irda_hex_encode);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
IR_PRINTF("decode functionality error !\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user