synced up with 0.2.4 decode core

This commit is contained in:
strawmanbobi
2019-12-30 20:56:57 +08:00
parent d54a1a578a
commit 3e80a73ad3
8 changed files with 323 additions and 256 deletions

View File

@@ -1137,7 +1137,7 @@ INT8 parse_swing_info(struct tag_head *tag, t_swing_info *si)
// count how many swing types are there
si->type = SWING_TYPE_NORMAL;
si->mode_count = 1;
for (i = 0; i < tag->len; i++)
for (int i = 0; i < tag->len; i++)
{
if (tag->p_data[i] == ',')
{

View File

@@ -22,7 +22,7 @@ Revision log:
struct ir_bin_buffer binary_file;
struct ir_bin_buffer *p_ir_buffer = &binary_file;
const char* release = "0.2.2";
const char* release = "0.2.4";
#if defined USE_DYNAMIC_TAG
struct tag_head *tags;
@@ -296,6 +296,7 @@ static UINT16 ir_ac_control(t_remote_ac_status ac_status, UINT16 *user_data, UIN
UINT8 function_code = 0;
ir_printf("key code = %d\n", key_code);
switch(key_code)
{
case 0:
@@ -580,6 +581,9 @@ INT8 get_supported_wind_direction(UINT8 *supported_wind_direction)
if (NULL != context)
{
*supported_wind_direction = (UINT8) (context->si.mode_count - 1);
if (*supported_wind_direction < 0) {
*supported_wind_direction = 0;
}
return IR_DECODE_SUCCEEDED;
}
else

View File

@@ -0,0 +1,303 @@
/**************************************************************************************
Filename: ir_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 <ctype.h>
#include <libgen.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "../include/ir_defs.h"
#include "../include/ir_decode.h"
#define INPUT_MAX 3
// global variable definition
t_remote_ac_status ac_status;
UINT16 user_data[USER_DATA_SIZE];
void input_number(int *val)
{
char n[50]={0};
int i = 0;
*val = 0;
scanf("%s", n);
getchar();
while(1)
{
if(n[i] < '0'||n[i] > '9')
{
printf("\nInvalid number format, please re-input : ");
scanf("%s", n);
i=0;
}
else
{
i++;
}
if(n[i] == '\0')
break;
}
i = 0;
while (n[i] != '\0')
{
*val = (*val * 10 + (int)n[i] - 48);
i++;
}
}
static INT8 decode_as_ac(char *file_name)
{
BOOL op_match = TRUE;
BOOL change_wind_dir = FALSE;
UINT8 function_code = AC_FUNCTION_MAX;
int key_code = 0;
int first_time = 1;
// get status
UINT8 supported_mode = 0x00;
INT8 min_temperature = 0;
INT8 max_temperature = 0;
UINT8 supported_speed = 0x00;
UINT8 supported_swing = 0x00;
UINT8 supported_wind_direction = 0x00;
BOOL need_control;
// init air conditioner status
ac_status.ac_display = 0;
ac_status.ac_sleep = 0;
ac_status.ac_timer = 0;
ac_status.ac_power = AC_POWER_OFF;
ac_status.ac_mode = AC_MODE_COOL;
ac_status.ac_temp = AC_TEMP_20;
ac_status.ac_wind_dir = AC_SWING_ON;
ac_status.ac_wind_speed = AC_WS_AUTO;
if (IR_DECODE_FAILED == ir_file_open(IR_CATEGORY_AC, 0, file_name))
{
ir_close();
return IR_DECODE_FAILED;
}
do
{
if (1 == first_time)
{
printf("Please input valid key code "
"(Key code could be referenced from https://irext.net/doc#keymap) : \n");
first_time = 0;
}
else
{
printf("Please input valid key code : \n");
}
input_number(&key_code);
op_match = TRUE;
need_control = FALSE;
change_wind_dir = FALSE;
if (99 == key_code)
{
break;
}
if (14 == key_code)
{
if (IR_DECODE_SUCCEEDED == get_supported_mode(&supported_mode))
{
printf("supported mode = %02X\n", supported_mode);
}
else
{
printf("get supported mode failed\n");
}
}
else if (15 == key_code)
{
if (IR_DECODE_SUCCEEDED == get_supported_wind_speed(ac_status.ac_mode, &supported_speed))
{
printf("supported wind speed in %d = %02X\n", ac_status.ac_mode, supported_speed);
}
else
{
printf("get supported wind speed failed\n");
}
}
else if (16 == key_code)
{
if (IR_DECODE_SUCCEEDED == get_temperature_range(ac_status.ac_mode, &min_temperature, &max_temperature))
{
printf("supported temperature range in mode %d = %d, %d\n",
ac_status.ac_mode, min_temperature, max_temperature);
}
else
{
printf("get supported temperature range failed\n");
}
}
else if (17 == key_code)
{
if (IR_DECODE_SUCCEEDED == get_supported_wind_direction(&supported_wind_direction))
{
printf("supported swing type = %02X\n", supported_wind_direction);
}
else
{
printf("get swing type failed\n");
}
}
else
{
switch (key_code)
{
case 0:
ac_status.ac_power = ((ac_status.ac_wind_dir == AC_POWER_ON) ? AC_POWER_OFF : AC_POWER_ON);
need_control = TRUE;
break;
case 1:
++ac_status.ac_mode;;
ac_status.ac_mode = ac_status.ac_mode % AC_MODE_MAX;
need_control = TRUE;
break;
case 2:
case 7:
ac_status.ac_temp = ((ac_status.ac_temp == AC_TEMP_30) ? AC_TEMP_30 : (ac_status.ac_temp + 1));
need_control = TRUE;
break;
case 3:
case 8:
ac_status.ac_temp = ((ac_status.ac_temp == AC_TEMP_16) ? AC_TEMP_16 : (ac_status.ac_temp - 1));
need_control = TRUE;
break;
case 9:
++ac_status.ac_wind_speed;
ac_status.ac_wind_speed = ac_status.ac_wind_speed % AC_WS_MAX;
need_control = TRUE;
break;
case 10:
ac_status.ac_wind_dir = ((ac_status.ac_wind_dir == AC_SWING_ON) ? AC_SWING_OFF : AC_SWING_ON);
need_control = TRUE;
break;
case 11:
if (ac_status.ac_wind_dir == AC_SWING_OFF) {
change_wind_dir = TRUE;
}
need_control = TRUE;
break;
default:
op_match = FALSE;
break;
}
if (TRUE == op_match && TRUE == need_control)
{
printf("switch AC to power = %d, mode = %d, temp = %d, speed = %d, swing = %d with function code = %d\n",
ac_status.ac_power,
ac_status.ac_mode,
ac_status.ac_temp,
ac_status.ac_wind_speed,
ac_status.ac_wind_dir,
function_code);
ir_decode(function_code, user_data, &ac_status, change_wind_dir);
}
}
} while (TRUE);
ir_close();
return IR_DECODE_SUCCEEDED;
}
static INT8 decode_as_tv(char *file_name, UINT8 ir_hex_encode)
{
// keyboard input
int key_code = 0;
int first_time = 1;
if (IR_DECODE_FAILED == ir_file_open(IR_CATEGORY_TV, ir_hex_encode, file_name))
{
ir_close();
return IR_DECODE_FAILED;
}
do
{
if (1 == first_time)
{
printf("Please input valid key code "
"(Key code could be referenced from https://irext.net/doc#keymap) : \n");
first_time = 0;
}
else
{
printf("Please input valid key code : \n");
}
input_number(&key_code);
if (99 == key_code)
{
break;
}
ir_decode(key_code, user_data, NULL, 0);
} while (TRUE);
ir_close();
return IR_DECODE_SUCCEEDED;
}
static void print_usage(const char *progn) {
printf("Usage: %s [function] [file] [subcate]\n"
"[function] : 0 - decode for AC; 1 - decode for TV\n"
"[file] : the remote control binary file\n"
"[subcate] : the sub_cate value from remote_index", progn);
}
int main(int argc, char *argv[])
{
char function = '0';
UINT8 ir_hex_encode = 0;
if (4 != argc)
{
print_usage(basename(argv[0]));
return -1;
}
function = argv[1][0];
ir_hex_encode = (UINT8) (argv[3][0] - '0');
switch (function)
{
case '0':
printf("Decode %s as status-typed binary\n", argv[2]);
decode_as_ac(argv[2]);
break;
case '1':
printf("Decode %s as command-typed binary in sub_cate %d\n", argv[2], ir_hex_encode);
decode_as_tv(argv[2], ir_hex_encode);
break;
default:
printf("Decode functionality not supported : %c\n", function);
break;
}
}

View File

@@ -1,248 +0,0 @@
/**************************************************************************************
Filename: ir_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 <stdio.h>
#include "../include/ir_defs.h"
#include "../include/ir_decode.h"
// global variable definition
t_remote_ac_status ac_status;
UINT16 user_data[USER_DATA_SIZE];
INT8 ir_tv_file_open(const char *file_name);
INT8 decode_as_ac(char *file_name)
{
// keyboard input
int in_char = 0;
BOOL op_match;
UINT8 function_code = AC_FUNCTION_MAX;
// get status
UINT8 supported_mode = 0x00;
INT8 min_temperature = 0;
INT8 max_temperature = 0;
UINT8 supported_speed = 0x00;
UINT8 supported_swing = 0x00;
UINT8 supported_wind_direction = 0x00;
BOOL need_control;
// init air conditioner status
ac_status.ac_display = 0;
ac_status.ac_sleep = 0;
ac_status.ac_timer = 0;
ac_status.ac_power = AC_POWER_OFF;
ac_status.ac_mode = AC_MODE_COOL;
ac_status.ac_temp = AC_TEMP_20;
ac_status.ac_wind_dir = AC_SWING_ON;
ac_status.ac_wind_speed = AC_WS_AUTO;
if (IR_DECODE_FAILED == ir_file_open(IR_CATEGORY_AC, 0, file_name))
{
ir_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.ac_temp = ((ac_status.ac_temp == AC_TEMP_30) ? AC_TEMP_30 : (ac_status.ac_temp + 1));
function_code = AC_FUNCTION_TEMPERATURE_UP;
break;
case 's':
case 'S':
// temperature minus
ac_status.ac_temp = ((ac_status.ac_temp == AC_TEMP_16) ? AC_TEMP_16 : (ac_status.ac_temp - 1));
function_code = AC_FUNCTION_TEMPERATURE_DOWN;
break;
case 'a':
case 'A':
// wind speed loop
++ac_status.ac_wind_speed;
ac_status.ac_wind_speed = ac_status.ac_wind_speed % AC_WS_MAX;
function_code = AC_FUNCTION_WIND_SPEED;
break;
case 'd':
case 'D':
// wind swing loop
ac_status.ac_wind_dir = ((ac_status.ac_wind_dir == 0) ? AC_SWING_OFF : AC_SWING_ON);
function_code = AC_FUNCTION_WIND_SWING;
break;
case 'q':
case 'Q':
++ac_status.ac_mode;
ac_status.ac_mode = ac_status.ac_mode % AC_MODE_MAX;
function_code = AC_FUNCTION_MODE;
break;
case '1':
// turn on
ac_status.ac_power = AC_POWER_ON;
function_code = AC_FUNCTION_POWER;
break;
case '2':
// turn off
ac_status.ac_power = 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.ac_mode, &supported_swing))
{
ir_printf("\nsupported swing in %d = %02X\n", ac_status.ac_mode, supported_swing);
}
need_control = FALSE;
break;
case '5':
if (IR_DECODE_SUCCEEDED == get_supported_wind_speed(ac_status.ac_mode, &supported_speed))
{
ir_printf("\nsupported wind speed in %d = %02X\n", ac_status.ac_mode, supported_speed);
}
need_control = FALSE;
break;
case '6':
if (IR_DECODE_SUCCEEDED == get_temperature_range(ac_status.ac_mode, &min_temperature, &max_temperature))
{
ir_printf("\nsupported temperature range in mode %d = %d, %d\n",
ac_status.ac_mode, min_temperature, max_temperature);
}
need_control = FALSE;
break;
case '7':
if (IR_DECODE_SUCCEEDED == get_supported_wind_direction(&supported_wind_direction))
{
ir_printf("\nsupported wind direction = %02X\n", supported_wind_direction);
}
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 with function code = %d\n",
ac_status.ac_power,
ac_status.ac_mode,
ac_status.ac_temp,
ac_status.ac_wind_speed,
ac_status.ac_wind_dir,
function_code
);
ir_decode(function_code, user_data, &ac_status, TRUE);
}
} while ('0' != in_char);
ir_close();
return IR_DECODE_SUCCEEDED;
}
INT8 decode_as_tv(char *file_name, UINT8 ir_hex_encode)
{
// keyboard input
int in_char = 0;
int key_code = 0;
if (IR_DECODE_FAILED == ir_file_open(IR_CATEGORY_TV, ir_hex_encode, file_name))
{
ir_close();
return IR_DECODE_FAILED;
}
do
{
in_char = getchar();
if (in_char >= '0' && in_char <= '9')
{
key_code = in_char - '0';
ir_decode((UINT8)key_code, user_data, NULL, 0);
}
else if (in_char >= 'a' && in_char <= 'f')
{
key_code = 10 + (in_char - 'a');
ir_decode((UINT8) key_code, user_data, NULL, 0);
}
else if (in_char == 'q')
{
ir_close();
}
else
{
// do nothing
}
} while ('Q' != in_char);
return IR_DECODE_SUCCEEDED;
}
int main(int argc, char *argv[])
{
char function = '0';
UINT8 ir_hex_encode = 0;
if (4 != argc)
{
ir_printf("number of args error !\n");
return -1;
}
function = argv[1][0];
ir_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", ir_hex_encode);
decode_as_tv(argv[2], ir_hex_encode);
break;
default:
ir_printf("decode functionality error !\n");
break;
}
}