Skip to content

Commit

Permalink
Merge branch 'ctrl'
Browse files Browse the repository at this point in the history
  • Loading branch information
vortigont committed May 13, 2024
2 parents c6be456 + 79d38b2 commit 5f830f9
Show file tree
Hide file tree
Showing 31 changed files with 3,101 additions and 1,213 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
.pioenvs
.piolibdeps
.clang_complete
.gcc-flags.json
.pio
.vscode
.DS_Store
.idea
.lnk
temp/
platformio_*.ini
SolderingPen_ESP32S2/build
SolderingPen_ESP32S2/.idea
SolderingPen_ESP32S2/config_*.h
5 changes: 0 additions & 5 deletions SolderingPen_ESP32S2/SolderingPen_ESP32S2.ino

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

bool write_default_EEPROM(){
Serial.println("Writing default config to EEPROM");

/*
EEPROM.writeUShort(ADDR_DEFAULT_TEMP, TEMP_DEFAULT);
EEPROM.writeUShort(ADDR_SLEEP_TEMP, TEMP_SLEEP);
EEPROM.writeUChar(ADDR_BOOST_TEMP, TEMP_BOOST);
EEPROM.writeUShort(ADDR_TIME_2_SLEEP, TIME2SLEEP);
EEPROM.writeUChar(ADDR_TIME_2_OFF, TIME2OFF);
EEPROM.writeUChar(ADDR_TIME_OF_BOOST, TIMEOFBOOST);
*/
EEPROM.writeUChar(ADDR_MAIN_SCREEN, MAINSCREEN);
// EEPROM.writeBool(ADDR_PID_ENABLE, PID_ENABLE);
EEPROM.writeBool(ADDR_BEEP_ENABLE, BEEP_ENABLE);
Expand Down Expand Up @@ -36,7 +37,7 @@ bool write_default_EEPROM(){
EEPROM.writeUChar(ADDR_LANGUAGE, DEFAULT_LANGUAGE);
EEPROM.writeUChar(ADDR_HAND_SIDE, DEFAULT_HAND_SIDE);

EEPROM.writeUInt(ADDR_SYSTEM_INIT_FLAG, VERSION_NUM);
EEPROM.writeUInt(ADDR_SYSTEM_INIT_FLAG, FW_VERSION_NUM);

if (EEPROM.commit())
{
Expand Down Expand Up @@ -66,19 +67,20 @@ bool init_EEPROM(){

bool update_EEPROM(){
Serial.println("Updating EEPROM");

/*
EEPROM.writeUShort(ADDR_DEFAULT_TEMP, DefaultTemp);
EEPROM.writeUShort(ADDR_SLEEP_TEMP, SleepTemp);
EEPROM.writeUChar(ADDR_BOOST_TEMP, BoostTemp);
EEPROM.writeUShort(ADDR_TIME_2_SLEEP, time2sleep);
EEPROM.writeUChar(ADDR_TIME_2_OFF, time2off);
EEPROM.writeUChar(ADDR_TIME_OF_BOOST, timeOfBoost);
*/
EEPROM.writeUChar(ADDR_MAIN_SCREEN, MainScrType);
// EEPROM.writeBool(ADDR_PID_ENABLE, PIDenable);
EEPROM.writeBool(ADDR_BEEP_ENABLE, beepEnable);
EEPROM.writeUChar(ADDR_VOLTAGE_VALUE, VoltageValue);
// EEPROM.writeUChar(ADDR_VOLTAGE_VALUE, VoltageValue);
EEPROM.writeBool(ADDR_QC_ENABLE, QCEnable);
EEPROM.writeUChar(ADDR_WAKEUP_THRESHOLD, WAKEUPthreshold);
//EEPROM.writeUChar(ADDR_WAKEUP_THRESHOLD, WAKEUPthreshold);
EEPROM.writeUChar(ADDR_CURRENT_TIP, CurrentTip);
EEPROM.writeUChar(ADDR_NUMBER_OF_TIPS, NumberOfTips);

Expand All @@ -94,7 +96,7 @@ bool update_EEPROM(){
EEPROM.writeUChar(ADDR_LANGUAGE, language);
EEPROM.writeUChar(ADDR_HAND_SIDE, hand_side);

EEPROM.writeUInt(ADDR_SYSTEM_INIT_FLAG, VERSION_NUM);
EEPROM.writeUInt(ADDR_SYSTEM_INIT_FLAG, FW_VERSION_NUM);

if (EEPROM.commit())
{
Expand All @@ -115,27 +117,27 @@ bool read_EEPROM(){

// system_init_flag = EEPROM.readUInt(ADDR_SYSTEM_INIT_FLAG);

if (EEPROM.readUInt(ADDR_SYSTEM_INIT_FLAG) != VERSION_NUM)
if (EEPROM.readUInt(ADDR_SYSTEM_INIT_FLAG) != FW_VERSION_NUM)
{
// return false;
Serial.println("System didn't initialised");
write_default_EEPROM();
}

// EEPROM.readString(ADDR_WIFI_SSID_1).toCharArray(WiFi_SSID_1, sizeof(WiFi_SSID_1));

/*
DefaultTemp = EEPROM.readUShort(ADDR_DEFAULT_TEMP);
SleepTemp = EEPROM.readUShort(ADDR_SLEEP_TEMP);
BoostTemp = EEPROM.readUChar(ADDR_BOOST_TEMP);
time2sleep = EEPROM.readUShort(ADDR_TIME_2_SLEEP);
time2off = EEPROM.readUChar(ADDR_TIME_2_OFF);
timeOfBoost = EEPROM.readUChar(ADDR_TIME_OF_BOOST);
*/
MainScrType = EEPROM.readUChar(ADDR_MAIN_SCREEN);
// PIDenable = EEPROM.readBool(ADDR_PID_ENABLE);
beepEnable = EEPROM.readBool(ADDR_BEEP_ENABLE);
VoltageValue = EEPROM.readUChar(ADDR_VOLTAGE_VALUE);
// VoltageValue = EEPROM.readUChar(ADDR_VOLTAGE_VALUE);
QCEnable = EEPROM.readBool(ADDR_QC_ENABLE);
WAKEUPthreshold = EEPROM.readUChar(ADDR_WAKEUP_THRESHOLD);
//WAKEUPthreshold = EEPROM.readUChar(ADDR_WAKEUP_THRESHOLD);
CurrentTip = EEPROM.readUChar(ADDR_CURRENT_TIP);
NumberOfTips = EEPROM.readUChar(ADDR_NUMBER_OF_TIPS);

Expand All @@ -155,9 +157,10 @@ bool read_EEPROM(){
}

bool update_default_temp_EEPROM(){
return true;
Serial.println("Updating default temp in EEPROM");

EEPROM.writeUShort(ADDR_DEFAULT_TEMP, DefaultTemp);
//EEPROM.writeUShort(ADDR_DEFAULT_TEMP, DefaultTemp);

if (EEPROM.commit())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
#define ADDR_EEPROM_SIZE ADDR_HAND_SIDE + 1


extern uint16_t DefaultTemp;
extern uint16_t SleepTemp;
extern uint8_t BoostTemp;
extern uint16_t time2sleep;
extern uint8_t time2off;
extern uint8_t timeOfBoost;
//extern uint16_t DefaultTemp;
//extern uint16_t SleepTemp;
//extern uint8_t BoostTemp;
//extern uint16_t time2sleep;
//extern uint8_t time2off;
//extern uint8_t timeOfBoost;
extern uint8_t MainScrType;
extern bool beepEnable;
extern volatile uint8_t VoltageValue;
//extern volatile uint8_t VoltageValue;
extern bool QCEnable;
extern uint8_t WAKEUPthreshold;
//extern uint8_t WAKEUPthreshold;
extern uint8_t CurrentTip;
extern uint8_t NumberOfTips;

Expand Down
37 changes: 37 additions & 0 deletions SolderingPen_ESP32S2/common.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
This file is a part of ESPIron-PTS200 project
https://github.com/vortigont/ESPIron-PTS200
Copyright © 2024 Emil Muratov (vortigont)
ESPIron-PTS200 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
*/
#pragma once
#if defined CUSTOM_CFG
# include CUSTOM_CFG
#warning "include custom cfg file"
#else
#include "config.h"
#endif
#include <stdint.h>

enum class ironState_t {
idle = 0, // everything is on, exept heater, Iron is in idle state, i.e. it was just powered ON
working, // everything is on, full function
standby, // heater is in standby mode, i.e. keeping warm after a certain period of inactivity
suspend, // hibernation mode
boost, // heater temperature is increased for a short period of time
setup, // iron is configuration mode, i.e. working with screen menu, heater switches off
notip // tip is missing or failed

};

// working temperature values
struct Temperatures {
int32_t working{TEMP_DEFAULT}, standby{TEMP_SLEEP}, boost{TEMP_BOOST}, deflt{TEMP_DEFAULT};
bool savewrk{false};
};

48 changes: 22 additions & 26 deletions SolderingPen_ESP32S2/config.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

// Firmware version
#define VERSION "v4.5.3" //20240130
#define VERSION_NUM 422
#define FW_VERSION "v0.0.1_experimental"
#define FW_VERSION_NUM 422

// Type of MOSFET
#define P_MOSFET // P_MOSFET or N_MOSFET
Expand All @@ -13,26 +13,15 @@
//typedef u8g2_uint_t u8g_uint_t;
#define SCREEN_OFFSET 2

// Type of rotary encoders / 旋转编码器的类型
#define ROTARY_TYPE 0 // 0: 2 increments/step; 1: 4 increments/step (default)
#define BUTTON_DELAY 5

// Pins
#define SENSOR_PIN 1 // tip temperature sense 烙铁头温感
#define VIN_PIN 6 // input voltage sense 检测输入电压
#define BUZZER_PIN 3 // buzzer 蜂鸣器
#define BUTTON_PIN 0 // switch 按键right
#define BUTTON_P_PIN 4 // 1 键位为“+”
#define BUTTON_N_PIN 2 // 2 键位为“-”
#define BUTTON_ACTION GPIO_NUM_0 // middle push-button
#define BUTTON_INCR GPIO_NUM_2 // incrementer “+” push-button
#define BUTTON_DECR GPIO_NUM_4 // decrementer “-” push-button
#define HEATER_PIN 5 // heater MOSFET PWM control 加热器MOSFET PWM控制
#define SH1107_RST_PIN 7 // display reset pin

// Heater PWM parameters
#define HEATER_CHANNEL LEDC_CHANNEL_2 // PWM channel
#define HEATER_FREQ 200 // PWM frequency
#define HEATER_HIGHFREQ 1000 // PWM frequency for 20V/50% PWM mode
#define HEATER_RES LEDC_TIMER_8_BIT // PWM resolution

// CH224K USB PD chip pins connection
// https://components101.com/sites/default/files/component_datasheet/WCH_CH224K_ENG.pdf
#define PD_CFG_0 16
Expand All @@ -42,15 +31,21 @@
#define QC_DP_PIN 14
#define QC_DM_PIN 13

// Heater PWM parameters
#define HEATER_CHANNEL LEDC_CHANNEL_2 // PWM channel
#define HEATER_FREQ 200 // PWM frequency
//#define HEATER_HIGHFREQ 1000 // PWM frequency for 20V/50% PWM mode
#define HEATER_RES LEDC_TIMER_8_BIT // PWM resolution

// Default temperature control value (recommended soldering temperature: 300~380°C)
// 默认温度控制值(推荐焊接温度:300~380°C)
#define TEMP_MIN 50 // 最小温度
#define TEMP_MIN 150 // 最小温度
#define TEMP_MAX 450 // 最大温度
#define TEMP_NOTIP 500 // virtual temperature when tip is not installed
#define TEMP_DEFAULT 260 // 默认温度
#define TEMP_SLEEP 150 // 休眠温度
#define TEMP_NOTIP 500 // virtual temperature threshold when tip is not installed
#define TEMP_DEFAULT 220 // 默认温度
#define TEMP_SLEEP 120 // 休眠温度
#define TEMP_BOOST 50 // 升温步进
#define TEMP_STEP 10 // temperature change step / 旋转编码器温度变化步进
#define TEMP_STEP 5 // temperature change step / 旋转编码器温度变化步进
#define POWER_LIMIT_15 170 // 功率限制
#define POWER_LIMIT_20 255 // 功率限制
#define POWER_LIMIT_20_2 127 // 功率限制
Expand All @@ -65,18 +60,19 @@
#define TIPNAMELENGTH 6 // max length of tip names (including termination)
#define TIPNAME "PTS " // default tip name

// Default timer value (0 = disabled) / 默认的定时器值 (0 = 禁用)
#define TIME2SLEEP 60 // sleep mode timer, seconds / 几秒钟后进入睡眠模式
#define TIME2OFF 5 // off timer, minutes / 几分钟后就要关闭加热器了
#define TIMEOFBOOST 60 // boos mode duration / 停留在加热模式多少秒
// Default timeout values, in milliseconds
#define TIMEOUT_STANDBY 60000 // standby time, when heater lowers it's temperature
#define TIMEOUT_IDLE 300000 // idle mode timeout, when Iron switches off the heater after a certain period of inactivity
#define TIMEOUT_SUSPEND 1200000 // suspend timeout
#define TIMEOUT_BOOST 60000 // boost mode duration / 停留在加热模式多少秒
#define WAKEUP_THRESHOLD 10 // MPU vibration detection accuracy, the smaller the value, the more sensitive it is / MPU 震动检测精度,数值越小,越灵敏

// Control values
#define TIME2SETTLE 5000 // The time in microseconds allowed for the OpAmp output to stabilize / 以微秒为单位的时间允许OpAmp输出稳定
#define TIME2SETTLE_20V 2000 // The time in microseconds allowed for the OpAmp output to stabilize / 以微秒为单位的时间允许OpAmp输出稳定
#define SMOOTHIE 0.2 // OpAmp output smoothing coefficient (1=no smoothing; default: 0.05) / OpAmp输出平滑系数 (1=无平滑; 默认:0.05)
//#define PID_ENABLE true // enable PID control
#define PID_ENGAGE_DIFF 50 // temperature difference when PID algo should be engaged
#define PID_ENGAGE_DIFF 30 // temperature difference when PID algo should be engaged
#define BEEP_ENABLE true // enable/disable buzzer
#define VOLTAGE_VALUE 3 // 电压值
#define QC_ENABLE false // enable/disable QC3.0
Expand Down
14 changes: 14 additions & 0 deletions SolderingPen_ESP32S2/const.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@

// static literals are defined here

// LOG tags
static constexpr const char* T_ADC = "ADC";
static constexpr const char* T_CTRL = "CTRL";
static constexpr const char* T_DBG = "DBG";
static constexpr const char* T_GYRO = "GYRO";
static constexpr const char* T_PWM = "PWM";
static constexpr const char* T_HEAT = "HEAT";

// NVS namespaces
static constexpr const char* T_IRON = "IRON";
static constexpr const char* T_Sensor = "Sensor";
static constexpr const char* T_UI = "UI";
static constexpr const char* T_HID = "HID";

// NVS keys
static constexpr const char* T_timeouts = "timeouts"; // blob with timeout values
static constexpr const char* T_temperatures = "temperatures"; // blob with temperature values

static constexpr const char* T_motionThr = "motionThr"; // motion threshold (uint32)

10 changes: 6 additions & 4 deletions SolderingPen_ESP32S2/evtloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@ static const char* TAG = "evt";
ESP_EVENT_DEFINE_BASE(SENSOR_DATA);
ESP_EVENT_DEFINE_BASE(IRON_SET_EVT);
ESP_EVENT_DEFINE_BASE(IRON_GET_EVT);
ESP_EVENT_DEFINE_BASE(IRON_STATE_EVT);
ESP_EVENT_DEFINE_BASE(IRON_CHANGE_EVT);
ESP_EVENT_DEFINE_BASE(IRON_NOTIFY);
ESP_EVENT_DEFINE_BASE(IRON_STATE);
ESP_EVENT_DEFINE_BASE(IRON_VISET);


namespace evt {

#define LOOP_EVT_Q_SIZE 16 // events loop queue size
#define LOOP_EVT_PRIORITY 1 // task priority is same as arduino's loop() to avoid extra context switches
#define LOOP_EVT_RUNNING_CORE tskNO_AFFINITY // ARDUINO_RUNNING_CORE
#ifdef PTS200_DEBUG_LEVEL
#define LOOP_EVT_STACK_SIZE 2048 // loop task stack size when debug is enabled, sprintf calls requires lots of mem
#define LOOP_EVT_STACK_SIZE 4096 // loop task stack size when debug is enabled, sprintf calls requires lots of mem
#else
#define LOOP_EVT_STACK_SIZE 1536 // loop task stack size
#define LOOP_EVT_STACK_SIZE 4096 // loop task stack size
#endif

void start(){
Expand Down
24 changes: 22 additions & 2 deletions SolderingPen_ESP32S2/evtloop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ESP_EVENT_DECLARE_BASE(IRON_SET_EVT); // ESPIron setter Commands events ba
ESP_EVENT_DECLARE_BASE(IRON_GET_EVT); // ESPIron getter Commands events base (in reply to this command, an IRON_STATE_EVT could be generated)
ESP_EVENT_DECLARE_BASE(IRON_NOTIFY); // ESPIron notification events base (those events are published when some state or mode changes due to any commands or component's logic)
ESP_EVENT_DECLARE_BASE(IRON_STATE); // ESPIron State publishing events base (those events are published on IRON_GET_EVT requests on demand)
ESP_EVENT_DECLARE_BASE(IRON_VISET); // ESPIron VisualSet HID events

// cast enum to int
template <class E>
Expand All @@ -40,12 +41,31 @@ enum class iron_t:int32_t {

// Sensors data 100-199
motion=100, // motion detected from GyroSensor

vin=110, // Vin voltage in millvolts, parameter uint32_t

tiptemp=120, // current Tip temperature, parameter int32_t
acceltemp=121, // accelerometer chip temperature, parameter float


// Commands
sensorsReload = 200, // reload configuration for any sensors available
heaterTargetT, // set heater target temperature, parameter int32_t
workTemp, // set working temperature, parameter int32_t
workModeToggle, // toggle working mode on/off
boostModeToggle, // toggle boost mode on/off

reloadTemp, // reload temperature configuration

// State notifications
stateWorking = 300,
stateStandby, // iron controller switched to 'Standby' mode
stateIdle,
stateSuspend,
stateBoost, // iron controller switched to 'Boost' mode, parameter uint32_t - seconds left to disable boost mode
stateSetup,
stateNoTip,
tipEject, // sent by heater when it looses the tip sense
tipInsert, // sent by heater when detect tip sensor

// END
noop_end // stub
};
Expand Down
Loading

0 comments on commit 5f830f9

Please sign in to comment.