#
# Copyright (c) 2018 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

menu "Asset tracker"

rsource "src/ui/Kconfig"

config APPLICATION_WORKQUEUE_STACK_SIZE
	int "Application workqueue stack size"
	default 4096

config APPLICATION_WORKQUEUE_PRIORITY
	int "Application workqueue priority"
	default SYSTEM_WORKQUEUE_PRIORITY

menu "GPS"

choice
	prompt "GPS device"
	default GPS_USE_SIM
	help
	  Select from which device GPS data will be fetched.

config GPS_USE_SIM
	bool "Use GPS simulator"
	select GPS_SIM
	select GPS_SIM_TRIGGER
	help
	  Use simulated GPS data.

config GPS_USE_EXTERNAL
	bool "User provided GPS device"
	help
	  Provide a GPS device that location data will be fetched from and
	  sent to nRF Cloud

endchoice

config GPS_DEV_NAME
	string "GPS device name"
	default GPS_SIM_DEV_NAME if GPS_USE_SIM
	help
	  GPS device from which location data will be fetched and sent
	  to nRF Cloud.

config GPS_CONTROL_ON_LONG_PRESS
	bool "Control the GPS state with button"
	default y
	help
	  Control the GPS operation with long-press on the button.
	  Press for 5 seconds to enable, or 5 seconds to disable.

config GPS_CONTROL_PSM_ENABLE_ON_START
	bool "Enable PSM when starting GPS"
	help
	  The nRF9160 modem needs to be set in PSM mode for the GPS to start
	  searching for satellites. Enabling this option will do so
	  automatically, otherwise the application must handle it.

config GPS_CONTROL_PSM_DISABLE_ON_STOP
	bool "Disable PSM when stopping GPS"
	help
	  Selecting this option will disable PSM when the GPS is stopped.
	  During a PSM interval, the device is not reachable from the outside
	  until the interval times out, or the device itself attempts to
	  send data on the link.

config GPS_CONTROL_FIRST_FIX_CHECK_DELAY
	int "Time from Cloud conenction until first fix check"
	default 30
	help
	  The amount of time that should pass between successfully establishing
	  connection to cloud until first attempt to get position fix.
	  Attempting to get a fix means entering PSM mode, in which the device
	  is not reachable for the duration of the interval, or until the
	  device itself sends data and then for the duration for the set
	  active time thereafter.

config GPS_CONTROL_FIX_CHECK_INTERVAL
	int "Interval in seconds to between check for position fix"
	default 120
	help
	  The fix check interval gives the interval for how long it will go
	  between each retry to achieve position fix. The actual fix time will
	  vary with factors such as satellite coverage, surrounding buildings
	  and landscape, PSM interval and activity time requested and granted
	  by the network.

config GPS_CONTROL_FIX_CHECK_OVERDUE
	int "Longest allowed time in seconds between checks for position fix"
	default 900
	help
	  The fix check interval gives the interval for how long it will go
	  between each retry to achieve position fix, when GPS_START_ON_MOTION
	  enabled, even if no motion is detected.

config GPS_CONTROL_FIX_TRY_TIME
	int "Time in seconds to try to get fix"
	default 180
	help
	  Amount of time the device will attempt to get position fix. Note that
	  if the interval is interrupted by the device sending data, the timer
	  is not reset, and the actual try time will be shortened due to
	  the device not being in PSM mode all the time. If fix is not acquired
	  before it times out, the device will try to get fix again in
	  GPS_CONTROL_FIX_CHECK_INTERVAL seconds. If GPS_CONTROL_FIX_COUNT is reached
	  before the full GPS_CONTROL_FIX_TRY_TIME has passed, the GPS will be stopped.

config GPS_CONTROL_FIX_COUNT
	int "Number of position fix before stopping GPS"
	default 3
	help
	  The number of fixes to get before stopping the GPS, within the time
	  set in GPS_CONTROL_FIX_CHECK_INTERVAL.

config GPS_CONTROL_MAX_FAILED_FIX_ATTEMPTS
	int "Number of failed fix attempts before stopping GPS"
	default 3
	help
	  Number of retries to get fix before shutting down the GPS until user
	  input tells it to start retrying.

config GPS_START_ON_MOTION
	bool "Motion triggered GPS update"
	default n
	help
	  When accelerometer detects movement, and GPS is enabled, update GPS
	  position, but if no movement, wait a longer delay between updates
	  to conserve power.

endmenu # GPS

menu "Device and modem"

config POWER_OPTIMIZATION_ENABLE
	bool "Enable power optimization"
	default y
	select LTE_EDRX_REQ

if MODEM_INFO

config HOLD_TIME_RSRP
	int "Minimum time [s] between RSRP subscription messages"
	default 60
	help
	  The minimum time in seconds where the modem
	  informer is allowed to submit RSRP data to the cloud.

endif

endmenu # Device

menuconfig MOTION
	bool "Enable motion sensing in Asset Tracker"
	default y
	help
	  Enables motion sensing in asset tracker with real
	  sensors or simulated ones.

if MOTION

choice
	prompt "Accelerometer device"
	default ACCEL_USE_SIM
	help
	  Select which device will provide accelerometer data.

config ACCEL_USE_SIM
	bool "Use simulated accelerometer data"
	select SENSOR
	select SENSOR_SIM
	select SENSOR_SIM_TRIGGER
	help
	  Use sensor simulator to generate accelerometer data for
	  flip detection data sent to nRF Cloud.

config ACCEL_USE_EXTERNAL
	bool "User provided accelerometer device"
	help
	  The user will provide an accelerometer device that will
	  be used for flip detection.

endchoice

if ACCEL_USE_SIM
config ACCEL_DEV_NAME
	string
	default SENSOR_SIM_DEV_NAME

config ACCEL_TRIGGER
	bool
	default SENSOR_SIM_TRIGGER

config FLIP_INPUT
	int "Button or switch number to simulate flip"
	range 1 4 if BOARD_NRF9160DK_NRF9160NS
	range 1 1 if BOARD_THINGY91_NRF9160NS
	default 3 if BOARD_NRF9160DK_NRF9160NS
	default 1 if BOARD_THINGY91_NRF9160NS
	help
	  Button or switch number to use for simulating
	  a board flip event.
	  1 - Button 1
	  2 - Button 2
	  3 - Switch 1
	  4 - Switch 2
endif

if ACCEL_USE_EXTERNAL

config ACCEL_DEV_NAME
	string "Accelerometer device name"
	help
	  Device from which accelerometer data will be fetched and used
	  for orientation detection and sent to nRF Cloud.

endif

config ACCEL_INVERTED
	bool "Accelerometer inverted"
	default y if BOARD_THINGY91_NRF9160NS
	help
	  Enable if the accelerometer is mounted with the top side facing
	  down when the board itself is in normal position.

endif # MOTION

menu "Cloud"

config MQTT_KEEPALIVE
	int "Time after last transmission to send a ping to keep connection on"
	default 1200
	help
	  This should be set to the expected time between messages sent from
	  this device. Making it larger than the expected data period does not
	  conserve bandwidth, as the ping is only sent if nothing else
	  has been within the specified period. Shorter values can prevent hidden
	  NAT timeouts at the carrier, but also will interrupt GPS fix attempts
	  and slow down TTFF.

config CLOUD_BUTTON
	bool "Enable button sensor"
	default y

config CLOUD_BUTTON_INPUT
	int "Set button sensor button number"
	range 1 4 if BOARD_NRF9160DK_NRF9160NS
	range 1 1 if BOARD_THINGY91_NRF9160NS
	default 1

config CLOUD_CONNECT_RETRY_DELAY
	int "Cloud connection retry delay in seconds"
	default 480
	help
	  Time to wait before trying to reconnect to the cloud if the
	  previous attempt failed (in seconds).

config CLOUD_CONNECT_COUNT_MAX
	int "Maximum number of cloud connection attempts"
	default 8
	help
	  Maximum number of unsuccessful cloud connection attempts.
	  Device will wait for the value defined by CLOUD_CONNECT_RETRY_DELAY
	  between attempts.

config CLOUD_WAIT_DURATION
	int "Cloud connection acknowledge wait duration"
	default 30
	help
	  How long the device should wait for a CONNACK
	  event from the cloud when connecting.  Device will reboot
	  if an ack is not received within the duration.

config CLOUD_FOTA_APP
	bool "Enable firmware over-the-air upgrades for application"
	depends on AWS_FOTA || NRF_CLOUD_FOTA
	depends on DFU_TARGET_MCUBOOT
	default y

config CLOUD_FOTA_MODEM
	bool "Enable firmware over-the-air upgrades for modem"
	depends on AWS_FOTA || NRF_CLOUD_FOTA
	depends on DFU_TARGET_MODEM_DELTA
	default y

config CLOUD_FOTA_BOOT
	bool "Enable firmware over-the-air upgrades for bootloader"
	depends on AWS_FOTA || NRF_CLOUD_FOTA
	depends on DFU_TARGET_MCUBOOT
	depends on SECURE_BOOT
	default y

config CLOUD_CONNECT_ERR_REBOOT_S
	int "Seconds to wait before rebooting when a cloud connect error occurs"
	default 300

endmenu # Cloud

menuconfig ENVIRONMENT_SENSORS
	bool "Enable environment sensing in Asset Tracker"
	default y
	help
	  Enables environment sensing in asset tracker with real
	  sensors or simulated ones.

if ENVIRONMENT_SENSORS

config USE_BME680_BSEC
	bool "Use Bosch BME680 BSEC lib"
	default n
	help
	  Enable use of Bosch BSEC library. The library itself is not a part of
	  NCS and must be downloaded from Bosch Sensortec.

config BOSCH_BSEC_LIBRARY_PATH
	string "Path to Bosch BSEC library folder"
	default "$(ZEPHYR_BASE)/../nrf/ext/BSEC_1.4.8.0_Generic_Release"
	help
	  Path to the folder where the Bosch BSEC library is placed.

config ENVIRONMENT_DATA_SEND_INTERVAL
	int "Interval in seconds for sending environment data"
	default 30
	help
	  Interval between each sampling and sending of environment sensor data.
	  If the GPS is active, sensor data will not be sent before it is
	  stopped. The unit is seconds.

config ENVIRONMENT_DATA_BACKOFF_TIME
	int "Time to delay sending environment data if GPS active"
	default 20
	help
	  Time in seconds before retrying to send environment sensor data if
	  the GPS is active.

choice
	prompt "Temperature measurement device"
	default TEMP_USE_SIM
	help
	  Select which device will provide temperature data.

config TEMP_USE_SIM
	bool "Use simulated temperature data"
	select SENSOR
	select SENSOR_SIM
	help
	  Use sensor simulator to generate temperature data to send to
	  nRF Cloud.

config TEMP_USE_EXTERNAL
	bool "User provided temperature device"
	help
	  The user provides a temperature device that is
	  used for temperature measurement.

endchoice

if TEMP_USE_SIM
config TEMP_DEV_NAME
	string
	default SENSOR_SIM_DEV_NAME

config TEMP_TRIGGER
	bool
	default SENSOR_SIM_TRIGGER

config TEMP_SIM_BUTTON
	int "Button or switch to trigger 'data ready' event"
	range 1 4 if BOARD_NRF9160DK_NRF9160NS
	range 1 1 if BOARD_THINGY91_NRF9160NS
	default 3 if BOARD_NRF9160DK_NRF9160NS
	default 1 if BOARD_THINGY91_NRF9160NS
	help
	  Button or switch number to use for triggering
	  a 'data ready' event.
	  1 - Button 1
	  2 - Button 2
	  3 - Switch 1
	  4 - Switch 2
endif

if TEMP_USE_EXTERNAL

config TEMP_DEV_NAME
	string "Temperature device name"
	help
	  Device from which temperature data will be fetched and
	  sent to nRF Cloud.

endif

endif # ENVIRONMENT_SENSORS

menuconfig LIGHT_SENSOR
	bool "Light sensor"
	select BH1749 if BOARD_THINGY91_NRF9160NS
	default y if BOARD_THINGY91_NRF9160NS

if LIGHT_SENSOR

config LIGHT_SENSOR_DEV_NAME
	string "Light sensor device name"
	default "BH1749" if BOARD_THINGY91_NRF9160NS

config LIGHT_SENSOR_DATA_SEND_INTERVAL
	int "Interval in seconds for sending light sensor data"
	default 60
	help
	  Interval between each sampling and sending of light sensor data.
	  If the GPS is active, sensor data will not be sent before it is
	  stopped. The unit is seconds.

endif # LIGHT_SENSOR

config GPS_START_AFTER_CLOUD_EVT_READY
	bool "Automatic start of GPS on CLOUD_EVT_READY event after reset"
	default n
	help
	  Enabling this will make the GPS automatically start after a reset.
	  Useful when operating as a GPS tracker outdoors for a longer period
	  of time.

config ASSET_TRACKER_WATCHDOG_TIMEOUT_MSEC
	int "Watchdog timeout in milliseconds"
	default 60000

config USE_AT_HOST
	bool "Enable AT commands"
	default y
	select AT_HOST_LIBRARY
	help
	  Enable the AT host library so that AT commands can be sent to and
	  received from a serial terminal.

endmenu

menu "Zephyr Kernel"
source "Kconfig.zephyr"
endmenu

module = ASSET_TRACKER
module-str = Asset Tracker
source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config"
