Skip to content

Commit 57d9e27

Browse files
author
Hasnain Virk
committed
Tidying up the boiler plate code
A little tidying up was needed as there was some boiler plate code that could be shoved into a corner and reused.
1 parent 24178bc commit 57d9e27

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

features/cellular/framework/targets/QUECTEL/EC2X/QUECTEL_EC2X.cpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,27 @@ CellularDevice *CellularDevice::get_default_instance()
6666
return &device;
6767
}
6868

69-
nsapi_error_t QUECTEL_EC2X::hard_power_on()
69+
nsapi_error_t QUECTEL_EC2X::press_power_button(uint32_t timeout)
7070
{
7171
if (_pwr_key.is_connected()) {
7272
_pwr_key = 1;
73-
ThisThread::sleep_for(600);
73+
ThisThread::sleep_for(timeout);
7474
_pwr_key = 0;
7575
ThisThread::sleep_for(100);
7676
}
7777

7878
return NSAPI_ERROR_OK;
7979
}
8080

81+
nsapi_error_t QUECTEL_EC2X::hard_power_on()
82+
{
83+
return press_power_button(600);
84+
}
85+
8186
nsapi_error_t QUECTEL_EC2X::hard_power_off()
8287

8388
{
84-
if (_pwr_key.is_connected()) {
85-
_pwr_key = 1;
86-
ThisThread::sleep_for(750);
87-
_pwr_key = 0;
88-
ThisThread::sleep_for(100);
89-
}
90-
91-
return NSAPI_ERROR_OK;
89+
return press_power_button(750);
9290
}
9391

9492
nsapi_error_t QUECTEL_EC2X::soft_power_on()
@@ -119,14 +117,7 @@ nsapi_error_t QUECTEL_EC2X::soft_power_on()
119117

120118
nsapi_error_t QUECTEL_EC2X::soft_power_off()
121119
{
122-
if (_pwr_key.is_connected()) {
123-
_pwr_key = 1;
124-
ThisThread::sleep_for(750);
125-
_pwr_key = 0;
126-
ThisThread::sleep_for(100);
127-
}
128-
129-
return NSAPI_ERROR_OK;
120+
return hard_power_off();
130121
}
131122

132123
#endif

features/cellular/framework/targets/QUECTEL/EC2X/QUECTEL_EC2X.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class QUECTEL_EC2X : public AT_CellularDevice {
4141
virtual nsapi_error_t soft_power_off();
4242

4343
private:
44+
nsapi_error_t press_power_button(uint32_t timeout);
4445
DigitalOut _pwr_key;
4546
DigitalOut _rst;
4647
};

0 commit comments

Comments
 (0)