Skip to content

Commit 587f4c0

Browse files
jhirsirlubos
authored andcommitted
samples: nrf9160: modem_shell: location: status led for the location
DK LED #1 (purple with Thingy91) is getting on for a while when location has been retrieved by the location command. Signed-off-by: Jani Hirsimäki <[email protected]>
1 parent ddb5e8b commit 587f4c0

File tree

6 files changed

+51
-8
lines changed

6 files changed

+51
-8
lines changed

doc/nrf/releases/release-notes-changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ nRF9160 samples
215215

216216
* Sample moved from :file:`samples/nrf9160/nrf_cloud_rest_cell_pos` to :file:`samples/nrf9160/nrf_cloud_rest_cell_location`.
217217

218+
* :ref:`modem_shell_application` sample:
219+
220+
* Added:
221+
222+
* LED 1 (nRF9160 DK)/Purple LED (Thingy:91) is lit for five seconds indicating that a current location has been acquired by using the ``location get`` command.
223+
218224
Thread samples
219225
--------------
220226

samples/nrf9160/modem_shell/README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,8 @@ LED indications
788788

789789
The LEDs have the following functions:
790790

791+
LED 1 (nRF9160 DK)/Purple LED (Thingy:91):
792+
Lit for five seconds when the current location has been successfully retrieved by using the ``location get`` command.
791793
LED 3 (nRF9160 DK)/Blue LED (Thingy:91):
792794
Indicates the LTE registration status.
793795

samples/nrf9160/modem_shell/src/link/link.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include "uart/uart_shell.h"
3333
#include "mosh_print.h"
34+
#include "mosh_defines.h"
3435

3536
#if defined(CONFIG_MOSH_SMS)
3637
#include "sms.h"
@@ -51,7 +52,6 @@ struct pdn_activation_status_info {
5152
uint8_t cid;
5253
};
5354

54-
#define REGISTERED_STATUS_LED DK_LED3
5555

5656
static bool link_subscribe_for_rsrp;
5757

@@ -167,8 +167,9 @@ static void link_registered_work(struct k_work *unused)
167167

168168
ARG_UNUSED(unused);
169169

170+
#if defined(CONFIG_DK_LIBRARY)
170171
dk_set_led_on(REGISTERED_STATUS_LED);
171-
172+
#endif
172173
memset(pdn_act_status_arr, 0,
173174
PDN_CONTEXTS_MAX * sizeof(struct pdn_activation_status_info));
174175

@@ -367,7 +368,9 @@ void link_ind_handler(const struct lte_lc_evt *const evt)
367368
evt->nw_reg_status == LTE_LC_NW_REG_REGISTERED_ROAMING) {
368369
k_work_submit_to_queue(&mosh_common_work_q, &registered_work);
369370
} else {
371+
#if defined(CONFIG_DK_LIBRARY)
370372
dk_set_led_off(REGISTERED_STATUS_LED);
373+
#endif
371374
}
372375
break;
373376
case LTE_LC_EVT_CELL_UPDATE:

samples/nrf9160/modem_shell/src/location/location_shell.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
#include <net/nrf_cloud_rest.h>
1616
#endif
1717
#include <modem/location.h>
18+
#include <dk_buttons_and_leds.h>
19+
1820

1921
#include "mosh_print.h"
2022
#include "location_cmd_utils.h"
2123

24+
#include "mosh_defines.h"
2225

2326
enum location_shell_command {
2427
LOCATION_CMD_NONE = 0,
@@ -38,6 +41,11 @@ struct gnss_location_work_data {
3841
};
3942
static struct gnss_location_work_data gnss_location_work_data;
4043

44+
45+
#if defined(CONFIG_DK_LIBRARY)
46+
static struct k_work_delayable location_evt_led_work;
47+
#endif
48+
4149
/******************************************************************************/
4250
static const char location_usage_str[] =
4351
"Usage: location <subcommand> [options]\n"
@@ -214,6 +222,13 @@ static void location_to_cloud_worker(struct k_work *work_item)
214222
}
215223
}
216224

225+
#if defined(CONFIG_DK_LIBRARY)
226+
static void location_evt_led_worker(struct k_work *work_item)
227+
{
228+
dk_set_led_off(LOCATION_STATUS_LED);
229+
}
230+
#endif
231+
217232
/******************************************************************************/
218233

219234
void location_ctrl_event_handler(const struct location_event_data *event_data)
@@ -252,6 +267,12 @@ void location_ctrl_event_handler(const struct location_event_data *event_data)
252267
gnss_location_work_data.format = gnss_location_to_cloud_format;
253268
k_work_submit_to_queue(&mosh_common_work_q, &gnss_location_work_data.work);
254269
}
270+
271+
#if defined(CONFIG_DK_LIBRARY)
272+
dk_set_led_on(LOCATION_STATUS_LED);
273+
k_work_reschedule_for_queue(&mosh_common_work_q, &location_evt_led_work,
274+
K_SECONDS(5));
275+
#endif
255276
break;
256277

257278
case LOCATION_EVT_TIMEOUT:
@@ -292,6 +313,10 @@ void location_ctrl_init(void)
292313
{
293314
int ret;
294315

316+
#if defined(CONFIG_DK_LIBRARY)
317+
k_work_init_delayable(&location_evt_led_work, location_evt_led_worker);
318+
#endif
319+
295320
ret = location_init(location_ctrl_event_handler);
296321
if (ret) {
297322
mosh_error("Initializing the Location library failed, err: %d\n", ret);
@@ -493,6 +518,8 @@ int location_shell(const struct shell *shell, size_t argc, char **argv)
493518
/* Handle location subcommands */
494519
switch (command) {
495520
case LOCATION_CMD_CANCEL:
521+
gnss_location_to_cloud = false;
522+
k_work_cancel(&gnss_location_work_data.work);
496523
ret = location_request_cancel();
497524
if (ret) {
498525
mosh_error("Canceling location request failed, err: %d", ret);

samples/nrf9160/modem_shell/src/main.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ static void mosh_print_version_info(void)
182182
#endif
183183
}
184184

185+
#if defined(CONFIG_DK_LIBRARY)
185186
static void button_handler(uint32_t button_states, uint32_t has_changed)
186187
{
187188
if (has_changed & button_states & DK_BTN1_MSK) {
@@ -203,6 +204,7 @@ static void button_handler(uint32_t button_states, uint32_t has_changed)
203204
uart_toggle_power_state();
204205
}
205206
}
207+
#endif
206208

207209
void main(void)
208210
{
@@ -292,11 +294,16 @@ void main(void)
292294
}
293295
#endif
294296

297+
#if defined(CONFIG_DK_LIBRARY)
295298
err = dk_buttons_init(button_handler);
296299
if (err) {
297300
printk("Failed to initialize DK buttons library, error: %d\n", err);
298301
}
299-
302+
err = dk_leds_init();
303+
if (err) {
304+
printk("Cannot initialize LEDs (err: %d)\n", err);
305+
}
306+
#endif
300307
/* Application started successfully, mark image as OK to prevent
301308
* revert at next reboot.
302309
*/
@@ -305,11 +312,6 @@ void main(void)
305312
#endif
306313
k_poll_signal_init(&mosh_signal);
307314

308-
err = dk_leds_init();
309-
if (err) {
310-
printk("Cannot initialize LEDs (err: %d)\n", err);
311-
}
312-
313315
#if defined(CONFIG_SHELL_BACKEND_SERIAL)
314316
/* Resize terminal width and height of the shell to have proper command editing. */
315317
shell_execute_cmd(mosh_shell, "resize");

samples/nrf9160/modem_shell/src/mosh_defines.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ enum mosh_signals {
2121
MOSH_SIGNAL_KILL,
2222
};
2323

24+
#define LOCATION_STATUS_LED DK_LED1
25+
#define REGISTERED_STATUS_LED DK_LED3
26+
2427
#endif /* MOSH_DEFINES_H */

0 commit comments

Comments
 (0)