Cleans up logging
This commit is contained in:
parent
2aa0ffc27b
commit
30162f4628
5 changed files with 63 additions and 42 deletions
|
|
@ -9,10 +9,17 @@
|
|||
// Deep sleep.
|
||||
#define PRST_DEEP_SLEEP_IN_SECONDS 2
|
||||
|
||||
// Analog to digital converter (ADC).
|
||||
// Prints out ADC debug info, such as the values read for battery and soil moisture.
|
||||
#define PRST_ADC_DEBUG 1
|
||||
|
||||
// BLE.
|
||||
#define PRST_BLE_ADV_NAME "prst"
|
||||
// Prints out BLE debug info, such as the final encoded advertisement packet.
|
||||
#define PRST_BLE_DEBUG 0
|
||||
|
||||
// PWM.
|
||||
#define PRST_PWM_PIN NRF_GPIO_PIN_MAP(0, 29)
|
||||
#define PRST_PWM_PIN NRF_GPIO_PIN_MAP(0, 5)
|
||||
#define PRST_FAST_DISCH_PIN NRF_GPIO_PIN_MAP(1, 10)
|
||||
|
||||
#endif // _PRST_CONFIG_H_
|
||||
|
|
@ -2835,7 +2835,7 @@
|
|||
// <e> NRFX_PWM_CONFIG_LOG_ENABLED - Enables logging in the module.
|
||||
//==========================================================
|
||||
#ifndef NRFX_PWM_CONFIG_LOG_ENABLED
|
||||
#define NRFX_PWM_CONFIG_LOG_ENABLED 1
|
||||
#define NRFX_PWM_CONFIG_LOG_ENABLED 0
|
||||
#endif
|
||||
// <o> NRFX_PWM_CONFIG_LOG_LEVEL - Default Severity level
|
||||
|
||||
|
|
@ -3308,7 +3308,7 @@
|
|||
// <e> NRFX_RTC_CONFIG_LOG_ENABLED - Enables logging in the module.
|
||||
//==========================================================
|
||||
#ifndef NRFX_RTC_CONFIG_LOG_ENABLED
|
||||
#define NRFX_RTC_CONFIG_LOG_ENABLED 1
|
||||
#define NRFX_RTC_CONFIG_LOG_ENABLED 0
|
||||
#endif
|
||||
// <o> NRFX_RTC_CONFIG_LOG_LEVEL - Default Severity level
|
||||
|
||||
|
|
@ -4340,7 +4340,7 @@
|
|||
// <e> NRFX_TWI_CONFIG_LOG_ENABLED - Enables logging in the module.
|
||||
//==========================================================
|
||||
#ifndef NRFX_TWI_CONFIG_LOG_ENABLED
|
||||
#define NRFX_TWI_CONFIG_LOG_ENABLED 1
|
||||
#define NRFX_TWI_CONFIG_LOG_ENABLED 0
|
||||
#endif
|
||||
// <o> NRFX_TWI_CONFIG_LOG_LEVEL - Default Severity level
|
||||
|
||||
|
|
@ -8072,7 +8072,7 @@
|
|||
// <e> CLOCK_CONFIG_LOG_ENABLED - Enables logging in the module.
|
||||
//==========================================================
|
||||
#ifndef CLOCK_CONFIG_LOG_ENABLED
|
||||
#define CLOCK_CONFIG_LOG_ENABLED 1
|
||||
#define CLOCK_CONFIG_LOG_ENABLED 0
|
||||
#endif
|
||||
// <o> CLOCK_CONFIG_LOG_LEVEL - Default Severity level
|
||||
|
||||
|
|
@ -8480,7 +8480,7 @@
|
|||
// <e> PWM_CONFIG_LOG_ENABLED - Enables logging in the module.
|
||||
//==========================================================
|
||||
#ifndef PWM_CONFIG_LOG_ENABLED
|
||||
#define PWM_CONFIG_LOG_ENABLED 1
|
||||
#define PWM_CONFIG_LOG_ENABLED 0
|
||||
#endif
|
||||
// <o> PWM_CONFIG_LOG_LEVEL - Default Severity level
|
||||
|
||||
|
|
@ -8640,7 +8640,7 @@
|
|||
// <e> RTC_CONFIG_LOG_ENABLED - Enables logging in the module.
|
||||
//==========================================================
|
||||
#ifndef RTC_CONFIG_LOG_ENABLED
|
||||
#define RTC_CONFIG_LOG_ENABLED 1
|
||||
#define RTC_CONFIG_LOG_ENABLED 0
|
||||
#endif
|
||||
// <o> RTC_CONFIG_LOG_LEVEL - Default Severity level
|
||||
|
||||
|
|
@ -8691,7 +8691,7 @@
|
|||
// <e> SAADC_CONFIG_LOG_ENABLED - Enables logging in the module.
|
||||
//==========================================================
|
||||
#ifndef SAADC_CONFIG_LOG_ENABLED
|
||||
#define SAADC_CONFIG_LOG_ENABLED 1
|
||||
#define SAADC_CONFIG_LOG_ENABLED 0
|
||||
#endif
|
||||
// <o> SAADC_CONFIG_LOG_LEVEL - Default Severity level
|
||||
|
||||
|
|
@ -8946,7 +8946,7 @@
|
|||
// <e> TWI_CONFIG_LOG_ENABLED - Enables logging in the module.
|
||||
//==========================================================
|
||||
#ifndef TWI_CONFIG_LOG_ENABLED
|
||||
#define TWI_CONFIG_LOG_ENABLED 1
|
||||
#define TWI_CONFIG_LOG_ENABLED 0
|
||||
#endif
|
||||
// <o> TWI_CONFIG_LOG_LEVEL - Default Severity level
|
||||
|
||||
|
|
@ -10284,7 +10284,7 @@
|
|||
// <e> NRF_SDH_BLE_LOG_ENABLED - Enable logging in SoftDevice handler (BLE) module.
|
||||
//==========================================================
|
||||
#ifndef NRF_SDH_BLE_LOG_ENABLED
|
||||
#define NRF_SDH_BLE_LOG_ENABLED 1
|
||||
#define NRF_SDH_BLE_LOG_ENABLED 0
|
||||
#endif
|
||||
// <o> NRF_SDH_BLE_LOG_LEVEL - Default Severity level
|
||||
|
||||
|
|
@ -11343,7 +11343,7 @@
|
|||
// <2=> BLOCK_IF_FIFO_FULL
|
||||
|
||||
#ifndef SEGGER_RTT_CONFIG_DEFAULT_MODE
|
||||
#define SEGGER_RTT_CONFIG_DEFAULT_MODE 0
|
||||
#define SEGGER_RTT_CONFIG_DEFAULT_MODE 2
|
||||
#endif
|
||||
|
||||
// </h>
|
||||
|
|
|
|||
|
|
@ -62,10 +62,14 @@ static void rtc_callback() {
|
|||
NRF_LOG_FLUSH();
|
||||
nrf_gpio_pin_set(PRST_LED_PIN);
|
||||
prst_shtc3_read_t temp_humi = prst_shtc3_read();
|
||||
nrf_gpio_pin_set(PRST_FAST_DISCH_PIN);
|
||||
prst_pwm_init();
|
||||
prst_pwm_start();
|
||||
prst_adc_batt_read_t batt_read = prst_adc_batt_read();
|
||||
int16_t soil_read = prst_adc_soil_read();
|
||||
prst_pwm_stop();
|
||||
nrf_gpio_pin_clear(PRST_FAST_DISCH_PIN);
|
||||
NRF_LOG_INFO("Read soil: %d", soil_read);
|
||||
prst_ble_update_adv_data(batt_read.millivolts, temp_humi.temp_millicelcius, temp_humi.humidity, 0);
|
||||
NRF_LOG_FLUSH();
|
||||
prst_adv_start();
|
||||
|
|
@ -84,6 +88,7 @@ static void rtc_callback() {
|
|||
|
||||
int main(void) {
|
||||
log_init();
|
||||
nrf_gpio_cfg_output(PRST_FAST_DISCH_PIN);
|
||||
leds_init();
|
||||
power_management_init();
|
||||
prst_ble_init();
|
||||
|
|
|
|||
|
|
@ -15,13 +15,19 @@
|
|||
#define PRST_ADC_BATT_INPUT NRF_SAADC_INPUT_VDD
|
||||
#define PRST_ADC_BATT_CHANNEL 0
|
||||
|
||||
// #define PRST_ADC_SOIL_INPUT NRF_SAADC_INPUT_AIN1
|
||||
// #define PRST_ADC_SOIL_CHANNEL 1
|
||||
#define PRST_ADC_SOIL_INPUT NRF_SAADC_INPUT_AIN1
|
||||
#define PRST_ADC_SOIL_CHANNEL 1
|
||||
|
||||
static nrf_saadc_value_t sample_adc_channel(uint8_t channel) {
|
||||
nrf_saadc_value_t result;
|
||||
// *WARNING* this function is blocking, which is ot ideal but okay, but it
|
||||
// *does not work* when oversampling is set! I had to manually disable
|
||||
// SAADC_CONFIG_OVERSAMPLE in sdk_config.h.
|
||||
APP_ERROR_CHECK(nrf_drv_saadc_sample_convert(channel, &result));
|
||||
return result;
|
||||
}
|
||||
|
||||
// Unused, since we'll call the SAADC synchronously for now.
|
||||
// void saadc_callback(nrfx_saadc_evt_t const* p_event) {
|
||||
// NRF_LOG_INFO("CB!", p_event->type)
|
||||
// }
|
||||
void saadc_callback(nrf_drv_saadc_evt_t const* p_event) {
|
||||
if (p_event->type == NRF_DRV_SAADC_EVT_DONE) {
|
||||
ret_code_t err_code;
|
||||
|
|
@ -31,10 +37,10 @@ void saadc_callback(nrf_drv_saadc_evt_t const* p_event) {
|
|||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
int i;
|
||||
NRF_LOG_INFO("ADC event!");
|
||||
NRF_LOG_INFO("[adc] ADC event!");
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
NRF_LOG_INFO("%d", p_event->data.done.p_buffer[i]);
|
||||
NRF_LOG_INFO("[adc] %d", p_event->data.done.p_buffer[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -48,32 +54,31 @@ void prst_adc_init() {
|
|||
APP_ERROR_CHECK(
|
||||
nrf_drv_saadc_channel_init(PRST_ADC_BATT_CHANNEL, &batt_channel_config));
|
||||
|
||||
// nrf_saadc_channel_config_t soil_channel_config =
|
||||
// NRFX_SAADC_DEFAULT_CHANNEL_CONFIG_SE(PRST_ADC_SOIL_INPUT);
|
||||
// soil_channel_config.reference = NRF_SAADC_REFERENCE_VDD4;
|
||||
nrf_saadc_channel_config_t soil_channel_config =
|
||||
NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(PRST_ADC_SOIL_INPUT);
|
||||
soil_channel_config.reference = NRF_SAADC_REFERENCE_VDD4;
|
||||
|
||||
// APP_ERROR_CHECK(
|
||||
// nrf_drv_saadc_channel_init(PRST_ADC_SOIL_CHANNEL,
|
||||
// &soil_channel_config));
|
||||
APP_ERROR_CHECK(
|
||||
nrf_drv_saadc_channel_init(PRST_ADC_SOIL_CHANNEL, &soil_channel_config));
|
||||
}
|
||||
|
||||
prst_adc_batt_read_t prst_adc_batt_read() {
|
||||
nrf_saadc_value_t result;
|
||||
// *WARNING* this function is blocking, which is ot ideal but okay, but it
|
||||
// *does not work* when oversampling is set! I had to manually disable
|
||||
// SAADC_CONFIG_OVERSAMPLE in sdk_config.h.
|
||||
APP_ERROR_CHECK(nrf_drv_saadc_sample_convert(PRST_ADC_BATT_CHANNEL, &result));
|
||||
NRF_LOG_INFO("Read batt: here %d", result);
|
||||
nrf_saadc_value_t result = sample_adc_channel(PRST_ADC_BATT_CHANNEL);
|
||||
prst_adc_batt_read_t ret;
|
||||
ret.raw = (uint16_t) result;
|
||||
ret.raw = (uint16_t)result;
|
||||
ret.voltage = (3.6 * result) / (1 << PRST_ADC_RESOLUTION);
|
||||
ret.millivolts = ret.voltage * 1000;
|
||||
#if PRST_ADC_DEBUG
|
||||
NRF_LOG_INFO("[adc] Read battery voltage: %d (raw); %d mV; ", ret.raw, ret.millivolts,
|
||||
ret.voltage);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
int16_t prst_adc_soil_read() {
|
||||
nrf_saadc_value_t result = 0;
|
||||
// APP_ERROR_CHECK(nrf_drv_saadc_sample_convert(PRST_ADC_SOIL_CHANNEL,
|
||||
// &result));
|
||||
nrf_saadc_value_t result = sample_adc_channel(PRST_ADC_SOIL_CHANNEL);
|
||||
#if PRST_ADC_DEBUG
|
||||
NRF_LOG_INFO("[adc] Read soil moisture: %d", result);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
|
@ -117,29 +117,33 @@ void prst_ble_update_adv_data(uint16_t batt_millivolts,
|
|||
service_data[6] = soil_moisture >> 8;
|
||||
service_data[7] = soil_moisture & 0xff;
|
||||
|
||||
NRF_LOG_INFO("LETS SEE");
|
||||
|
||||
// Encodes adv_data_ into .gap_adv_data_.
|
||||
uint32_t err_code = ble_advdata_encode(
|
||||
&adv_data_, gap_adv_data_.adv_data.p_data, &gap_adv_data_.adv_data.len);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
// NRF_LOG_INFO("Encoded BLE adv packket:");
|
||||
// for (int i = 0; i < sizeof(encoded_adv_data_); i++) {
|
||||
// NRF_LOG_INFO("0x%x ", encoded_adv_data_[i]);
|
||||
// }
|
||||
#if PRST_BLE_DEBUG
|
||||
NRF_LOG_INFO("[ble] Encoded BLE adv packket:");
|
||||
for (int i = 0; i < sizeof(encoded_adv_data_); i++) {
|
||||
NRF_LOG_INFO("[ble] 0x%x ", encoded_adv_data_[i]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void prst_adv_start() {
|
||||
ret_code_t err_code;
|
||||
err_code = sd_ble_gap_adv_start(adv_handle_, PRST_CONN_CFG_TAG);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
NRF_LOG_INFO("Advertising started.\n");
|
||||
#if PRST_BLE_DEBUG
|
||||
NRF_LOG_INFO("[ble] Advertising started.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
void prst_adv_stop() {
|
||||
ret_code_t err_code;
|
||||
err_code = sd_ble_gap_adv_stop(adv_handle_);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
NRF_LOG_INFO("Advertising stopped.\n");
|
||||
#if PRST_BLE_DEBUG
|
||||
NRF_LOG_INFO("[ble] Advertising stopped.\n");
|
||||
#endif
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue