@@ -31,8 +31,6 @@ using irutils::addIntToString;
3131using  irutils::addLabeledString;
3232using  irutils::addModeToString;
3333using  irutils::addTempToString;
34- using  irutils::setBit;
35- using  irutils::setBits;
3634
3735#if  SEND_TROTEC
3836// / Send a Trotec message.
@@ -64,7 +62,7 @@ void IRsend::sendTrotec(const unsigned char data[], const uint16_t nbytes,
6462// / @param[in] use_modulation Is frequency modulation to be used?
6563IRTrotecESP::IRTrotecESP (const  uint16_t  pin, const  bool  inverted,
6664                         const  bool  use_modulation)
67-     : _irsend(pin, inverted, use_modulation) { this -> stateReset (); }
65+     : _irsend(pin, inverted, use_modulation) { stateReset (); }
6866
6967// / Set up hardware to be able to send a message.
7068void  IRTrotecESP::begin (void ) { _irsend.begin (); }
@@ -96,118 +94,114 @@ bool IRTrotecESP::validChecksum(const uint8_t state[], const uint16_t length) {
9694
9795// / Calculate & set the checksum for the current internal state of the remote.
9896void  IRTrotecESP::checksum (void ) {
99-   remote_state[kTrotecStateLength  - 1 ] = sumBytes (remote_state + 2 ,
100-                                                   kTrotecStateLength  - 3 );
97+   _.Sum  = sumBytes (_.raw  + 2 , kTrotecStateLength  - 3 );
10198}
10299
103100// / Reset the state of the remote to a known good state/sequence.
104101void  IRTrotecESP::stateReset (void ) {
105-   for  (uint8_t  i = 2 ; i < kTrotecStateLength ; i++) remote_state [i] = 0x0 ;
102+   for  (uint8_t  i = 2 ; i < kTrotecStateLength ; i++) _. raw [i] = 0x0 ;
106103
107-   remote_state[ 0 ]  = kTrotecIntro1 ;
108-   remote_state[ 1 ]  = kTrotecIntro2 ;
104+   _. Intro1  = kTrotecIntro1 ;
105+   _. Intro2  = kTrotecIntro2 ;
109106
110-   this -> setPower ( false ) ;
111-   this -> setTemp (kTrotecDefTemp );
112-   this -> setSpeed ( kTrotecFanMed ) ;
113-   this -> setMode ( kTrotecAuto ) ;
107+   _. Power  =  false ;
108+   setTemp (kTrotecDefTemp );
109+   _. Fan  =  kTrotecFanMed ;
110+   _. Mode  =  kTrotecAuto ;
114111}
115112
116113// / Get a PTR to the internal state/code for this protocol.
117114// / @return PTR to a code for this protocol based on the current internal state.
118115uint8_t * IRTrotecESP::getRaw (void ) {
119-   this -> checksum ();
120-   return  remote_state ;
116+   checksum ();
117+   return  _. raw ;
121118}
122119
123120// / Set the internal state from a valid code for this protocol.
124121// / @param[in] state A valid code for this protocol.
125122void  IRTrotecESP::setRaw (const  uint8_t  state[]) {
126-   memcpy (remote_state , state, kTrotecStateLength );
123+   memcpy (_. raw , state, kTrotecStateLength );
127124}
128125
129126// / Set the requested power state of the A/C to on.
130- void  IRTrotecESP::on (void ) { this -> setPower (true ); }
127+ void  IRTrotecESP::on (void ) { setPower (true ); }
131128
132129// / Set the requested power state of the A/C to off.
133- void  IRTrotecESP::off (void ) { this -> setPower (false ); }
130+ void  IRTrotecESP::off (void ) { setPower (false ); }
134131
135132// / Change the power setting.
136133// / @param[in] on true, the setting is on. false, the setting is off.
137134void  IRTrotecESP::setPower (const  bool  on) {
138-   setBit (&remote_state[ 2 ],  kTrotecPowerBitOffset ,  on) ;
135+   _. Power  =  on;
139136}
140137
141138// / Get the value of the current power setting.
142139// / @return true, the setting is on. false, the setting is off.
143- bool  IRTrotecESP::getPower (void ) {
144-   return  GETBIT8 (remote_state[ 2 ],  kTrotecPowerBitOffset ) ;
140+ bool  IRTrotecESP::getPower (void ) const   {
141+   return  _. Power ;
145142}
146143
147144// / Set the speed of the fan.
148145// / @param[in] fan The desired setting.
149146void  IRTrotecESP::setSpeed (const  uint8_t  fan) {
150147  uint8_t  speed = std::min (fan, kTrotecFanHigh );
151-   setBits (&remote_state[ 2 ],  kTrotecFanOffset ,  kTrotecFanSize ,  speed) ;
148+   _. Fan  =  speed;
152149}
153150
154151// / Get the current fan speed setting.
155152// / @return The current fan speed/mode.
156- uint8_t  IRTrotecESP::getSpeed (void ) {
157-   return  GETBITS8 (remote_state[ 2 ],  kTrotecFanOffset ,  kTrotecFanSize ) ;
153+ uint8_t  IRTrotecESP::getSpeed (void ) const   {
154+   return  _. Fan ;
158155}
159156
160157// / Set the operating mode of the A/C.
161158// / @param[in] mode The desired operating mode.
162159void  IRTrotecESP::setMode (const  uint8_t  mode) {
163-   setBits (&remote_state[2 ], kTrotecModeOffset , kTrotecModeSize ,
164-           (mode > kTrotecFan ) ? kTrotecAuto  : mode);
160+   _.Mode  = (mode > kTrotecFan ) ? kTrotecAuto  : mode;
165161}
166162
167163// / Get the operating mode setting of the A/C.
168164// / @return The current operating mode setting.
169- uint8_t  IRTrotecESP::getMode (void ) {
170-   return  GETBITS8 (remote_state[ 2 ],  kTrotecModeOffset ,  kTrotecModeSize ) ;
165+ uint8_t  IRTrotecESP::getMode (void ) const   {
166+   return  _. Mode ;
171167}
172168
173169// / Set the temperature.
174170// / @param[in] celsius The temperature in degrees celsius.
175171void  IRTrotecESP::setTemp (const  uint8_t  celsius) {
176172  uint8_t  temp = std::max (celsius, kTrotecMinTemp );
177173  temp = std::min (temp, kTrotecMaxTemp );
178-   setBits (&remote_state[3 ], kTrotecTempOffset , kTrotecTempSize ,
179-           temp - kTrotecMinTemp );
174+   _.Temp  = temp - kTrotecMinTemp ;
180175}
181176
182177// / Get the current temperature setting.
183178// / @return The current setting for temp. in degrees celsius.
184- uint8_t  IRTrotecESP::getTemp (void ) {
185-   return  GETBITS8 (remote_state[3 ], kTrotecTempOffset , kTrotecTempSize ) +
186-       kTrotecMinTemp ;
179+ uint8_t  IRTrotecESP::getTemp (void ) const  {
180+   return  _.Temp  + kTrotecMinTemp ;
187181}
188182
189183// / Set the Sleep setting of the A/C.
190184// / @param[in] on true, the setting is on. false, the setting is off.
191185void  IRTrotecESP::setSleep (const  bool  on) {
192-   setBit (&remote_state[ 3 ],  kTrotecSleepBitOffset ,  on) ;
186+   _. Sleep  =  on;
193187}
194188
195189// / Get the Sleep setting of the A/C.
196190// / @return true, the setting is on. false, the setting is off.
197- bool  IRTrotecESP::getSleep (void ) {
198-   return  GETBIT8 (remote_state[ 3 ],  kTrotecSleepBitOffset ) ;
191+ bool  IRTrotecESP::getSleep (void ) const   {
192+   return  _. Sleep ;
199193}
200194
201195// / Set the timer time in nr. of Hours.
202196// / @param[in] timer Nr. of Hours. Max is `kTrotecMaxTimer`
203197void  IRTrotecESP::setTimer (const  uint8_t  timer) {
204-   setBit (&remote_state[ 5 ],  kTrotecTimerBitOffset ,  timer) ;
205-   remote_state[ 6 ]  = (timer > kTrotecMaxTimer ) ? kTrotecMaxTimer  : timer;
198+   _. Timer  =  timer;
199+   _. Hours  = (timer > kTrotecMaxTimer ) ? kTrotecMaxTimer  : timer;
206200}
207201
208202// / Get the timer time in nr. of Hours.
209203// / @return Nr. of Hours.
210- uint8_t  IRTrotecESP::getTimer (void ) { return  remote_state[ 6 ] ; }
204+ uint8_t  IRTrotecESP::getTimer (void ) const   { return  _. Hours ; }
211205
212206// / Convert a stdAc::opmode_t enum into its native mode.
213207// / @param[in] mode The enum to be converted.
@@ -262,15 +256,15 @@ stdAc::fanspeed_t IRTrotecESP::toCommonFanSpeed(const uint8_t spd) {
262256
263257// / Convert the current internal state into its stdAc::state_t equivalent.
264258// / @return The stdAc equivalent of the native settings.
265- stdAc::state_t  IRTrotecESP::toCommon (void ) {
259+ stdAc::state_t  IRTrotecESP::toCommon (void ) const   {
266260  stdAc::state_t  result;
267261  result.protocol  = decode_type_t ::TROTEC;
268-   result.power  = this -> getPower () ;
269-   result.mode  = this -> toCommonMode (this -> getMode () );
262+   result.power  = _. Power ;
263+   result.mode  = toCommonMode (_. Mode );
270264  result.celsius  = true ;
271-   result.degrees  = this -> getTemp ();
272-   result.fanspeed  = this -> toCommonFanSpeed (this -> getSpeed () );
273-   result.sleep  = this -> getSleep ()  ? 0  : -1 ;
265+   result.degrees  = getTemp ();
266+   result.fanspeed  = toCommonFanSpeed (_. Fan );
267+   result.sleep  = _. Sleep  ? 0  : -1 ;
274268  //  Not supported.
275269  result.model  = -1 ;  //  Not supported.
276270  result.swingv  = stdAc::swingv_t ::kOff ;
@@ -288,16 +282,16 @@ stdAc::state_t IRTrotecESP::toCommon(void) {
288282
289283// / Convert the current internal state into a human readable string.
290284// / @return A human readable string.
291- String IRTrotecESP::toString (void ) {
285+ String IRTrotecESP::toString (void ) const   {
292286  String result = " " 
293287  result.reserve (100 );  //  Reserve some heap for the string to reduce fragging.
294-   result += addBoolToString (getPower () , kPowerStr , false );
295-   result += addModeToString (getMode () , kTrotecAuto , kTrotecCool , kTrotecAuto ,
288+   result += addBoolToString (_. Power , kPowerStr , false );
289+   result += addModeToString (_. Mode , kTrotecAuto , kTrotecCool , kTrotecAuto ,
296290                            kTrotecDry , kTrotecFan );
297291  result += addTempToString (getTemp ());
298-   result += addFanToString (getSpeed () , kTrotecFanHigh , kTrotecFanLow ,
292+   result += addFanToString (_. Fan , kTrotecFanHigh , kTrotecFanLow ,
299293                           kTrotecFanHigh , kTrotecFanHigh , kTrotecFanMed );
300-   result += addBoolToString (getSleep () , kSleepStr );
294+   result += addBoolToString (_. Sleep , kSleepStr );
301295  return  result;
302296}
303297
0 commit comments