fixed non-standard naming and usage
This commit is contained in:
parent
2af0fb3815
commit
d3232585b0
@ -39,7 +39,7 @@
|
||||
|
||||
#define MONKEY_DEV_CREATE_MATCH(monkey, type_mask, type) \
|
||||
do { \
|
||||
if ((type_mask & MONKEY_DEV_TYPE_##type) == MONKEY_DEV_TYPE_##type) \
|
||||
if (((type_mask) & MONKEY_DEV_TYPE_##type) == MONKEY_DEV_TYPE_##type) \
|
||||
{ \
|
||||
FAR struct monkey_dev_s *dev; \
|
||||
dev = monkey_dev_create(CONFIG_TESTING_MONKEY_DEV_PATH_##type, \
|
||||
@ -48,8 +48,8 @@ do { \
|
||||
{ \
|
||||
goto failed; \
|
||||
} \
|
||||
monkey->devs[monkey->dev_num] = dev; \
|
||||
monkey->dev_num++; \
|
||||
(monkey)->devs[(monkey)->dev_num] = dev; \
|
||||
(monkey)->dev_num++; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
@ -63,9 +63,8 @@ do { \
|
||||
|
||||
FAR struct monkey_s *monkey_create(int dev_type_mask)
|
||||
{
|
||||
FAR struct monkey_s *monkey = malloc(sizeof(struct monkey_s));
|
||||
FAR struct monkey_s *monkey = calloc(1, sizeof(struct monkey_s));
|
||||
MONKEY_ASSERT_NULL(monkey);
|
||||
memset(monkey, 0, sizeof(struct monkey_s));
|
||||
|
||||
if (MONKEY_IS_UINPUT_TYPE(dev_type_mask))
|
||||
{
|
||||
@ -106,7 +105,7 @@ void monkey_delete(FAR struct monkey_s *monkey)
|
||||
|
||||
for (i = 0; i < monkey->dev_num; i++)
|
||||
{
|
||||
monkey_dev_delete(monkey->devs[i]);
|
||||
monkey_dev_delete(monkey->devs[i]);
|
||||
}
|
||||
|
||||
if (monkey->recorder)
|
||||
|
@ -18,8 +18,8 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __MONKEY_H__
|
||||
#define __MONKEY_H__
|
||||
#ifndef __APPS_TESTING_MONKEY_MONKEY_H
|
||||
#define __APPS_TESTING_MONKEY_MONKEY_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
@ -95,4 +95,4 @@ bool monkey_set_recorder_path(FAR struct monkey_s *monkey,
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MONKEY_H__ */
|
||||
#endif /* __APPS_TESTING_MONKEY_MONKEY_H */
|
||||
|
@ -18,8 +18,8 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __MONKEY_ASSERT_H__
|
||||
#define __MONKEY_ASSERT_H__
|
||||
#ifndef __APPS_TESTING_MONKEY_MONKEY_ASSERT_H
|
||||
#define __APPS_TESTING_MONKEY_MONKEY_ASSERT_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
@ -34,4 +34,4 @@
|
||||
#define MONKEY_ASSERT(expr) DEBUGASSERT(expr)
|
||||
#define MONKEY_ASSERT_NULL(ptr) MONKEY_ASSERT(ptr != NULL)
|
||||
|
||||
#endif /* __MONKEY_ASSERT_H__ */
|
||||
#endif /* __APPS_TESTING_MONKEY_MONKEY_ASSERT_H */
|
||||
|
@ -134,6 +134,10 @@ static bool button_read(int fd, FAR uint32_t *value)
|
||||
return true;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: monkey_dev_create
|
||||
****************************************************************************/
|
||||
@ -147,9 +151,8 @@ FAR struct monkey_dev_s *monkey_dev_create(FAR const char *dev_path,
|
||||
|
||||
MONKEY_ASSERT_NULL(dev_path);
|
||||
|
||||
dev = malloc(sizeof(struct monkey_dev_s));
|
||||
dev = calloc(1, sizeof(struct monkey_dev_s));
|
||||
MONKEY_ASSERT_NULL(dev);
|
||||
memset(dev, 0, sizeof(struct monkey_dev_s));
|
||||
|
||||
if (MONKEY_IS_UINPUT_TYPE(type))
|
||||
{
|
||||
@ -189,10 +192,6 @@ failed:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: monkey_dev_delete
|
||||
****************************************************************************/
|
||||
@ -212,7 +211,6 @@ void monkey_dev_delete(FAR struct monkey_dev_s *dev)
|
||||
|
||||
MONKEY_LOG_NOTICE("close fd: %d", dev->fd);
|
||||
close(dev->fd);
|
||||
dev->fd = -1;
|
||||
}
|
||||
|
||||
free(dev);
|
||||
@ -223,25 +221,25 @@ void monkey_dev_delete(FAR struct monkey_dev_s *dev)
|
||||
****************************************************************************/
|
||||
|
||||
void monkey_dev_set_state(FAR struct monkey_dev_s *dev,
|
||||
FAR const struct monkey_dev_state_s *state)
|
||||
FAR const struct monkey_dev_state_s *state)
|
||||
{
|
||||
MONKEY_ASSERT_NULL(dev);
|
||||
|
||||
switch (MONKEY_GET_DEV_TYPE(dev->type))
|
||||
{
|
||||
case MONKEY_DEV_TYPE_TOUCH:
|
||||
utouch_write(dev->fd,
|
||||
state->data.touch.x,
|
||||
state->data.touch.y,
|
||||
state->data.touch.is_pressed);
|
||||
break;
|
||||
case MONKEY_DEV_TYPE_TOUCH:
|
||||
utouch_write(dev->fd,
|
||||
state->data.touch.x,
|
||||
state->data.touch.y,
|
||||
state->data.touch.is_pressed);
|
||||
break;
|
||||
|
||||
case MONKEY_DEV_TYPE_BUTTON:
|
||||
ubutton_write(dev->fd, state->data.button.value);
|
||||
break;
|
||||
case MONKEY_DEV_TYPE_BUTTON:
|
||||
ubutton_write(dev->fd, state->data.button.value);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -261,19 +259,19 @@ bool monkey_dev_get_state(FAR struct monkey_dev_s *dev,
|
||||
|
||||
switch (dev->type)
|
||||
{
|
||||
case MONKEY_DEV_TYPE_TOUCH:
|
||||
retval = touch_read(dev->fd,
|
||||
&state->data.touch.x,
|
||||
&state->data.touch.y,
|
||||
&state->data.touch.is_pressed);
|
||||
break;
|
||||
case MONKEY_DEV_TYPE_TOUCH:
|
||||
retval = touch_read(dev->fd,
|
||||
&state->data.touch.x,
|
||||
&state->data.touch.y,
|
||||
&state->data.touch.is_pressed);
|
||||
break;
|
||||
|
||||
case MONKEY_DEV_TYPE_BUTTON:
|
||||
retval = button_read(dev->fd, &state->data.button.value);
|
||||
break;
|
||||
case MONKEY_DEV_TYPE_BUTTON:
|
||||
retval = button_read(dev->fd, &state->data.button.value);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return retval;
|
||||
|
@ -18,8 +18,8 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __MONKEY_DEV_H__
|
||||
#define __MONKEY_DEV_H__
|
||||
#ifndef __APPS_TESTING_MONKEY_MONKEY_DEV_H
|
||||
#define __APPS_TESTING_MONKEY_MONKEY_DEV_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
@ -94,4 +94,4 @@ int monkey_dev_get_available(FAR struct monkey_dev_s *devs[], int dev_num);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MONKEY_DEV_H__ */
|
||||
#endif /* __APPS_TESTING_MONKEY_MONKEY_DEV_H */
|
||||
|
@ -56,9 +56,10 @@ void monkey_log_printf(enum monkey_log_level_type_e level,
|
||||
struct va_format vaf;
|
||||
va_list ap;
|
||||
|
||||
static const int priority[_MONKEY_LOG_LEVEL_LAST] = {
|
||||
LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_ERR
|
||||
};
|
||||
static const int priority[_MONKEY_LOG_LEVEL_LAST] =
|
||||
{
|
||||
LOG_INFO, LOG_NOTICE, LOG_WARNING, LOG_ERR
|
||||
};
|
||||
|
||||
if (level < g_log_level)
|
||||
{
|
||||
|
@ -18,8 +18,8 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __MONKEY_LOG_H__
|
||||
#define __MONKEY_LOG_H__
|
||||
#ifndef __APPS_TESTING_MONKEY_MONKEY_LOG_H
|
||||
#define __APPS_TESTING_MONKEY_MONKEY_LOG_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
@ -114,4 +114,4 @@ enum monkey_log_level_type_e monkey_log_get_level(void);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MONKEY_LOG_H__ */
|
||||
#endif /* __APPS_TESTING_MONKEY_MONKEY_LOG_H */
|
||||
|
@ -43,7 +43,7 @@
|
||||
do \
|
||||
{ \
|
||||
FAR char *ptr; \
|
||||
value = (type)strtoul(optarg, &ptr, base); \
|
||||
(value) = (type)strtoul(optarg, &ptr, (base)); \
|
||||
if (*ptr != '\0') \
|
||||
{ \
|
||||
printf(MONKEY_PREFIX "Parameter error: -%c %s\n", ch, optarg); \
|
||||
@ -208,9 +208,11 @@ static void parse_commandline(int argc, FAR char **argv,
|
||||
case 't':
|
||||
OPTARG_TO_VALUE(param->dev_type_mask, int, 16);
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
param->file_path = optarg;
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
converted = sscanf(optarg, "%d-%d", &period_min, &period_max);
|
||||
if (converted == 2 && period_min >= 0 && period_max >= 0)
|
||||
@ -224,6 +226,7 @@ static void parse_commandline(int argc, FAR char **argv,
|
||||
show_usage(argv[0], EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
|
||||
case 's':
|
||||
converted = sscanf(optarg, "%dx%d", &hor_res, &ver_res);
|
||||
if (converted == 2 && hor_res > 0 && ver_res > 0)
|
||||
@ -238,6 +241,7 @@ static void parse_commandline(int argc, FAR char **argv,
|
||||
show_usage(argv[0], EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
|
||||
case '?':
|
||||
printf(MONKEY_PREFIX ": Unknown option: %c\n", optopt);
|
||||
show_usage(argv[0], EXIT_FAILURE);
|
||||
|
@ -135,9 +135,8 @@ FAR struct monkey_recorder_s *monkey_recorder_create(FAR const char *path,
|
||||
|
||||
MONKEY_ASSERT_NULL(path);
|
||||
|
||||
recorder = malloc(sizeof(struct monkey_recorder_s));
|
||||
recorder = calloc(1, sizeof(struct monkey_recorder_s));
|
||||
MONKEY_ASSERT_NULL(recorder);
|
||||
memset(recorder, 0, sizeof(struct monkey_recorder_s));
|
||||
|
||||
if (mode == MONKEY_RECORDER_MODE_RECORD)
|
||||
{
|
||||
@ -198,7 +197,6 @@ void monkey_recorder_delete(FAR struct monkey_recorder_s *recorder)
|
||||
{
|
||||
MONKEY_LOG_NOTICE("close fd: %d", recorder->fd);
|
||||
close(recorder->fd);
|
||||
recorder->fd = -1;
|
||||
}
|
||||
|
||||
free(recorder);
|
||||
@ -223,24 +221,26 @@ enum monkey_recorder_res_e monkey_recorder_write(
|
||||
cur_tick = monkey_tick_get();
|
||||
|
||||
switch (MONKEY_GET_DEV_TYPE(state->type))
|
||||
{
|
||||
case MONKEY_DEV_TYPE_TOUCH:
|
||||
len = snprintf(buffer, sizeof(buffer), MONKEY_REC_TOUCH_FMT,
|
||||
cur_tick,
|
||||
state->type,
|
||||
state->data.touch.x,
|
||||
state->data.touch.y,
|
||||
state->data.touch.is_pressed);
|
||||
break;
|
||||
case MONKEY_DEV_TYPE_BUTTON:
|
||||
len = snprintf(buffer, sizeof(buffer), MONKEY_REC_BTN_FMT,
|
||||
cur_tick,
|
||||
state->type,
|
||||
state->data.button.value);
|
||||
break;
|
||||
default:
|
||||
return MONKEY_RECORDER_RES_DEV_TYPE_ERROR;
|
||||
}
|
||||
{
|
||||
case MONKEY_DEV_TYPE_TOUCH:
|
||||
len = snprintf(buffer, sizeof(buffer), MONKEY_REC_TOUCH_FMT,
|
||||
cur_tick,
|
||||
state->type,
|
||||
state->data.touch.x,
|
||||
state->data.touch.y,
|
||||
state->data.touch.is_pressed);
|
||||
break;
|
||||
|
||||
case MONKEY_DEV_TYPE_BUTTON:
|
||||
len = snprintf(buffer, sizeof(buffer), MONKEY_REC_BTN_FMT,
|
||||
cur_tick,
|
||||
state->type,
|
||||
state->data.button.value);
|
||||
break;
|
||||
|
||||
default:
|
||||
return MONKEY_RECORDER_RES_DEV_TYPE_ERROR;
|
||||
}
|
||||
|
||||
if (len <= 0)
|
||||
{
|
||||
@ -300,32 +300,34 @@ enum monkey_recorder_res_e monkey_recorder_read(
|
||||
|
||||
switch (MONKEY_GET_DEV_TYPE(state->type))
|
||||
{
|
||||
case MONKEY_DEV_TYPE_TOUCH:
|
||||
converted = sscanf(buffer,
|
||||
MONKEY_REC_TOUCH_FMT,
|
||||
time_stamp,
|
||||
&dev_type,
|
||||
&state->data.touch.x,
|
||||
&state->data.touch.y,
|
||||
&state->data.touch.is_pressed);
|
||||
if (converted != 5)
|
||||
{
|
||||
return MONKEY_RECORDER_RES_PARSER_ERROR;
|
||||
}
|
||||
break;
|
||||
case MONKEY_DEV_TYPE_BUTTON:
|
||||
converted = sscanf(buffer,
|
||||
MONKEY_REC_BTN_FMT,
|
||||
time_stamp,
|
||||
&dev_type,
|
||||
&state->data.button.value);
|
||||
if (converted != 3)
|
||||
{
|
||||
return MONKEY_RECORDER_RES_PARSER_ERROR;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return MONKEY_RECORDER_RES_DEV_TYPE_ERROR;
|
||||
case MONKEY_DEV_TYPE_TOUCH:
|
||||
converted = sscanf(buffer,
|
||||
MONKEY_REC_TOUCH_FMT,
|
||||
time_stamp,
|
||||
&dev_type,
|
||||
&state->data.touch.x,
|
||||
&state->data.touch.y,
|
||||
&state->data.touch.is_pressed);
|
||||
if (converted != 5)
|
||||
{
|
||||
return MONKEY_RECORDER_RES_PARSER_ERROR;
|
||||
}
|
||||
break;
|
||||
|
||||
case MONKEY_DEV_TYPE_BUTTON:
|
||||
converted = sscanf(buffer,
|
||||
MONKEY_REC_BTN_FMT,
|
||||
time_stamp,
|
||||
&dev_type,
|
||||
&state->data.button.value);
|
||||
if (converted != 3)
|
||||
{
|
||||
return MONKEY_RECORDER_RES_PARSER_ERROR;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return MONKEY_RECORDER_RES_DEV_TYPE_ERROR;
|
||||
}
|
||||
|
||||
return MONKEY_RECORDER_RES_OK;
|
||||
|
@ -18,8 +18,8 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __MONKEY_RECORDER_H__
|
||||
#define __MONKEY_RECORDER_H__
|
||||
#ifndef __APPS_TESTING_MONKEY_MONKEY_RECORDER_H
|
||||
#define __APPS_TESTING_MONKEY_MONKEY_RECORDER_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
@ -107,4 +107,4 @@ enum monkey_recorder_res_e monkey_recorder_reset(
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MONKEY_RECORDER_H__ */
|
||||
#endif /* __APPS_TESTING_MONKEY_MONKEY_RECORDER_H */
|
||||
|
@ -18,8 +18,8 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __MONKEY_TYPE_H__
|
||||
#define __MONKEY_TYPE_H__
|
||||
#ifndef __APPS_TESTING_MONKEY_MONKEY_TYPE_H
|
||||
#define __APPS_TESTING_MONKEY_MONKEY_TYPE_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
@ -34,7 +34,7 @@
|
||||
|
||||
#define MONKEY_UINPUT_TYPE_MASK (0x10)
|
||||
#define MONKEY_IS_UINPUT_TYPE(type) (!!((type) & MONKEY_UINPUT_TYPE_MASK))
|
||||
#define MONKEY_GET_DEV_TYPE(type) (type & ~MONKEY_UINPUT_TYPE_MASK)
|
||||
#define MONKEY_GET_DEV_TYPE(type) ((type) & ~MONKEY_UINPUT_TYPE_MASK)
|
||||
#define MONKEY_DEV_MAX_NUM 2
|
||||
|
||||
/****************************************************************************
|
||||
@ -110,9 +110,9 @@ struct monkey_s
|
||||
FAR struct monkey_recorder_s *recorder;
|
||||
struct
|
||||
{
|
||||
struct monkey_dev_state_s state;
|
||||
uint32_t time_stamp;
|
||||
struct monkey_dev_state_s state;
|
||||
uint32_t time_stamp;
|
||||
} playback_ctx;
|
||||
};
|
||||
|
||||
#endif /* __MONKEY_TYPE_H__ */
|
||||
#endif /* __APPS_TESTING_MONKEY_MONKEY_TYPE_H */
|
||||
|
@ -18,8 +18,8 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __MONKEY_UTILS_H__
|
||||
#define __MONKEY_UTILS_H__
|
||||
#ifndef __APPS_TESTING_MONKEY_MONKEY_UTILS_H
|
||||
#define __APPS_TESTING_MONKEY_MONKEY_UTILS_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
@ -91,4 +91,4 @@ enum monkey_dev_type_e monkey_dev_name2type(FAR const char *name);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MONKEY_UTILS_H__ */
|
||||
#endif /* __APPS_TESTING_MONKEY_MONKEY_UTILS_H */
|
||||
|
Loading…
Reference in New Issue
Block a user