Skip to content

Commit

Permalink
add some power meter param setting of smart plug to Kconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjianqiang committed Mar 16, 2018
1 parent 33a1e3f commit 83152d3
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
Expand Up @@ -45,7 +45,7 @@ typedef struct {
pcnt_unit_t current_pcnt_unit; /**< pulse count unit of current pin */
uint32_t current_ref_param; /**< reference value to calculate actual current value */
uint8_t sel_io_num; /**< gpio number of mode select pin */
uint8_t sel_level; /**< the gpio level you wang to set to mode select pin */
uint8_t sel_level; /**< the gpio level you want to set to mode select pin */
pm_mode_t pm_mode; /**< mode of power meter refer to struct pm_mode_t */
} pm_config_t;

Expand Down
Expand Up @@ -46,17 +46,31 @@ menu "IoT Example - smart_device"
depends on SMART_PLUG_POWER_METER_ENABLE
config SMART_PLUG_PM_CF_IO
depends on SMART_PLUG_POWER_METER_ENABLE
int "Power meter GPIO number for CF pin"
int "GPIO number for power meter CF pin"
default 25
help
To set the GPIO number for CF pin of power meter.
config SMART_PLUG_PM_CF_PCNT_UNIT_NUM
depends on SMART_PLUG_POWER_METER_ENABLE
int "PCNT uint number for CF pin"
range 0 7
default 0
help
To set PCNT uint number for CF pin of power meter.
config SMART_PLUG_PM_CFI_IO
depends on SMART_PLUG_POWER_METER_ENABLE
int "Power meter GPIO number for CFI pin"
int "GPIO number for power meter CFI pin"
default 26
help
To set the GPIO number for CF pin of power meter.
This pin defines the output on CF pin is current or voltage.
To set the GPIO number for CFI pin of power meter.
This pin defines the output on CFI pin is current or voltage.
config SMART_PLUG_PM_CFI_PCNT_UNIT_NUM
depends on SMART_PLUG_POWER_METER_ENABLE
int "PCNT uint number for CFI pin"
range 0 7
default 1
help
To set PCNT uint number for CFI pin of power meter.
config SMART_PLUG_PM_POWER_COEF
depends on SMART_PLUG_POWER_METER_ENABLE
int "Power-frequency coefficient for power meter"
Expand All @@ -77,7 +91,20 @@ menu "IoT Example - smart_device"
default 102961
help
Voltage-frequency coefficient for voltage value read from power meter.
Voltage = frequency * coefficient
Voltage = frequency * coefficient
config SMART_PLUG_PM_MODE_SEL_PIN
depends on SMART_PLUG_POWER_METER_ENABLE
int "GPIO number for power meter mode select pin"
default 17
help
To set the GPIO number for select pin of power meter.
config SMART_PLUG_PM_MODE_SEL_PIN_LEVEL
depends on SMART_PLUG_POWER_METER_ENABLE
int "Power meter mode select pin level"
range 0 1
default 0
help
To set the select pin level of power meter.
endmenu

menu "Main button"
Expand Down
Expand Up @@ -30,12 +30,18 @@
#if CONFIG_SMART_PLUG_DEVICE
#define PLUG_NAME_SPACE CONFIG_SMART_PLUG_NAME_SPACE
#define PLUG_PARAM_KEY CONFIG_SMART_PLUG_PARAM_KEY

#define PLUG_POWER_METER_ENABLE CONFIG_SMART_PLUG_POWER_METER_ENABLE
#define PM_CF_IO_NUM CONFIG_SMART_PLUG_PM_CF_IO
#define PM_CF_PCNT_UNIT_NUM CONFIG_SMART_PLUG_PM_CF_PCNT_UNIT_NUM
#define PM_CFI_IO_NUM CONFIG_SMART_PLUG_PM_CFI_IO
#define PM_CFI_PCNT_UNIT_NUM CONFIG_SMART_PLUG_PM_CFI_PCNT_UNIT_NUM
#define PM_POWER_PARAM CONFIG_SMART_PLUG_PM_POWER_COEF
#define PM_CURRENT_PARAM CONFIG_SMART_PLUG_PM_CURRENT_COEF
#define PM_VOLTAGE_PARAM CONFIG_SMART_PLUG_PM_VOLTAGE_COEF
#define PM_MODE_SEL_PIN CONFIG_SMART_PLUG_PM_MODE_SEL_PIN
#define PM_MODE_SEL_PIN_LEVEL CONFIG_SMART_PLUG_PM_MODE_SEL_PIN_LEVEL

#define BUTTON_IO_NUM_MAIN CONFIG_SMART_PLUG_MAIN_BUTTON_IO
#define BUTTON_ACTIVE_LEVEL CONFIG_SMART_PLUG_MAIN_BUTTON_ACT_LEVEL
#define NET_LED_NUM CONFIG_SMART_PLUG_NET_STATUS_LED_IO
Expand Down Expand Up @@ -88,12 +94,18 @@
#else
#define PLUG_NAME_SPACE "socket"
#define PLUG_PARAM_KEY "socket_param"

#define PLUG_POWER_METER_ENABLE (1)
#define PM_CF_IO_NUM (25)
#define PM_CF_PCNT_UNIT_NUM (0)
#define PM_CFI_IO_NUM (26)
#define PM_CFI_PCNT_UNIT_NUM (1)
#define PM_POWER_PARAM (1293699)
#define PM_CURRENT_PARAM (13670)
#define PM_VOLTAGE_PARAM (102961)
#define PM_MODE_SEL_PIN (17)
#define PM_MODE_SEL_PIN_LEVEL (0)

#define BUTTON_IO_NUM_MAIN (4)
#define BUTTON_ACTIVE_LEVEL (0)
#define NET_LED_NUM GPIO_NUM_19
Expand Down
Expand Up @@ -263,17 +263,17 @@ plug_handle_t plug_init(SemaphoreHandle_t xSemWriteInfo)
/* create a power meter object */
pm_config_t pm_conf = {
.power_io_num = PM_CF_IO_NUM,
.power_pcnt_unit = PCNT_UNIT_0,
.power_pcnt_unit = PM_CF_PCNT_UNIT_NUM,
.power_ref_param = PM_POWER_PARAM,
.voltage_io_num = PM_CFI_IO_NUM,
.voltage_pcnt_unit = PCNT_UNIT_1,
.voltage_pcnt_unit = PM_CFI_PCNT_UNIT_NUM,
.voltage_ref_param = PM_VOLTAGE_PARAM,
.current_io_num = PM_CFI_IO_NUM,
.current_pcnt_unit = PCNT_UNIT_1,
.current_pcnt_unit = PM_CFI_PCNT_UNIT_NUM,
.current_ref_param = PM_CURRENT_PARAM,
.sel_io_num = 17,
.sel_level = 0,
.pm_mode = PM_SINGLE_VOLTAGE
.sel_io_num = PM_MODE_SEL_PIN,
.sel_level = PM_MODE_SEL_PIN_LEVEL,
.pm_mode = PM_SINGLE_VOLTAGE
};
plug_dev->pm_handle = iot_powermeter_create(pm_conf);
xTaskCreate(powermeter_task, "powermeter_task", 2048, plug_dev, 5, NULL);
Expand Down

0 comments on commit 83152d3

Please sign in to comment.