int V4Linux2Camera::getCameraSetting(int mode) {

    if (!hasCameraSetting(mode)) return 0;
    v4l2_control v4l2_ctrl;

    switch (mode) {
        case BRIGHTNESS: v4l2_ctrl.id = V4L2_CID_BRIGHTNESS; break;
        case CONTRAST: v4l2_ctrl.id = V4L2_CID_CONTRAST; break;
        case SHARPNESS: v4l2_ctrl.id = V4L2_CID_SHARPNESS; break;
        case GAIN: v4l2_ctrl.id = V4L2_CID_GAIN; break;
        case AUTO_GAIN: v4l2_ctrl.id = V4L2_CID_AUTOGAIN; break;
        case EXPOSURE: v4l2_ctrl.id = V4L2_CID_EXPOSURE_ABSOLUTE; break;
        case AUTO_EXPOSURE: return getCameraSettingAuto(EXPOSURE); break;
        case WHITE: v4l2_ctrl.id = V4L2_CID_WHITE_BALANCE_TEMPERATURE; break;
        case AUTO_WHITE: v4l2_ctrl.id = V4L2_CID_AUTO_WHITE_BALANCE; break;
        case FOCUS: v4l2_ctrl.id = V4L2_CID_FOCUS_ABSOLUTE; break;
        case AUTO_FOCUS: return getCameraSettingAuto(FOCUS);
        case BACKLIGHT: v4l2_ctrl.id = V4L2_CID_BACKLIGHT_COMPENSATION; break;
        case POWERLINE: v4l2_ctrl.id = V4L2_CID_POWER_LINE_FREQUENCY; break;
        case GAMMA: v4l2_ctrl.id = V4L2_CID_GAMMA; break;
        case SATURATION: v4l2_ctrl.id = V4L2_CID_SATURATION; break;
        case COLOR_HUE: v4l2_ctrl.id = V4L2_CID_HUE; break;
        case AUTO_HUE: v4l2_ctrl.id = V4L2_CID_HUE_AUTO; break;
        case COLOR_RED: v4l2_ctrl.id = V4L2_CID_RED_BALANCE; break;
        case COLOR_BLUE: v4l2_ctrl.id = V4L2_CID_BLUE_BALANCE; break;
        default: return 0;
    }

    if ((ioctl(dev_handle, VIDIOC_G_CTRL, &v4l2_ctrl)) < 0) {
        return 0;
    } else return v4l2_ctrl.value;
}
void CameraEngine::updateSettings()  {

    int brightness = getCameraSetting(BRIGHTNESS);
    if (brightness==getMinCameraSetting(BRIGHTNESS)) config.brightness=SETTING_MIN;
    if (brightness==getMaxCameraSetting(BRIGHTNESS)) config.brightness=SETTING_MAX;
    if (brightness==getDefaultCameraSetting(BRIGHTNESS)) config.brightness=SETTING_DEFAULT;
    //printf("brightness %d\n",brightness);

    int contrast = getCameraSetting(CONTRAST);
    if (contrast==getMinCameraSetting(CONTRAST)) config.contrast=SETTING_MIN;
    if (contrast==getMaxCameraSetting(CONTRAST)) config.contrast=SETTING_MAX;
    if (contrast==getDefaultCameraSetting(CONTRAST)) config.contrast=SETTING_DEFAULT;
    //printf("contrast %d\n",contrast);

    int gain = getCameraSetting(GAIN);
    if (gain==getMinCameraSetting(GAIN)) config.gain=SETTING_MIN;
    if (gain==getMaxCameraSetting(GAIN)) config.gain=SETTING_MAX;
    if (gain==getDefaultCameraSetting(GAIN)) config.gain=SETTING_DEFAULT;
    //printf("gain %d\n",gain);

    int exposure = getCameraSetting(EXPOSURE);
    if (exposure==getMinCameraSetting(EXPOSURE)) config.exposure=SETTING_MIN;
    if (exposure==getMaxCameraSetting(EXPOSURE)) config.exposure=SETTING_MAX;
    if (getCameraSettingAuto(EXPOSURE)==true) config.exposure=SETTING_AUTO;
    if (exposure==getDefaultCameraSetting(EXPOSURE)) config.exposure=SETTING_DEFAULT;
    //printf("exposure %d\n",exposure);

    int sharpness = getCameraSetting(SHARPNESS);
    if (sharpness==getMinCameraSetting(SHARPNESS)) config.sharpness=SETTING_MIN;
    if (sharpness==getMaxCameraSetting(SHARPNESS)) config.sharpness=SETTING_MAX;
    if (sharpness==getDefaultCameraSetting(SHARPNESS)) config.sharpness=SETTING_DEFAULT;
    //printf("sharpness %d\n",sharpness);

    int focus = getCameraSetting(FOCUS);
    if (focus==getMinCameraSetting(FOCUS)) config.focus=SETTING_MIN;
    if (focus==getMaxCameraSetting(FOCUS)) config.focus=SETTING_MAX;
    if (focus==getDefaultCameraSetting(FOCUS)) config.focus=SETTING_DEFAULT;
    //printf("focus %d\n",focus);

    int gamma = getCameraSetting(GAMMA);
    if (gamma==getMinCameraSetting(GAMMA)) config.gamma=SETTING_MIN;
    if (gamma==getMaxCameraSetting(GAMMA)) config.gamma=SETTING_MAX;
    if (gamma==getDefaultCameraSetting(GAMMA)) config.gamma=SETTING_DEFAULT;
    if (getCameraSettingAuto(GAMMA)==true) config.gamma=SETTING_AUTO;
    //printf("gamma %d\n",gamma);

}