stk11xx-sysfs.c

Go to the documentation of this file.
00001 
00034 #include <linux/module.h>
00035 #include <linux/init.h>
00036 #include <linux/kernel.h>
00037 #include <linux/errno.h>
00038 #include <linux/slab.h>
00039 #include <linux/kref.h>
00040 #include <linux/device.h>
00041 
00042 #include <linux/usb.h>
00043 //#include <linux/videodev2.h>
00044 #include <media/v4l2-common.h>
00045 
00046 #include "stk11xx.h"
00047 
00048 
00049 extern const struct stk11xx_coord stk11xx_image_sizes[STK11XX_NBR_SIZES];
00050 
00051 
00061 static ssize_t show_release(struct class_device *class, char *buf)
00062 {
00063     struct video_device *vdev = to_video_device(class);
00064     struct usb_stk11xx *dev = video_get_drvdata(vdev);
00065 
00066     return sprintf(buf, "%d\n", dev->release);
00067 }
00068 
00069 
00079 static ssize_t show_videostatus(struct class_device *class, char *buf)
00080 {
00081     struct video_device *vdev = to_video_device(class);
00082     struct usb_stk11xx *dev = video_get_drvdata(vdev);
00083 
00084     return sprintf(buf,
00085             "Nbr ISOC errors    : %d\n"
00086             "Nbr dropped frames : %d\n"
00087             "Nbr dumped frames  : %d\n",
00088             dev->visoc_errors,
00089             dev->vframes_error,
00090             dev->vframes_dumped);
00091 }
00092 
00093 
00103 static ssize_t show_informations(struct class_device *class, char *buf)
00104 {
00105     int width, height;
00106 
00107     struct video_device *vdev = to_video_device(class);
00108     struct usb_stk11xx *dev = video_get_drvdata(vdev);
00109 
00110 
00111     switch (dev->resolution) {
00112         case STK11XX_80x60:
00113         case STK11XX_128x96:
00114         case STK11XX_160x120:
00115         case STK11XX_213x160:
00116         case STK11XX_320x240:
00117         case STK11XX_640x480:
00118             width = stk11xx_image_sizes[STK11XX_640x480].x;
00119             height = stk11xx_image_sizes[STK11XX_640x480].y;
00120             break;
00121 
00122         case STK11XX_800x600:
00123         case STK11XX_1024x768:
00124         case STK11XX_1280x1024:
00125             width = stk11xx_image_sizes[STK11XX_1280x1024].x;
00126             height = stk11xx_image_sizes[STK11XX_1280x1024].y;
00127             break;
00128 
00129         default:
00130             width = 0;
00131             height = 0;
00132     }
00133 
00134     return sprintf(buf,
00135             "Asked resolution  : %dx%d\n"
00136             "Driver resolution : %dx%d\n"
00137             "Webcam resolution : %dx%d\n",
00138             dev->view.x, dev->view.y,
00139             stk11xx_image_sizes[dev->resolution].x, stk11xx_image_sizes[dev->resolution].y,
00140             width, height);
00141 }
00142 
00143 
00153 static ssize_t show_brightness(struct class_device *class, char *buf)
00154 {
00155     struct video_device *vdev = to_video_device(class);
00156     struct usb_stk11xx *dev = video_get_drvdata(vdev);
00157 
00158     return sprintf(buf, "%X\n", dev->vsettings.brightness);
00159 }
00160 
00161 
00171 static ssize_t store_brightness(struct class_device *class, const char *buf, size_t count)
00172 {
00173     char *endp;
00174     unsigned long value;
00175 
00176     struct video_device *vdev = to_video_device(class);
00177     struct usb_stk11xx *dev = video_get_drvdata(vdev);
00178 
00179     value = simple_strtoul(buf, &endp, 16);
00180 
00181     dev->vsettings.brightness = (int) value;
00182 
00183     dev_stk11xx_set_camera_quality(dev);
00184 
00185     return strlen(buf);
00186 }
00187 
00197 static ssize_t show_contrast(struct class_device *class, char *buf)
00198 {
00199     struct video_device *vdev = to_video_device(class);
00200     struct usb_stk11xx *dev = video_get_drvdata(vdev);
00201 
00202     return sprintf(buf, "%X\n", dev->vsettings.contrast);
00203 }
00204 
00205 
00215 static ssize_t store_contrast(struct class_device *class, const char *buf, size_t count)
00216 {
00217     char *endp;
00218     unsigned long value;
00219 
00220     struct video_device *vdev = to_video_device(class);
00221     struct usb_stk11xx *dev = video_get_drvdata(vdev);
00222 
00223     value = simple_strtoul(buf, &endp, 16);
00224 
00225     dev->vsettings.contrast = (int) value;
00226 
00227     dev_stk11xx_set_camera_quality(dev);
00228 
00229     return strlen(buf);
00230 }
00231 
00232 
00242 static ssize_t show_whitebalance(struct class_device *class, char *buf)
00243 {
00244     struct video_device *vdev = to_video_device(class);
00245     struct usb_stk11xx *dev = video_get_drvdata(vdev);
00246 
00247     return sprintf(buf, "%X\n", dev->vsettings.whiteness);
00248 }
00249 
00250 
00260 static ssize_t store_whitebalance(struct class_device *class, const char *buf, size_t count)
00261 {
00262     char *endp;
00263     unsigned long value;
00264 
00265     struct video_device *vdev = to_video_device(class);
00266     struct usb_stk11xx *dev = video_get_drvdata(vdev);
00267 
00268     value = simple_strtoul(buf, &endp, 16);
00269 
00270     dev->vsettings.whiteness = (int) value;
00271 
00272     dev_stk11xx_set_camera_quality(dev);
00273 
00274     return strlen(buf);
00275 }
00276 
00277 
00287 static ssize_t show_hflip(struct class_device *class, char *buf)
00288 {
00289     struct video_device *vdev = to_video_device(class);
00290     struct usb_stk11xx *dev = video_get_drvdata(vdev);
00291 
00292     return sprintf(buf, "%d\n", dev->vsettings.hflip);
00293 }
00294 
00295 
00305 static ssize_t store_hflip(struct class_device *class, const char *buf, size_t count)
00306 {
00307     struct video_device *vdev = to_video_device(class);
00308     struct usb_stk11xx *dev = video_get_drvdata(vdev);
00309 
00310     if (strncmp(buf, "1", 1) == 0)
00311         dev->vsettings.hflip = 1;
00312     else if (strncmp(buf, "0", 1) == 0)
00313         dev->vsettings.hflip = 0;
00314     else
00315         return -EINVAL;
00316 
00317     return strlen(buf);
00318 }
00319 
00320 
00330 static ssize_t show_vflip(struct class_device *class, char *buf)
00331 {
00332     struct video_device *vdev = to_video_device(class);
00333     struct usb_stk11xx *dev = video_get_drvdata(vdev);
00334 
00335     return sprintf(buf, "%d\n", dev->vsettings.vflip);
00336 }
00337 
00338 
00348 static ssize_t store_vflip(struct class_device *class, const char *buf, size_t count)
00349 {
00350     struct video_device *vdev = to_video_device(class);
00351     struct usb_stk11xx *dev = video_get_drvdata(vdev);
00352 
00353     if (strncmp(buf, "1", 1) == 0)
00354         dev->vsettings.vflip = 1;
00355     else if (strncmp(buf, "0", 1) == 0)
00356         dev->vsettings.vflip = 0;
00357     else
00358         return -EINVAL;
00359 
00360     return strlen(buf);
00361 }
00362 
00363 
00364 
00365 
00366 static ssize_t runtest(struct class_device *class, const char *buf, size_t count)
00367 {
00368     char *endp;
00369     unsigned long value;
00370 
00371     struct video_device *vdev = to_video_device(class);
00372     struct usb_stk11xx *dev = video_get_drvdata(vdev);
00373 
00374     value = simple_strtoul(buf, &endp, 16);
00375 
00376     switch (value) {
00377         case 1:
00378             dev_stk11xx_set_camera_quality(dev);
00379             STK_INFO("1 run\n");
00380             break;
00381 
00382         case 2:
00383             dev_stk11xx_set_camera_fps(dev);
00384             STK_INFO("2 run\n");
00385             break;
00386 
00387         case 3:
00388             dev_stk11xx_camera_settings(dev);
00389             STK_INFO("3 run\n");
00390             break;
00391     }
00392 
00393     return strlen(buf);
00394 }
00395 
00396 
00397 
00398 static CLASS_DEVICE_ATTR(release, S_IRUGO, show_release, NULL);                                     
00399 static CLASS_DEVICE_ATTR(videostatus, S_IRUGO, show_videostatus, NULL);                             
00400 static CLASS_DEVICE_ATTR(informations, S_IRUGO, show_informations, NULL);                           
00401 static CLASS_DEVICE_ATTR(brightness, S_IRUGO | S_IWUGO, show_brightness, store_brightness);         
00402 static CLASS_DEVICE_ATTR(contrast, S_IRUGO | S_IWUGO, show_contrast, store_contrast);               
00403 static CLASS_DEVICE_ATTR(whitebalance, S_IRUGO | S_IWUGO, show_whitebalance, store_whitebalance);   
00404 static CLASS_DEVICE_ATTR(hflip, S_IRUGO | S_IWUGO, show_hflip, store_hflip);                        
00405 static CLASS_DEVICE_ATTR(vflip, S_IRUGO | S_IWUGO, show_vflip, store_vflip);                        
00406 static CLASS_DEVICE_ATTR(test, S_IRUGO | S_IWUGO, NULL, runtest);
00407 
00408 
00418 int stk11xx_create_sysfs_files(struct video_device *vdev)
00419 {
00420     int ret;
00421 
00422     ret = video_device_create_file(vdev, &class_device_attr_release);
00423     ret = video_device_create_file(vdev, &class_device_attr_videostatus);
00424     ret = video_device_create_file(vdev, &class_device_attr_informations);
00425     ret = video_device_create_file(vdev, &class_device_attr_brightness);
00426     ret = video_device_create_file(vdev, &class_device_attr_contrast);
00427     ret = video_device_create_file(vdev, &class_device_attr_whitebalance);
00428     ret = video_device_create_file(vdev, &class_device_attr_hflip);
00429     ret = video_device_create_file(vdev, &class_device_attr_vflip);
00430     ret = video_device_create_file(vdev, &class_device_attr_test);
00431 
00432     return ret;
00433 }
00434 
00435 
00445 void stk11xx_remove_sysfs_files(struct video_device *vdev)
00446 {
00447     video_device_remove_file(vdev, &class_device_attr_release);
00448     video_device_remove_file(vdev, &class_device_attr_videostatus);
00449     video_device_remove_file(vdev, &class_device_attr_informations);
00450     video_device_remove_file(vdev, &class_device_attr_brightness);
00451     video_device_remove_file(vdev, &class_device_attr_contrast);
00452     video_device_remove_file(vdev, &class_device_attr_whitebalance);
00453     video_device_remove_file(vdev, &class_device_attr_hflip);
00454     video_device_remove_file(vdev, &class_device_attr_vflip);
00455     video_device_remove_file(vdev, &class_device_attr_test);
00456 }
00457 

Generated on Tue Oct 2 06:18:12 2007 for SyntekUSBVideoCamera by  doxygen 1.5.3