]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
change contition to reset methods
authorBastian Dehn <hhaalo@arcor.de>
Mon, 29 Jan 2024 21:05:36 +0000 (22:05 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Mon, 29 Jan 2024 21:05:36 +0000 (22:05 +0100)
src/kds_s2000w_handler.c

index e916359041f9f77ac32e7d7ef488dc601d32f698..c4766b65bce0ed7e64a4bcb8a4ccb26ec4315b1f 100644 (file)
@@ -61,20 +61,30 @@ void _load_options()
        resp = NULL;
 }
 
-void _reset_output_type()
+int _reset_output_type(const char* current_value)
 {
-       json_object* value_object = json_object_object_get(config, "OutputType");
-       const char* reset_value_ptr = "Images";
-       _write_string_value_to_json(value_object, (void*) reset_value_ptr);
-       value_object = NULL;
+       if (strcmp(current_value, "Color_BW") != 0) {
+               json_object* value_object = json_object_object_get(config, "OutputType");
+               const char* reset_value_ptr = "Images";
+               _write_string_value_to_json(value_object, (void*) reset_value_ptr);
+               value_object = NULL;
+               return 1;
+       }
+
+       return 0;
 }
 
-void _color_change_to_color_bw()
+int _color_change_to_color_bw(const char* current_value)
 {
-       json_object* value_object = json_object_object_get(config, "ColorMode");
-       const char* reset_value_ptr = "Color_BW";
-       _write_string_value_to_json(value_object, (void*) reset_value_ptr);
-       value_object = NULL;
+       if (strcmp(current_value, "Color_BW") != 0) {
+               json_object* value_object = json_object_object_get(config, "ColorMode");
+               const char* reset_value_ptr = "Color_BW";
+               _write_string_value_to_json(value_object, (void*) reset_value_ptr);
+               value_object = NULL;
+               return 1;
+       }
+
+       return 0;
 }
 
 current_state* kds_s2000w_handler_open()
@@ -267,11 +277,11 @@ void kds_s2000w_handler_set_option(int option, void* value, int* info)
                case 4:
                        value_object = json_object_object_get(config, "ColorMode");
                        _write_string_value_to_json(value_object, value);
+                       const char* current_value = (const char*) value;
 
-                       if (strcmp((const char*) value, "Color_BW") != 0) {
-                               _reset_output_type();
+                       if (_reset_output_type(current_value))
                                *info = RELOAD_OPTIONS;
-                       }
+
                        break;
                case 5:
                        value_object = json_object_object_get(config, "SkipBlankPages");
@@ -296,10 +306,9 @@ void kds_s2000w_handler_set_option(int option, void* value, int* info)
 
                        value_object = json_object_object_get(config, "ColorMode");
                        const char* color_mode = json_object_get_string(value_object);
-                       if (strcmp(color_mode, "Color_BW") != 0) {
-                               _color_change_to_color_bw();
+                       if (_color_change_to_color_bw(color_mode))
                                *info = RELOAD_OPTIONS;
-                       }
+
                        break;
                case 10:
                        value_object = json_object_object_get(config, "ColorAutoBrightnessMode");