@@ -100,14 +100,15 @@ CameraClass::status() const {
100100 return result;
101101 }
102102
103- result.resolution = Resolution (sensor->status .framesize );
104- result.brightness = sensor->status .brightness ;
105- result.contrast = sensor->status .contrast ;
106- result.saturation = sensor->status .saturation ;
107- result.lightMode = static_cast <LightMode>(sensor->status .wb_mode );
108- result.specialEffect = static_cast <SpecialEffect>(sensor->status .special_effect );
109- result.hmirror = sensor->status .hmirror != 0 ;
110- result.vflip = sensor->status .vflip != 0 ;
103+ const auto & ss = sensor->status ;
104+ result.resolution = Resolution (ss.framesize );
105+ result.brightness = ss.brightness ;
106+ result.contrast = ss.contrast ;
107+ result.saturation = ss.saturation ;
108+ result.lightMode = ss.awb_gain ? static_cast <LightMode>(ss.wb_mode ) : LightMode::NONE;
109+ result.specialEffect = static_cast <SpecialEffect>(ss.special_effect );
110+ result.hmirror = ss.hmirror != 0 ;
111+ result.vflip = ss.vflip != 0 ;
111112 return result;
112113}
113114
@@ -127,33 +128,39 @@ CameraClass::update(const Settings& settings, int sleepFor) {
127128 } \
128129 } while (false )
129130
130- #define UPDATE (STATUS_MEM, SETTING_MEM , SETTER_TYP ) \
131+ #define UPDATE (STATUS_MEM, value , SETTER_TYP ) \
131132 do { \
132133 int prev = static_cast <int >(sensor->status .STATUS_MEM ); \
133- int next = static_cast <int >(settings. SETTING_MEM ); \
134- if (prev != static_cast < int >(settings. SETTING_MEM )) { \
135- int res = sensor->set_ ##STATUS_MEM (sensor, static_cast <SETTER_TYP>(next )); \
136- ESP32CAM_LOG (" update " #STATUS_MEM " %d => %d %s" , prev, next, \
134+ int desired = static_cast <int >(value); \
135+ if (prev != desired) { \
136+ int res = sensor->set_ ##STATUS_MEM (sensor, static_cast <SETTER_TYP>(desired )); \
137+ ESP32CAM_LOG (" update " #STATUS_MEM " %d => %d %s" , prev, desired, \
137138 res == 0 ? " success" : " failure" ); \
138139 if (res != 0 ) { \
139140 return false ; \
140141 } \
141142 } \
142143 } while (false )
143- #define UPDATE1 (MEM ) UPDATE(MEM, MEM, int )
144+ #define UPDATE1 (MEM ) UPDATE(MEM, settings. MEM, int )
144145
145146 CHECK_RANGE (brightness, -2 , 2 );
146147 CHECK_RANGE (contrast, -2 , 2 );
147148 CHECK_RANGE (saturation, -2 , 2 );
148- CHECK_RANGE (lightMode, 0 , 4 );
149+ CHECK_RANGE (lightMode, - 1 , 4 );
149150 CHECK_RANGE (specialEffect, 0 , 6 );
150151
151- UPDATE (framesize, resolution.as <framesize_t >(), framesize_t );
152+ UPDATE (framesize, settings. resolution .as <framesize_t >(), framesize_t );
152153 UPDATE1 (brightness);
153154 UPDATE1 (contrast);
154155 UPDATE1 (saturation);
155- UPDATE (wb_mode, lightMode, int );
156- UPDATE (special_effect, specialEffect, int );
156+ if (settings.lightMode == LightMode::NONE) {
157+ UPDATE (awb_gain, 0 , int );
158+ UPDATE (wb_mode, 0 , int );
159+ } else {
160+ UPDATE (awb_gain, 1 , int );
161+ UPDATE (wb_mode, settings.lightMode , int );
162+ }
163+ UPDATE (special_effect, settings.specialEffect , int );
157164 UPDATE1 (hmirror);
158165 UPDATE1 (vflip);
159166
0 commit comments