diff options
author | Mike Isely <isely@pobox.com> | 2006-06-25 20:04:40 -0300 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2006-06-27 00:17:27 -0300 |
commit | 332139635a8c0431cc2eb67adf1e983eb96728e3 (patch) | |
tree | e7646bc367486fd1b52bd80bc789fe26307ed9fe /drivers/media/video/pvrusb2/pvrusb2-ctrl.c | |
parent | 077203a7d464f6ea7c94b4f3ea4b5bd246285fcd (diff) |
V4L/DVB (4239): Handle boolean controls in pvrusb2
Signed-off-by: Mike Isely <isely@pobox.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/pvrusb2/pvrusb2-ctrl.c')
-rw-r--r-- | drivers/media/video/pvrusb2/pvrusb2-ctrl.c | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c index 3577d5bfa00..d644afec5a5 100644 --- a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c +++ b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c @@ -53,6 +53,8 @@ int pvr2_ctrl_set_mask_value(struct pvr2_ctrl *cptr,int mask,int val) if (val >= cptr->info->def.type_enum.count) { break; } + } else if (cptr->info->type != pvr2_ctl_bool) { + break; } ret = cptr->info->set_value(cptr,mask,val); } else { @@ -308,6 +310,14 @@ static unsigned int gen_bitmask_string(int msk,int val,int msk_only, } +static const char *boolNames[] = { + "false", + "true", + "no", + "yes", +}; + + static int parse_token(const char *ptr,unsigned int len, int *valptr, const char **names,unsigned int namecnt) @@ -338,7 +348,7 @@ static int parse_token(const char *ptr,unsigned int len, *valptr = simple_strtol(buf,&p2,0); if (negfl) *valptr = -(*valptr); if (*p2) return -EINVAL; - return 0; + return 1; } @@ -453,21 +463,31 @@ int pvr2_ctrl_sym_to_value(struct pvr2_ctrl *cptr, LOCK_TAKE(cptr->hdw->big_lock); do { if (cptr->info->type == pvr2_ctl_int) { ret = parse_token(ptr,len,valptr,0,0); - if ((ret == 0) && + if ((ret >= 0) && ((*valptr < cptr->info->def.type_int.min_value) || (*valptr > cptr->info->def.type_int.max_value))) { - ret = -EINVAL; + ret = -ERANGE; } if (maskptr) *maskptr = ~0; + } else if (cptr->info->type == pvr2_ctl_bool) { + ret = parse_token( + ptr,len,valptr,boolNames, + sizeof(boolNames)/sizeof(boolNames[0])); + if (ret == 1) { + *valptr = *valptr ? !0 : 0; + } else if (ret == 0) { + *valptr = (*valptr & 1) ? !0 : 0; + } + if (maskptr) *maskptr = 1; } else if (cptr->info->type == pvr2_ctl_enum) { ret = parse_token( ptr,len,valptr, cptr->info->def.type_enum.value_names, cptr->info->def.type_enum.count); - if ((ret == 0) && + if ((ret >= 0) && ((*valptr < 0) || (*valptr >= cptr->info->def.type_enum.count))) { - ret = -EINVAL; + ret = -ERANGE; } if (maskptr) *maskptr = ~0; } else if (cptr->info->type == pvr2_ctl_bitmask) { @@ -493,6 +513,9 @@ int pvr2_ctrl_value_to_sym_internal(struct pvr2_ctrl *cptr, if (cptr->info->type == pvr2_ctl_int) { *len = scnprintf(buf,maxlen,"%d",val); ret = 0; + } else if (cptr->info->type == pvr2_ctl_bool) { + *len = scnprintf(buf,maxlen,"%s",val ? "true" : "false"); + ret = 0; } else if (cptr->info->type == pvr2_ctl_enum) { const char **names; names = cptr->info->def.type_enum.value_names; |