Skip to content

Commit

Permalink
remove some old code and vars, set defaults
Browse files Browse the repository at this point in the history
run heater/sensors
  • Loading branch information
vortigont committed May 18, 2024
1 parent 5d2802d commit 378b16f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 174 deletions.
2 changes: 1 addition & 1 deletion ESPIron/heater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ void TipHeater::_heaterControl(){
ledc_set_duty(LEDC_MODE, _pwm.channel, 0);
ledc_update_duty(LEDC_MODE, _pwm.channel);
_state = HeaterState_t::notip;
LOGI(T_HEAT, printf, "Iron Tip ejected, T:%d\n", t);
LOGI(T_HEAT, printf, "Iron Tip ejected, T:%d\n", static_cast<int32_t>(t));
EVT_POST(SENSOR_DATA, e2int(evt::iron_t::tipEject));
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion ESPIron/hid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ U8G2_SH1107_64X128_F_HW_I2C u8g2(U8G2_R1, SH1107_RST_PIN);
#error Wrong OLED controller type!
#endif

#define TIMER_DISPLAY_REFRESH 10 // 10 fps max (screen redraw is ~35 ms)
#define TIMER_DISPLAY_REFRESH 100 // 10 fps max (screen redraw is ~35 ms)

#define X_OFFSET_TIP_TEMP 50
#define Y_OFFSET_TIP_TEMP 18
Expand Down
45 changes: 14 additions & 31 deletions ESPIron/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,12 @@ VinSensor vin;
bool beepEnable = BEEP_ENABLE;
bool QCEnable = QC_ENABLE;


// Default value for T12
// T12的默认值
uint16_t CalTemp[TIPMAX][4] = {TEMP200, TEMP280, TEMP360, TEMPCHP};
char TipName[TIPMAX][TIPNAMELENGTH] = {TIPNAME};
uint8_t CurrentTip = 0;
uint8_t NumberOfTips = 1;

// MSC Firmware
bool MSC_Updating_Flag = false;




// *** Arduino setup ***
void setup() {
// set PD-trigger pins
Expand All @@ -63,10 +58,9 @@ void setup() {

#if PTS200_DEBUG_LEVEL > 3
// let ACM device intitialize to catch early log output
delay(4000);
delay(3000);
#endif
Serial.printf( "ESPIron PTS200 firmware version: %s\n", FW_VERSION);
//LOGI(T_IRON, printf, "ESPIron PTS200 firmware version: %s\n", FW_VERSION);
LOGI(T_IRON, printf, "ESPIron PTS200 firmware version: %s\n", FW_VERSION);

// Start event loop task
evt::start();
Expand Down Expand Up @@ -111,11 +105,11 @@ void setup() {
}
#endif

// Initialize IronController
// Initialize Iron Controller
espIron.init();

// request configured voltage via PD trigger
//PD_Update();
PD_Update();

// I2C bus (for display)
Wire.begin();
Expand Down Expand Up @@ -158,48 +152,37 @@ void beep() {
}


int32_t variance(int16_t a[]) {
// Compute mean (average of elements)计算平均值(元素的平均值)
int32_t sum = 0;

for (int i = 0; i < 32; i++) sum += a[i];
int16_t mean = (int32_t)sum / 32;
// Compute sum squared differences with mean.计算和平方差的平均值
int32_t sqDiff = 0;
for (int i = 0; i < 32; i++) sqDiff += (a[i] - mean) * (a[i] - mean);
return (int32_t)sqDiff / 32;
}

void PD_Update() {
// fake readings for now
int VoltageValue = 20;
switch (VoltageValue) {
// 9 volts
case 0: {
case 9: {
digitalWrite(PD_CFG_0, LOW);
digitalWrite(PD_CFG_1, LOW);
digitalWrite(PD_CFG_2, LOW);
} break;
// 12 volts
case 1: {
case 12: {
digitalWrite(PD_CFG_0, LOW);
digitalWrite(PD_CFG_1, LOW);
digitalWrite(PD_CFG_2, HIGH);
} break;
// 15 volts
case 2: {
case 15: {
digitalWrite(PD_CFG_0, LOW);
digitalWrite(PD_CFG_1, HIGH);
digitalWrite(PD_CFG_2, HIGH);
} break;
// 20 volts
case 3:
case 4: {
case 20: {
digitalWrite(PD_CFG_0, LOW);
digitalWrite(PD_CFG_1, HIGH);
digitalWrite(PD_CFG_2, LOW);
} break;
default:;
default:
// start PD trigger with default 5 volts
digitalWrite(PD_CFG_0, HIGH);
}
/*
if (VoltageValue == 3) {
Expand Down
125 changes: 0 additions & 125 deletions ESPIron/main.h
Original file line number Diff line number Diff line change
@@ -1,139 +1,14 @@
#pragma once
#include "Arduino.h"
#include "Languages.h"


// function forward declarations

void getEEPROM();

void PD_Update();

float getVIN();

/**
* @brief Averaging 32 ADC readings to reduce noise
* 对32个ADC读数进行平均以降噪
* VP+_Ru = 100k, Rd_GND = 1K
*
*/
//float denoiseAnalog(byte port);

// calculates real temperature value according to ADC reading and calibration values
// 根据ADC读数和校准值,计算出真实的温度值
int32_t calculateTemp(float t);

// reads current rotary encoder value 读取当前旋转编码器值
int getRotary();

// sets start values for rotary encoder
// 设置旋转编码器的起始值
void setRotary(int rmin, int rmax, int rstep, int rvalue);

// creates a short beep on the buzzer
// 在蜂鸣器上创建一个短的哔哔声
void beep();

/**
* @brief check rotary encoder; set temperature, toggle boost mode, enter setup menu// accordingly
* 检查旋转编码器;设置温度,切换升压模式,进入设置菜单相应
*
*/
void ROTARYCheck();

/**
* @brief check and activate/deactivate sleep modes
* 检查和激活/关闭睡眠模式
*
*/
void SLEEPCheck();

/**
* @brief reads temperature, vibration switch and supply voltages
* 读取温度,振动开关和电源电压
*/
void SENSORCheck();

/**
* @brief measure tip temperature
* this will disable PWM!!!
*/
void measureTipTemp();

/**
* @brief input value screen
* 输入值屏幕
*
* @param Items
* @return uint16_t
*/
uint16_t InputScreen(const char *Items[][language_types]);

/**
* @brief // menu screen
* 菜单屏幕
* @param Items
* @param numberOfItems
* @param selected
* @return uint8_t
*/
uint8_t MenuScreen(const char *Items[][language_types], uint8_t numberOfItems, uint8_t selected);

/**
* @brief input value screen
* 输入值屏幕
* @param Items
* @return uint16_t
*/
uint16_t InputScreen(const char *Items[][language_types]);

/**
* @brief controls the heater
* 控制加热器
*/
void thermostatCheck();

/**
* @brief draws the main screen
* 绘制主屏幕
*
*/
void MainScreen();

// setup screen 设置屏幕
void SetupScreen();

// tip settings screen 烙铁头设置屏幕
void TipScreen();

// temperature settings screen 温度设置屏幕
void TempScreen();

// timer settings screen 定时器设置屏幕
void TimerScreen();

// menu screen 菜单屏幕
uint8_t MenuScreen(const char *Items[][language_types], uint8_t numberOfItems, uint8_t selected);

// change tip screen 改变烙铁头屏幕
void ChangeTipScreen();

// temperature calibration screen 温度校准屏幕
void CalibrationScreen();

// input tip name screen 输入烙铁头名字屏幕
void InputNameScreen();

// delete tip screen 删除烙铁头屏幕
void DeleteTipScreen();

// add new tip screen 添加新的烙铁头屏幕
void AddTipScreen();

// information display screen 信息显示屏幕
void InfoScreen();

// check -/+ buttons press
void Button_loop();

static void usbEventCallback(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
41 changes: 28 additions & 13 deletions ESPIron/sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
#include "log.h"

#define LIS
#define ACCEL_MOTION_FACTOR 25000
#define ACCEL_MOTION_FACTOR 25000
#define ACCEL_MOTION_POLL_PERIOD 50 // ms
#define ACCEL_TEMPERATURE_POLL_PERIOD 1000 // ms
#define ACCEL_TEMPERATURE_POLL_PERIOD 3000 // ms

#define VIN_ADC_POLL_PERIOD 1000 // ms
#define VIN_ADC_POLL_PERIOD 1500 // ms

GyroSensor::~GyroSensor(){
// unsubscribe from event bus
Expand All @@ -28,6 +28,7 @@ void GyroSensor::init(){
LOGE(T_GYRO, println, "Accelerometer not detected.");
return;
}
LOGI(T_Sensor, println, "Init Accelerometer sensor");

// start temperature polling
if (!_tmr_temp){
Expand All @@ -37,8 +38,8 @@ void GyroSensor::init(){
static_cast<void*>(this),
[](TimerHandle_t h) { static_cast<GyroSensor*>(pvTimerGetTimerID(h))->_temperature_poll(); }
);
if (_tmr_temp)
xTimerStart( _tmr_temp, pdMS_TO_TICKS(10) );
//if (_tmr_temp)
// xTimerStart( _tmr_temp, portMAX_DELAY );
}

// start accl polling
Expand All @@ -49,8 +50,9 @@ void GyroSensor::init(){
static_cast<void*>(this),
[](TimerHandle_t h) { static_cast<GyroSensor*>(pvTimerGetTimerID(h))->_accel_poll(); }
);
// keep it disabled on begin, TODO: realct on events from mode changes
xTimerStart( _tmr_accel, pdMS_TO_TICKS(10) );
// TODO: realct on events from mode changes
//if (_tmr_accel)
// xTimerStart( _tmr_accel, portMAX_DELAY );
}

// subscribe to event bus
Expand All @@ -64,7 +66,9 @@ void GyroSensor::init(){
&_evt_set_handler
);
}


// start sensor polling
enable();
// lis2dh12_block_data_update_set(&(accel.dev_ctx), PROPERTY_DISABLE);
// accel.setScale(LIS2DH12_2g);
// accel.setMode(LIS2DH12_HR_12bit);
Expand Down Expand Up @@ -186,20 +190,26 @@ void GyroSensor::enable(){
std::unique_ptr<nvs::NVSHandle> nvs = nvs::open_nvs_handle(T_Sensor, NVS_READONLY, &err);

// load configured motion threshold
if (err != ESP_OK) {
if (err == ESP_OK) {
_motionThreshold = WAKEUP_THRESHOLD;
nvs->get_item(T_motionThr, _motionThreshold);
}

// start sensor polling
if (_tmr_accel)
xTimerStart( _tmr_accel, pdMS_TO_TICKS(10) );
xTimerStart( _tmr_accel, portMAX_DELAY );

LOGD(T_GYRO, printf, "gyro enabled, thr:%u\n", _motionThreshold);
if (_tmr_temp)
xTimerStart( _tmr_temp, portMAX_DELAY );
LOGD(T_GYRO, printf, "accel sensor enabled, thr:%u\n", _motionThreshold);
}

void GyroSensor::disable(){
if (_tmr_accel)
xTimerStop( _tmr_accel, pdMS_TO_TICKS(10) );
xTimerStop( _tmr_accel, portMAX_DELAY );

if (_tmr_temp)
xTimerStop( _tmr_temp, portMAX_DELAY );
}

void GyroSensor::_clear(){
Expand All @@ -221,6 +231,7 @@ void GyroSensor::_temperature_poll(){
// *** VinSensor methods ***

void VinSensor::init(){
LOGI(T_Sensor, println, "Init Voltage sensor");
// input voltage pin ADC
adc_vin.attach(VIN_PIN);

Expand All @@ -233,7 +244,11 @@ void VinSensor::init(){
[](TimerHandle_t h) { static_cast<VinSensor*>(pvTimerGetTimerID(h))->_runner(); }
);
// start poller right away
xTimerStart( _tmr_runner, pdMS_TO_TICKS(10) );
if (_tmr_runner && xTimerStart( _tmr_runner, portMAX_DELAY ) == pdPASS){
LOGD(T_Sensor, println, "Enable Input voltage polling");
} else {
LOGE(T_Sensor, println, "Unable to start voltage polling");
}
}

/*
Expand Down
6 changes: 3 additions & 3 deletions ESPIron/sensors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class GyroSensor {

SPARKFUN_LIS2DH12 accel;
// temperature polling timer
TimerHandle_t _tmr_temp = nullptr;
TimerHandle_t _tmr_temp{nullptr};
// accell sensor polling timer
TimerHandle_t _tmr_accel = nullptr;
TimerHandle_t _tmr_accel{nullptr};

esp_event_handler_instance_t _evt_set_handler = nullptr;

Expand Down Expand Up @@ -107,7 +107,7 @@ class GyroSensor {
*/
class VinSensor {
// RTOS polling timer
TimerHandle_t _tmr_runner = nullptr;
TimerHandle_t _tmr_runner{nullptr};

//esp_event_handler_instance_t _evt_set_handler = nullptr;

Expand Down

0 comments on commit 378b16f

Please sign in to comment.