add atuators control & init

This commit is contained in:
2022-08-20 14:52:02 +02:00
parent 3efa1b6665
commit 5937417568
8 changed files with 398 additions and 101 deletions
+1
View File
@@ -6,6 +6,7 @@ idf_component_register(SRCS
utils.c
wifi_conn.c
mbiface.c
actuators.c
console/console_ioimpl.c
console/console_server.c
console/register_cmds.c
+23 -7
View File
@@ -1,17 +1,33 @@
menu "IRBLASTER Configuration"
menu "Pin mapping"
config PIN_I2C_SDA0
int "I2C0 SDA"
config PIN_BUZZER
int "Buzzer pin"
default 16
config PIN_LED
int "LED pin"
default 17
config PIN_BLIND
int "Blind open pin"
default 18
config PIN_I2C_SCL0
int "I2C0 SCL"
config PIN_PWM
int "Motor PWM pin"
default 19
config PIN_IRLED
int "IR LED"
default 17
config PIN_DIR
int "Motor direction pin"
default 20
config PIN_1WIRE_1
int "1Wire 1 (indoor)"
default 21
config PIN_1WIRE_2
int "1Wire 2 (outdoor)"
default 22
endmenu
menu "Console"
+132
View File
@@ -0,0 +1,132 @@
//
// Created by MightyPork on 2022/08/20.
//
#include <driver/ledc.h>
#include "actuators.h"
#include "settings.h"
struct actuators_status g_Act = {
.blind = false,
.dir = MOTOR_DIR_IN,
.power = 0,
};
static void buzzer_init() {
ledc_timer_config_t ledc_timer = {
.duty_resolution = LEDC_TIMER_8_BIT, // resolution of PWM duty
.freq_hz = 4400, // frequency of PWM signal
.speed_mode = LEDC_HIGH_SPEED_MODE, // timer mode
.timer_num = LEDC_TIMER_0, // timer index
.clk_cfg = LEDC_AUTO_CLK, // Auto select the source clock
};
// Set configuration of timer0 for high speed channels
ledc_timer_config(&ledc_timer);
ledc_channel_config_t chan = {
.channel = LEDC_CHANNEL_0,
.duty = 127,
.gpio_num = CONFIG_PIN_BUZZER,
.speed_mode = LEDC_HIGH_SPEED_MODE,
.hpoint = 0,
.timer_sel = LEDC_TIMER_0
};
ledc_channel_config(&chan);
}
void act_buzzer_set(bool on) {
g_Act.buzzer = on;
if (on) {
ledc_set_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, 127);
ledc_update_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0);
} else {
ledc_stop(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_0, 0);
}
}
static void motor_init() {
ledc_timer_config_t ledc_timer = {
.duty_resolution = LEDC_TIMER_10_BIT, // resolution of PWM duty
.freq_hz = 1000, // frequency of PWM signal
.speed_mode = LEDC_HIGH_SPEED_MODE, // timer mode
.timer_num = LEDC_TIMER_1, // timer index
.clk_cfg = LEDC_AUTO_CLK, // Auto select the source clock
};
// Set configuration of timer1 for high speed channels
ledc_timer_config(&ledc_timer);
// PWM output
ledc_channel_config_t chan = {
.channel = LEDC_CHANNEL_1,
.duty = 512,
.gpio_num = CONFIG_PIN_PWM,
.speed_mode = LEDC_HIGH_SPEED_MODE,
.hpoint = 0,
.timer_sel = LEDC_TIMER_0,
.flags.output_invert = true,
};
ledc_channel_config(&chan);
// Direction output
gpio_config_t ioconf = {
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = 1 << CONFIG_PIN_DIR,
};
gpio_config(&ioconf);
}
void act_motor_power_set(uint16_t perc) {
if (perc > 0) {
if (perc < g_Settings.min_power) {
perc = g_Settings.min_power;
}
g_Act.power = perc;
uint16_t duty = (uint16_t) (10.23f * (float)perc);
if (duty > 1023) {
duty = 1023;
}
ledc_set_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_1, duty);
ledc_update_duty(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_1);
} else {
ledc_stop(LEDC_HIGH_SPEED_MODE, LEDC_CHANNEL_1, 0);
}
}
void act_motor_direction_set(enum motor_direction dir) {
g_Act.dir = dir;
gpio_set_level(CONFIG_PIN_DIR, (int) dir); // TODO verify polarity
}
static void blind_init() {
// Blind output
gpio_config_t ioconf = {
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = 1 << CONFIG_PIN_BLIND,
};
gpio_config(&ioconf);
}
void act_blind_set(bool open) {
g_Act.blind = open;
gpio_set_level(CONFIG_PIN_BLIND, (int) open); // TODO verify polarity
}
static void led_init() {
gpio_config_t ioconf = {
.mode = GPIO_MODE_OUTPUT,
.pin_bit_mask = 1 << CONFIG_PIN_LED,
};
gpio_config(&ioconf);
}
void act_led_set(bool on) {
g_Act.led = on;
gpio_set_level(CONFIG_PIN_LED, (int) on); // TODO verify polarity
}
void act_init() {
buzzer_init();
motor_init();
blind_init();
led_init();
}
+30
View File
@@ -0,0 +1,30 @@
//
// Created by MightyPork on 2022/08/20.
//
#ifndef FANCTL_ACTUATORS_H
#define FANCTL_ACTUATORS_H
enum motor_direction {
MOTOR_DIR_IN = 0,
MOTOR_DIR_OUT = 1
};
struct actuators_status {
enum motor_direction dir;
bool blind;
bool led;
bool buzzer;
uint16_t power;
};
extern struct actuators_status g_Act;
void act_init();
void act_buzzer_set(bool on);
void act_motor_power_set(uint16_t perc);
void act_motor_direction_set(enum motor_direction dir);
void act_blind_set(bool open);
void act_led_set(bool on);
#endif //FANCTL_ACTUATORS_H
+2
View File
@@ -20,6 +20,7 @@
#include "console/register_cmds.h"
#include "irblast.h"
#include "mbiface.h"
#include "actuators.h"
static const char *TAG = "main";
@@ -56,6 +57,7 @@ void app_main(void) {
console_setup_uart_stdio();
ESP_ERROR_CHECK(console_start_stdio(NULL, NULL));
act_init();
mbiface_setup();
telnetsrv_start(CONSOLE_TELNET_PORT);
+9 -1
View File
@@ -38,7 +38,15 @@ extern nvs_handle g_nvs_storage;
X(uint32_t , static_ip_mask , , 0x00ffffff , true , u32 , &) /* 255.255.255.0 */ \
X(uint32_t , static_ip_gw , , 0x0100a8c0 , true , u32 , &) /* 192.168.0.1 */ \
X(uint32_t , ap_ip , , 0x0100a8c0 , true , u32 , &) /* 192.168.0.1 */ \
X(uint32_t , static_dns , , 0x08080808 , true , u32 , &) /* 8.8.8.8 */
X(uint32_t , static_dns , , 0x08080808 , true , u32 , &) /* 8.8.8.8 */ \
X(uint16_t , recup_mode , , 0 , true , u16 , &) /* recuperator control mode - 0=time, 1=min time+temp equilibrium */ \
X(uint16_t , recup_time , , 60 , true , u16 , &) /* seconds */ \
X(uint16_t , start_stop_time, , 3 , true , u16 , &) /* cas rozjezdu nebo zastaveni motoru (s) */ \
X(uint16_t , blind_time , , 30 , true , u16 , &) /* cas otevreni nebo zavreni rolety (s) */ \
X(uint16_t , initial_mode , , 0 , true , u16 , &) /* rezim po zapnuti napajeni */ \
X(uint16_t , initial_power , , 100 , true , u16 , &) /* vychozi vykon */ \
X(uint16_t , min_power , , 1 , true , u16 , &) /* min power % */ \
X(bool , summer_mode , , 0 , true , bool , &) /* rezim po zapnuti napajeni */
enum settings_key_enum {
#undef X