updated embeded, windows and jni examples

This commit is contained in:
strawmanbobi
2019-06-16 22:04:20 +08:00
parent c78ae1be69
commit 348cd663d1
17 changed files with 549 additions and 52 deletions

View File

@@ -495,6 +495,11 @@ static INT8 apply_checksum_spec_byte_onebyte(UINT8 *ac_code, t_tag_checksum_data
static UINT8 has_function(struct ac_protocol *protocol, UINT8 function)
{
if (function < AC_FUNCTION_POWER || function > AC_FUNCTION_WIND_FIX)
{
return FALSE;
}
if (0 != protocol->function1.len)
{
if (0 != protocol->function1.comp_data[function - 1].seg_len)
@@ -518,6 +523,11 @@ INT8 apply_function(struct ac_protocol *protocol, UINT8 function)
{
UINT16 i = 0;
if (function < AC_FUNCTION_POWER || function > AC_FUNCTION_WIND_FIX)
{
return IR_DECODE_FAILED;
}
// function index starts from 1 (AC_FUNCTION_POWER), do -1 operation at first
if (0 == protocol->function1.len)
{

View File

@@ -22,7 +22,7 @@ extern t_ac_protocol *context;
INT8 parse_nmode_data_speed(char *pdata, t_ac_n_mode seq)
{
char buf[16] = {0};
char buf[16] = { 0 };
char *p = pdata;
UINT16 pos = 0;
UINT16 cnt = 0, index = 0;
@@ -47,7 +47,7 @@ INT8 parse_nmode_data_speed(char *pdata, t_ac_n_mode seq)
INT8 parse_nmode_data_temp(char *pdata, t_ac_n_mode seq)
{
char buf[16] = {0};
char buf[16] = { 0 };
char *p = pdata;
UINT16 pos = 0;
UINT16 cnt = 0, index = 0;
@@ -71,8 +71,8 @@ INT8 parse_nmode_data_temp(char *pdata, t_ac_n_mode seq)
INT8 parse_nmode_pos(char *buf, t_ac_n_mode index)
{
UINT16 i = 0;
char data[64] = {0};
// char start[8] = {0};
char data[64] = { 0 };
// char start[8] = { 0 };
if (ir_strlen(buf) == 1)
{
if (buf[0] == 'S' || buf[0] == 's')
@@ -111,7 +111,7 @@ INT8 parse_nmode(struct tag_head *tag, t_ac_n_mode index)
UINT16 i = 0;
UINT16 preindex = 0;
char buf[64] = {0};
char buf[64] = { 0 };
if (tag->p_data[0] == 'N' && tag->p_data[1] == 'A')
{

View File

@@ -19,7 +19,7 @@ Revision log:
INT8 parse_boot_code(struct tag_head *tag)
{
UINT8 buf[16] = {0};
UINT8 buf[16] = { 0 };
UINT8 *p = NULL;
UINT16 pos = 0;
UINT16 cnt = 0, index = 0;
@@ -53,8 +53,8 @@ INT8 parse_boot_code(struct tag_head *tag)
INT8 parse_zero(struct tag_head *tag)
{
UINT8 low[16] = {0};
UINT8 high[16] = {0};
UINT8 low[16] = { 0 };
UINT8 high[16] = { 0 };
UINT16 index = 0;
UINT8 *p = NULL;
@@ -84,8 +84,8 @@ INT8 parse_zero(struct tag_head *tag)
INT8 parse_one(struct tag_head *tag)
{
UINT8 low[16] = {0};
UINT8 high[16] = {0};
UINT8 low[16] = { 0 };
UINT8 high[16] = { 0 };
UINT16 index = 0;
UINT8 *p = NULL;
@@ -115,7 +115,7 @@ INT8 parse_one(struct tag_head *tag)
INT8 parse_delay_code_data(UINT8 *pdata)
{
UINT8 buf[16] = {0};
UINT8 buf[16] = { 0 };
UINT8 *p = NULL;
UINT16 pos = 0;
UINT16 cnt = 0, index = 0;
@@ -146,7 +146,7 @@ INT8 parse_delay_code_data(UINT8 *pdata)
INT8 parse_delay_code_pos(UINT8 *buf)
{
UINT16 i = 0;
UINT8 data[64] = {0}, start[8] = {0};
UINT8 data[64] = { 0 }, start[8] = { 0 };
if (NULL == buf)
{
@@ -171,7 +171,7 @@ INT8 parse_delay_code_pos(UINT8 *buf)
INT8 parse_delay_code(struct tag_head *tag)
{
UINT8 buf[64] = {0};
UINT8 buf[64] = { 0 };
UINT16 i = 0;
UINT16 preindex = 0;
preindex = 0;
@@ -228,7 +228,7 @@ INT8 parse_frame_len(struct tag_head *tag, UINT16 len)
INT8 parse_endian(struct tag_head *tag)
{
UINT8 buf[8] = {0};
UINT8 buf[8] = { 0 };
if (NULL == tag)
{
@@ -241,7 +241,7 @@ INT8 parse_endian(struct tag_head *tag)
INT8 parse_lastbit(struct tag_head *tag)
{
UINT8 buf[8] = {0};
UINT8 buf[8] = { 0 };
if (NULL == tag)
{
@@ -254,7 +254,7 @@ INT8 parse_lastbit(struct tag_head *tag)
INT8 parse_repeat_times(struct tag_head *tag)
{
char asc_code[8] = {0};
char asc_code[8] = { 0 };
if (NULL == tag)
{
return IR_DECODE_FAILED;
@@ -270,7 +270,7 @@ INT8 parse_repeat_times(struct tag_head *tag)
INT8 parse_delay_code_tag48_pos(UINT8 *buf)
{
UINT16 i = 0;
UINT8 data[64] = {0}, start[8] = {0};
UINT8 data[64] = { 0 }, start[8] = { 0 };
if (NULL == buf)
{
@@ -297,7 +297,7 @@ INT8 parse_bit_num(struct tag_head *tag)
{
UINT16 i = 0;
UINT16 preindex = 0;
UINT8 buf[64] = {0};
UINT8 buf[64] = { 0 };
if (NULL == tag)
{

View File

@@ -22,6 +22,8 @@ Revision log:
struct ir_bin_buffer binary_file;
struct ir_bin_buffer *p_ir_buffer = &binary_file;
const char* release = "0.2.1";
#if defined USE_DYNAMIC_TAG
struct tag_head *tags;
#else
@@ -31,7 +33,7 @@ struct tag_head tags[TAG_COUNT_FOR_PROTOCOL];
UINT8 *ir_hex_code = NULL;
UINT8 ir_hex_len = 0;
UINT8 byteArray[PROTOCOL_SIZE] = {0};
UINT8 byteArray[PROTOCOL_SIZE] = { 0 };
size_t binary_length = 0;
UINT8 *binary_content = NULL;
@@ -53,12 +55,19 @@ lp_apply_ac_parameter apply_table[AC_APPLY_MAX] =
};
// static functions declarations
#if !defined NO_FS
static INT8 ir_ac_file_open(const char *file_name);
#endif
static INT8 ir_ac_binary_open(UINT8 *binary, UINT16 binary_length);
static UINT16 ir_ac_control(t_remote_ac_status ac_status, UINT16 *user_data, UINT8 function_code,
BOOL change_wind_direction);
static INT8 ir_ac_binary_close();
#if !defined NO_FS
static INT8 ir_tv_file_open(const char *file_name);
#endif
static INT8 ir_tv_binary_open(UINT8 *binary, UINT16 binary_length);
static INT8 ir_tv_binary_parse(UINT8 ir_hex_encode);
static UINT16 ir_tv_control(UINT8 key, UINT16 *l_user_data);
@@ -118,7 +127,7 @@ INT8 ir_file_open(const UINT8 category, const UINT8 sub_category, const char* fi
#else
INT8 ir_file_open(const UINT8 category, const UINT8 sub_category, const char* file_name)
{
return IR_DECODE_SUCCESS;
return IR_DECODE_SUCCEEDED;
}
#endif
@@ -168,7 +177,8 @@ INT8 ir_binary_open(const UINT8 category, const UINT8 sub_category, UINT8* binar
}
UINT16 ir_decode(UINT8 key_code, UINT16* user_data, t_remote_ac_status* ac_status, BOOL change_wind_direction)
UINT16 ir_decode(UINT8 key_code, UINT16* user_data,
t_remote_ac_status* ac_status, BOOL change_wind_direction)
{
if (IR_TYPE_COMMANDS == ir_binary_type)
{
@@ -180,6 +190,13 @@ UINT16 ir_decode(UINT8 key_code, UINT16* user_data, t_remote_ac_status* ac_statu
{
return 0;
}
ir_printf("ac status is not null in decode core : power = %d, mode = %d, "
"temp = %d, wind_dir = %d, wind_speed = %d, "
"keycode = %d, change_wind_direction = %d\n",
ac_status->ac_power, ac_status->ac_mode,
ac_status->ac_temp, ac_status->ac_wind_dir,
ac_status->ac_wind_speed,
key_code, change_wind_direction);
return ir_ac_control(*ac_status, user_data, key_code, change_wind_direction);
}
}
@@ -189,10 +206,12 @@ INT8 ir_close()
{
if (IR_TYPE_COMMANDS == ir_binary_type)
{
ir_printf("tv binary close\n");
return ir_tv_binary_close();
}
else
{
ir_printf("ac binary close\n");
return ir_ac_binary_close();
}
}
@@ -206,9 +225,9 @@ void ir_lib_free_inner_buffer();
// static function definitions
//////// AC Begin ////////
#if !defined NO_FS
static INT8 ir_ac_file_open(const char *file_name)
{
#if !defined NO_FS
size_t ret = 0;
#if !defined WIN32
FILE *stream = fopen(file_name, "rb");
@@ -252,9 +271,9 @@ static INT8 ir_ac_file_open(const char *file_name)
binary_length = 0;
return IR_DECODE_FAILED;
}
#endif
return IR_DECODE_SUCCEEDED;
}
#endif
static INT8 ir_ac_binary_open(UINT8 *binary, UINT16 binary_length)
{
@@ -266,7 +285,7 @@ static INT8 ir_ac_binary_open(UINT8 *binary, UINT16 binary_length)
return IR_DECODE_SUCCEEDED;
}
static UINT16 ir_ac_control(t_remote_ac_status ac_status, UINT16 *user_data, UINT8 function_code,
static UINT16 ir_ac_control(t_remote_ac_status ac_status, UINT16 *user_data, UINT8 key_code,
BOOL change_wind_direction)
{
UINT16 time_length = 0;
@@ -275,6 +294,36 @@ static UINT16 ir_ac_control(t_remote_ac_status ac_status, UINT16 *user_data, UIN
UINT16 i = 0;
#endif
UINT8 function_code = 0;
switch(key_code)
{
case 0:
function_code = AC_FUNCTION_POWER;
break;
case 1:
function_code = AC_FUNCTION_MODE;
break;
case 2:
function_code = AC_FUNCTION_TEMPERATURE_UP;
break;
case 3:
function_code = AC_FUNCTION_TEMPERATURE_DOWN;
break;
case 7:
function_code = AC_FUNCTION_TEMPERATURE_UP;
break;
case 8:
function_code = AC_FUNCTION_TEMPERATURE_DOWN;
break;
case 9:
function_code = AC_FUNCTION_WIND_SPEED;
break;
case 10:
function_code = AC_FUNCTION_WIND_SWING;
break;
}
if (0 == context->default_code.len)
{
ir_printf("\ndefault code is empty\n");
@@ -543,9 +592,9 @@ INT8 get_supported_wind_direction(UINT8 *supported_wind_direction)
//////// AC End ////////
//////// TV Begin ////////
#if !defined NO_FS
static INT8 ir_tv_file_open(const char *file_name)
{
#if !defined NO_FS
size_t ret = 0;
#if !defined WIN32
@@ -590,9 +639,9 @@ static INT8 ir_tv_file_open(const char *file_name)
binary_length = 0;
return IR_DECODE_FAILED;
}
#endif
return IR_DECODE_SUCCEEDED;
}
#endif
static INT8 ir_tv_binary_open(UINT8 *binary, UINT16 binary_length)
{
@@ -639,6 +688,25 @@ static INT8 ir_tv_binary_close()
}
//////// TV End ////////
// combo decode for JNI which means call open, decode and then close in one JNI call
UINT16 ir_decode_combo(const UINT8 category, const UINT8 sub_category,
UINT8* binary, UINT16 binary_length,
UINT8 key_code, UINT16* user_data,
t_remote_ac_status* ac_status, BOOL change_wind_direction)
{
UINT16 decoded_length = 0;
if (IR_DECODE_SUCCEEDED ==
ir_binary_open(category, sub_category, binary, binary_length))
{
decoded_length = ir_decode(key_code, user_data, ac_status, change_wind_direction);
ir_close();
return decoded_length;
}
else
{
return 0;
}
}
#if (defined BOARD_PC || defined BOARD_PC_DLL)
void ir_lib_free_inner_buffer()

View File

@@ -315,7 +315,7 @@ static void print_ir_time(t_ir_data *data, UINT8 key_index, UINT16 *ir_time)
}
else if (ir_decode_flag == IRDA_DECODE_2_BITS)
{
// for quanternary formatted code
// for quaternary formatted code
process_decode_number(key_code, data, 2, ir_time);
}
else if (ir_decode_flag == IRDA_DECODE_4_BITS)