Example #1
0
uint32_t rain_reset_configs(){
	uint32_t   err_code = NRF_SUCCESS;

	//Set service to default configurations
	err_code = ble_ambient_config_update(m_rain.m_amb, RAIN_INITIAL_CONFIG, BLE_AMBIENT_RAIN);

	if(err_code != NRF_SUCCESS){
		rain_printf("ble_ambient_config_update() for RAIN failed.\r\n");
		return err_code;
	}

	err_code = rain_configs_update();

	if(err_code != NRF_SUCCESS){
		rain_printf("rain_configs_update() failed.\r\n");
		return err_code;
	}

	//Reset sensor values
	uint8_t rain_buffer[AMB_RAIN_MAX_PACKET_VALUE];
	for(uint8_t i = 0; i < AMB_RAIN_MAX_PACKET_VALUE; i++) rain_buffer[i] = INVALID_SENSOR_VALUE;

	check_ble_service_err_code(
			ble_ambient_sensor_update(m_rain.m_amb, rain_buffer, AMB_RAIN_MAX_PACKET_VALUE, BLE_AMBIENT_RAIN));

	return NRF_SUCCESS;
}
Example #2
0
uint32_t lum_reset_configs(){
	uint32_t   err_code = NRF_SUCCESS;

	//Set service to default configurations
	err_code = ble_ambient_config_update(m_lum.m_amb, LUM_INITIAL_CONFIG, BLE_AMBIENT_LUM);

	if(err_code != NRF_SUCCESS){
		lum_printf("ble_ambient_config_update() for LUM failed.\r\n");
		return err_code;
	}

	err_code = lum_configs_update();

	if(err_code != NRF_SUCCESS){
		lum_printf("lum_configs_update() failed.\r\n");
		return err_code;
	}

	//Reset sensor values
	uint8_t lum_buffer[AMB_LUM_MAX_PACKET_VALUE];
	for(uint8_t i = 0; i < AMB_LUM_MAX_PACKET_VALUE; i++) lum_buffer[i] = INVALID_SENSOR_VALUE;

	check_ble_service_err_code(
			ble_ambient_sensor_update(m_lum.m_amb, lum_buffer, AMB_LUM_MAX_PACKET_VALUE, BLE_AMBIENT_LUM));

	return NRF_SUCCESS;
}
Example #3
0
uint32_t temp_reset_configs(){
	uint32_t   err_code = NRF_SUCCESS;

	//Set service to default configurations
	err_code = ble_ambient_config_update(m_temp.m_amb, TEMP_INITIAL_CONFIG, BLE_AMBIENT_TEMP);

	if(err_code != NRF_SUCCESS){
		temp_printf("ble_ambient_config_update() for TEMP failed.\r\n");
		return err_code;
	}

	err_code = temp_configs_update();

	if(err_code != NRF_SUCCESS){
		temp_printf("temp_configs_update() failed.\r\n");
		return err_code;
	}

	//Reset sensor values
	uint8_t temp_buffer[AMB_TEMP_MAX_PACKET_VALUE];
	for(uint8_t i = 0; i < AMB_TEMP_MAX_PACKET_VALUE; i++) temp_buffer[i] = INVALID_SENSOR_VALUE;

	check_ble_service_err_code(ble_ambient_sensor_update(m_temp.m_amb, temp_buffer, AMB_TEMP_MAX_PACKET_VALUE, BLE_AMBIENT_TEMP));

	return NRF_SUCCESS;
}
Example #4
0
/**@brief Function for handling the Write event.
 *
 * @param[in]   p_amb       Ambient Service Service structure.
 * @param[in]   p_ble_evt   Event received from the BLE stack.
 */
static void on_write(ble_ambient_t * p_amb, ble_evt_t * p_ble_evt){
#if TEMP_ENABLED || PR_ENABLED || HUM_ENABLED || LUM_ENABLED
	ble_gatts_evt_write_t * p_evt_write = &p_ble_evt->evt.gatts_evt.params.write;
#endif
	
    //***************** TEMP ***********************/
	#if TEMP_ENABLED
	//Sensor configuration written and with right size
	if((p_evt_write->handle == p_amb->temp_configuration_handles.value_handle) &&
			(p_evt_write->len == 1)) { 
				
		if (p_amb->evt_handler != NULL){
			ble_ambient_evt_t amb_evt;
			
			amb_evt.evt_type = BLE_AMBIENT_EVT_TEMP_CONFIG_CHANGED;
			amb_evt.p_ble_evt = p_ble_evt;
			
			//Save new configuration value
			ble_ambient_config_update(p_amb, p_evt_write->data[0], BLE_AMBIENT_TEMP);
			
			//Signal the app that the configuration has changed
			p_amb->evt_handler(p_amb, &amb_evt);
		}
	}
	#endif

    //***************** PR ***********************/
	#if PR_ENABLED
	//Sensor configuration written and with right size
	if((p_evt_write->handle == p_amb->pr_configuration_handles.value_handle) &&
			(p_evt_write->len == 1)) {

		if (p_amb->evt_handler != NULL){
			ble_ambient_evt_t amb_evt;

			amb_evt.evt_type = BLE_AMBIENT_EVT_PR_CONFIG_CHANGED;
			amb_evt.p_ble_evt = p_ble_evt;

			//Save new configuration value
			ble_ambient_config_update(p_amb, p_evt_write->data[0], BLE_AMBIENT_PR);

			//Signal the app that the configuration has changed
			p_amb->evt_handler(p_amb, &amb_evt);
		}
	}
	#endif

	//***************** HUM ***********************/
	#if HUM_ENABLED
	//Sensor configuration written and with right size
	if((p_evt_write->handle == p_amb->hum_configuration_handles.value_handle) &&
			(p_evt_write->len == 1)) {

		if (p_amb->evt_handler != NULL){
			ble_ambient_evt_t amb_evt;

			amb_evt.evt_type = BLE_AMBIENT_EVT_HUM_CONFIG_CHANGED;
			amb_evt.p_ble_evt = p_ble_evt;

			//Save new configuration value
			ble_ambient_config_update(p_amb, p_evt_write->data[0], BLE_AMBIENT_HUM);

			//Signal the app that the configuration has changed
			p_amb->evt_handler(p_amb, &amb_evt);
		}
	}
	#endif

	//***************** HUMSOLO ***********************/
	#if HUMSOLO_ENABLED
	//Sensor configuration written and with right size
	if((p_evt_write->handle == p_amb->humsolo_configuration_handles.value_handle) &&
			(p_evt_write->len == 1)) {

		if (p_amb->evt_handler != NULL){
			ble_ambient_evt_t amb_evt;

			amb_evt.evt_type = BLE_AMBIENT_EVT_HUMSOLO_CONFIG_CHANGED;
			amb_evt.p_ble_evt = p_ble_evt;

			//Save new configuration value
			ble_ambient_config_update(p_amb, p_evt_write->data[0], BLE_AMBIENT_HUMSOLO);

			//Signal the app that the configuration has changed
			p_amb->evt_handler(p_amb, &amb_evt);
		}
	}
	#endif
		
    //***************** LUM ***********************/
	#if LUM_ENABLED
	//Sensor configuration written and with right size
	if((p_evt_write->handle == p_amb->lum_configuration_handles.value_handle) &&
			(p_evt_write->len == 1)) {

		if (p_amb->evt_handler != NULL){
			ble_ambient_evt_t amb_evt;

			amb_evt.evt_type = BLE_AMBIENT_EVT_LUM_CONFIG_CHANGED;
			amb_evt.p_ble_evt = p_ble_evt;

			//Save new configuration value
			ble_ambient_config_update(p_amb, p_evt_write->data[0], BLE_AMBIENT_LUM);

			//Signal the app that the configuration has changed
			p_amb->evt_handler(p_amb, &amb_evt);
		}
	}
	#endif

}