You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

114 lines
2.6 KiB

//
// Created by MightyPork on 2018/12/08.
//
#include <esp_heap_caps.h>
#include <esp_system.h>
#include "console/cmd_common.h"
#include <console/cmddef.h>
#include "actuators.h"
#include "settings.h"
static int cmd_pwm_show(console_ctx_t *ctx, cmd_signature_t *reg)
{
EMPTY_CMD_SETUP("Show PWM config");
console_printf("freq %d Hz, duty %d/1024, thres %d mV, ADC = %d mV\n", pwm_freq, pwm_duty, pwm_thres, last_adc_mv);
return 0;
}
static int cmd_duty(console_ctx_t *ctx, cmd_signature_t *reg)
{
static struct {
struct arg_int *duty;
struct arg_end *end;
} cmd_args;
if (reg) {
cmd_args.duty = arg_int1(NULL, NULL, "<duty>", EXPENDABLE_STRING("Duty cycle"));
cmd_args.end = arg_end(1);
reg->argtable = &cmd_args;
reg->help = "Set duty 0-1023";
return 0;
}
uint32_t duty = (uint32_t) cmd_args.duty->ival[0];
if (duty > 950) {
duty = 950;
}
pwm_duty = duty;
act_pwm_set(pwm_on);
gSettings.pwm_duty = duty;
settings_persist(SETTINGS_pwm_duty);
return 0;
}
static int cmd_freq(console_ctx_t *ctx, cmd_signature_t *reg)
{
static struct {
struct arg_int *freq;
struct arg_end *end;
} cmd_args;
if (reg) {
cmd_args.freq = arg_int1(NULL, NULL, "<freq>", EXPENDABLE_STRING("Freq"));
cmd_args.end = arg_end(1);
reg->argtable = &cmd_args;
reg->help = "Set freq Hz";
return 0;
}
uint32_t freq = (uint32_t) cmd_args.freq->ival[0];
pwm_freq = freq;
act_pwm_update_conf();
gSettings.pwm_freq = freq;
settings_persist(SETTINGS_pwm_freq);
return 0;
}
static int cmd_thres(console_ctx_t *ctx, cmd_signature_t *reg)
{
static struct {
struct arg_int *thres;
struct arg_end *end;
} cmd_args;
if (reg) {
cmd_args.thres = arg_int1(NULL, NULL, "<thres>", EXPENDABLE_STRING("Threshold mV 0-950"));
cmd_args.end = arg_end(1);
reg->argtable = &cmd_args;
reg->help = "Set thres 0-1023";
return 0;
}
uint32_t thres = (uint32_t) cmd_args.thres->ival[0];
pwm_thres = thres;
act_pwm_set(pwm_on);
gSettings.pwm_thres = thres;
settings_persist(SETTINGS_pwm_thres);
return 0;
}
void register_cmd_pwm(void)
{
console_cmd_register(cmd_pwm_show, "pwm");
console_cmd_register(cmd_duty, "duty");
console_cmd_register(cmd_freq, "freq");
console_cmd_register(cmd_thres, "thres");
console_cmd_add_alias_fn(cmd_duty, "d");
console_cmd_add_alias_fn(cmd_freq, "f");
console_cmd_add_alias_fn(cmd_thres, "t");
}