diff options
author | Mike Isely <isely@pobox.com> | 2006-06-25 18:04:40 -0500 |
---|---|---|
committer | Mike Isely <isely@pobox.com> | 2006-06-25 18:04:40 -0500 |
commit | 235a84bf2bb998390130641e216fcbdd91f08a51 (patch) | |
tree | d8a345359e2e6fb007cf62f91a5a3408439a652e /linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c | |
parent | 24cb66707a7281272bbb6a73c60ddca94eb5d6a7 (diff) | |
download | mediapointer-dvb-s2-235a84bf2bb998390130641e216fcbdd91f08a51.tar.gz mediapointer-dvb-s2-235a84bf2bb998390130641e216fcbdd91f08a51.tar.bz2 |
Handle boolean controls in pvrusb2
From: Mike Isely <isely@pobox.com>
Signed-off-by: Mike Isely <isely@pobox.com>
Diffstat (limited to 'linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c')
-rw-r--r-- | linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c b/linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c index e55f43e44..0b1157def 100644 --- a/linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c +++ b/linux/drivers/media/video/pvrusb2/pvrusb2-ctrl.c @@ -58,6 +58,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 { @@ -313,6 +315,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) @@ -343,7 +353,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; } @@ -458,21 +468,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) { @@ -498,6 +518,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; |