#include "control.h"

ctrl_struct Control; //FLASH    (rx)

void control_init(void)
{
	Control.dev_type		= DEV_TYPE;
	Control.ble_mode_set 	= ble_raw;
	Control.ble_mode_now 	= ble_off;
	Control.serial_number 	= BASE_SERIAL_NUM;
	Control.password 		= BASE_PASSWORD;
	Control.mesh_netid 		= BASE_MESH_ID;
	Control.mesh_adr 		= BASE_MESH_ADR;
	Control.master_adr 		= BASE_MASTER_ADR;
	Control.ble_ask 		= false;
}

void control_init_var(ctrl_struct * control)
{
	control->dev_type		= DEV_TYPE;
	control->ble_mode_set 	= ble_off;
	control->ble_mode_set 	= ble_off;
	control->serial_number 	= BASE_SERIAL_NUM;
	control->password 		= BASE_PASSWORD;
	control->mesh_netid 	= BASE_MESH_ID;
	control->mesh_adr 		= BASE_MESH_ADR;
	control->master_adr 	= BASE_MASTER_ADR;
	control->ble_ask 		= false;
}


void lets_sleep(void)
{
	//Выключили питание АЦП
	HAL_GPIO_WritePin(INA_PWR_GPIO_Port, INA_PWR_Pin, RESET);
	//Выключили питание потенциометра
	HAL_GPIO_WritePin(POT_PWR_GPIO_Port, POT_PWR_Pin, GPIO_PIN_RESET);
	HAL_GPIO_WritePin(BLE_PWR_GPIO_Port, BLE_PWR_Pin, SET);


//	hv_pwm(false);
//	hv_power(false);
//	hv_ll_control(z_state, z_state, z_state);
//	HAL_Delay(20);
//	relay_all_control(false, false, false);

	HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN1);
	//Сейчас второй кнопки нет!!
	//HAL_PWR_DisableWakeUpPin(PWR_WAKEUP_PIN2);//если вторая кнопка тоже подключена PC0
	__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
	HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1);
	HAL_PWR_EnterSTANDBYMode();
}
