Skip to content

Commit

Permalink
remove fan control in setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Seungcheol committed Nov 3, 2021
1 parent 5d6a0f5 commit f91d845
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 144 deletions.
Binary file modified prebuilt/firmware.bin
Binary file not shown.
58 changes: 0 additions & 58 deletions smartpower3/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,10 @@ void Screen::checkOnOff()
setting->setBacklightLevel(0);
writeSysLED(0);
setting->setLogIntervalValue(0);
setting->setFanLevel(0);
} else {
shutdown = false;
tft.fillRect(0, 0, 480, 320, TFT_BLACK);
setting->setLogInterval();
setting->setFanLevel();
setting->setBacklightLevel();

header->init(5, 8);
Expand Down Expand Up @@ -214,7 +212,6 @@ void Screen::deActivate()
void Screen::deActivateSetting()
{
setting->deActivateBLLevel();
setting->deActivateFanLevel();
setting->deActivateSerialLogging();
}

Expand Down Expand Up @@ -272,9 +269,6 @@ void Screen::activate_setting()
case STATE_BL:
setting->activateBLLevel();
break;
case STATE_FAN:
setting->activateFanLevel();
break;
case STATE_LOG:
setting->activateSerialLogging();
break;
Expand Down Expand Up @@ -442,10 +436,6 @@ void Screen::drawSetting()
mode = SETTING_BL;
dial_cnt = setting->getBacklightLevel();
setting->activateBLLevel(TFT_GREEN);
} else if (activated == STATE_FAN) {
mode = SETTING_FAN;
dial_cnt = setting->getFanLevel();
setting->activateFanLevel(TFT_GREEN);
} else if (activated == STATE_LOG) {
mode = SETTING_LOG;
dial_cnt = setting->getSerialBaudLevel();
Expand Down Expand Up @@ -501,50 +491,6 @@ void Screen::drawSettingBL()
}
}

void Screen::drawSettingFAN()
{
if ((cur_time - dial_time) > 10000) {
mode = SETTING;
deActivateSetting();
activated = dial_cnt = dial_cnt_old = STATE_NONE;
dial_cnt_old = STATE_NONE;
setting->changeFan();
setting->deActivateFanLevel();
}
if ((btn_pressed[2] == true) || (flag_long_press == 2)) {
flag_long_press = 3;
btn_pressed[2] = false;
disableBtn();
mode = SETTING;
activated = dial_cnt = dial_cnt_old = STATE_FAN;
deActivateSetting();
setting->changeFan();
setting->activateFanLevel();

enableBtn();
return;
}
if (btn_pressed[3] == true) {
btn_pressed[3] = false;
disableBtn();
mode = SETTING;
activated = dial_cnt = dial_cnt_old = STATE_FAN;
setSysParam("fan_level", String(setting->setFanLevel()));
setting->activateFanLevel();

enableBtn();
return;
}
if (dial_cnt != dial_cnt_old) {
if (dial_cnt < 0)
dial_cnt = 0;
else if (dial_cnt > 6)
dial_cnt = 6;
dial_cnt_old = dial_cnt;
setting->changeFan(dial_cnt);
}
}

void Screen::drawSettingLOG()
{
if ((cur_time - dial_time) > 10000) {
Expand Down Expand Up @@ -644,9 +590,6 @@ void Screen::drawScreen()
case SETTING_BL:
drawSettingBL();
break;
case SETTING_FAN:
drawSettingFAN();
break;
case SETTING_LOG:
drawSettingLOG();
break;
Expand Down Expand Up @@ -993,7 +936,6 @@ void Screen::fsInit(void)
channel[1]->setVolt(volt_set1, 1);
channel[1]->setCurrentLimit(current_limit1, 1);
setting->setBacklightLevel(backlight_level, true);
setting->setFanLevel(fan_level);
setting->setSerialBaud(serial_baud);
setting->setLogIntervalValue(log_interval);
readFile("/setting.txt");
Expand Down
5 changes: 1 addition & 4 deletions smartpower3/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@ enum screen_mode_t {
BASE_EDIT,
SETTING,
SETTING_BL,
SETTING_FAN,
SETTING_LOG,
};

enum state {
STATE_VOLT1 = 0,
STATE_CURRENT1,
STATE_CURRENT0,
STATE_VOLT0,
STATE_VOLT0
};

enum state_setting {
STATE_LOG = 0,
STATE_FAN,
STATE_BL,
STATE_NONE
};
Expand Down Expand Up @@ -106,7 +104,6 @@ class Screen
void drawBaseMove(void);
void drawSetting(void);
void drawSettingBL(void);
void drawSettingFAN(void);
void drawSettingLOG(void);
static bool _int;
uint8_t state_power = 0;
Expand Down
81 changes: 11 additions & 70 deletions smartpower3/setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ Setting::Setting(TFT_eSPI *tft)
ledcSetup(2, FREQ, RESOLUTION);
ledcAttachPin(BL_LCD, 2);

ledcSetup(3, FREQ, RESOLUTION);
ledcAttachPin(FAN, 3);

popup = new TFT_eSprite(tft);
popup->createSprite(100, 100);

Expand All @@ -32,31 +29,25 @@ void Setting::init(uint16_t x, uint16_t y)

tft->loadFont("Chewy-Regular32");
tft->drawString("Backlight Level", x, y, 4);
tft->drawString("Fan Level", x, y + 50, 4);
tft->drawString("Serial Logging", x, y + 100, 4);
tft->drawString("Serial Logging", x, y + Y_SERIAL_LOGGING, 4);
tft->unloadFont();

tft->fillRect(x + X_BL_LEVEL, y, 135, 26, TFT_BLACK);
tft->drawRect(x + X_BL_LEVEL, y-1, 135, 28, TFT_YELLOW);
changeBacklight(backlight_level);

tft->fillRect(x + X_FAN_LEVEL, y + 50, 135, 26, TFT_BLACK);
tft->drawRect(x + X_FAN_LEVEL, y-1 + 50, 135, 28, TFT_YELLOW);
changeFan(fan_level);

com_serial_baud->init(TFT_WHITE, TFT_BLACK, 1, MC_DATUM);
com_serial_baud->setCoordinate(x + X_LOG_LEVEL-35, y + 130);
tft->loadFont("Chewy-Regular24");
tft->drawString("Baud Rate /", x + X_LOG_LEVEL-25, y + 100);
tft->drawString("/", x + X_LOG_LEVEL+85, y + 130);
tft->unloadFont();
drawSerialBaud(this->serial_baud);

com_serial_baud->setCoordinate(x + X_LOG_LEVEL-35, y + 30 + Y_SERIAL_LOGGING);
com_log_interval->init(TFT_WHITE, TFT_BLACK, 1, MC_DATUM);
com_log_interval->setCoordinate(x + X_LOG_LEVEL+105, y + 130);
com_log_interval->setCoordinate(x + X_LOG_LEVEL+105, y + 30 + Y_SERIAL_LOGGING);

tft->loadFont("Chewy-Regular24");
tft->drawString(" Interval", x + X_LOG_LEVEL+100, y + 100);
tft->drawString("Baud Rate /", x + X_LOG_LEVEL-25, y + Y_SERIAL_LOGGING);
tft->drawString("/", x + X_LOG_LEVEL+85, y + 30 + Y_SERIAL_LOGGING);
tft->drawString(" Interval", x + X_LOG_LEVEL+100, y + Y_SERIAL_LOGGING);
tft->unloadFont();

drawSerialBaud(this->serial_baud);
drawLogInterval(log_value[log_interval]);
}

Expand Down Expand Up @@ -96,21 +87,6 @@ void Setting::setBacklightLevel(uint8_t level)
backlight_level = _setBacklightLevel(level);
}

uint8_t Setting::setFanLevel(void)
{
return fan_level = fan_level_edit;
}

void Setting::setFanLevel(uint8_t level)
{
if (level > 6)
level = 6;
else if (level < 0)
level = 0;
fan_level = level;
ledcWrite(3, fan_value[level]);
}

void Setting::setLogIntervalValue(uint16_t val)
{
log_interval = val;
Expand Down Expand Up @@ -140,11 +116,6 @@ uint8_t Setting::getBacklightLevel(void)
return backlight_level;
}

uint8_t Setting::getFanLevel(void)
{
return fan_level;
}

uint16_t Setting::getLogInterval(void)
{
return log_interval;
Expand Down Expand Up @@ -187,16 +158,6 @@ void Setting::changeBacklight(uint8_t level)
ledcWrite(2, bl_value[level]);
}

void Setting::changeFan(uint8_t level)
{
if (level == 255) {
level = fan_level;
}
drawFanLevel(level);
fan_level_edit = level;
ledcWrite(3, fan_value[level]);
}

void Setting::restoreLogInterval()
{
drawLogInterval(log_value[this->log_interval]);
Expand Down Expand Up @@ -240,16 +201,10 @@ void Setting::activateBLLevel(uint16_t color)
tft->drawRect(x + X_BL_LEVEL-i, y-1-i, 135+i*2, 28+i*2, color);
}

void Setting::activateFanLevel(uint16_t color)
{
for (int i = 1; i < 4; i++)
tft->drawRect(x + X_FAN_LEVEL -i, y-1-i + 50, 135+i*2, 28+i*2, color);
}

void Setting::activateSerialLogging(uint16_t color)
{
for (int i = 1; i < 4; i++)
tft->drawRect(x + X_LOG_LEVEL -i-50, y-1-i + 100-10, 135+i*2+120, 28+i*2+40, color);
tft->drawRect(x + X_LOG_LEVEL -i-50, y-1-i + Y_SERIAL_LOGGING -10, 135+i*2+120, 28+i*2+40, color);
}

void Setting::activateLogInterval(uint16_t color)
Expand All @@ -264,12 +219,6 @@ void Setting::deActivateBLLevel(uint16_t color)
tft->drawRect(x + X_BL_LEVEL -i, y-1-i, 135+i*2, 28+i*2, color);
}

void Setting::deActivateFanLevel(uint16_t color)
{
for (int i = 1; i < 4; i++)
tft->drawRect(x + X_FAN_LEVEL -i, y-1-i + 50, 135+i*2, 28+i*2, color);
}

void Setting::deActivateLogInterval(uint16_t color)
{
com_log_interval->setTextColor(color, TFT_BLACK);
Expand All @@ -280,7 +229,7 @@ void Setting::deActivateLogInterval(uint16_t color)
void Setting::deActivateSerialLogging(uint16_t color)
{
for (int i = 1; i < 4; i++)
tft->drawRect(x + X_LOG_LEVEL -i-50, y-1-i + 100-10, 135+i*2+120, 28+i*2+40, color);
tft->drawRect(x + X_LOG_LEVEL -i-50, y-1-i + Y_SERIAL_LOGGING -10, 135+i*2+120, 28+i*2+40, color);
}


Expand All @@ -292,14 +241,6 @@ void Setting::drawBacklightLevel(uint8_t level)
}
}

void Setting::drawFanLevel(uint8_t level)
{
tft->fillRect(x + X_FAN_LEVEL + 2, y+1 + 50, 130, 24, TFT_BLACK);
for (int i = 0; i < level; i++) {
tft->fillRect(x + X_FAN_LEVEL + 2 + (i*22), y + 1 + 50, 20, 24, TFT_YELLOW);
}
}

void Setting::activateSerialBaud(uint16_t color)
{
com_serial_baud->setTextColor(color, TFT_BLACK);
Expand Down
14 changes: 2 additions & 12 deletions smartpower3/setting.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#include <TFT_eSPI.h>
#include "component.h"

#define FAN 12
#define BL_LCD 17
#define FREQ 50000
#define RESOLUTION 8

#define X_BL_LEVEL 250
#define X_FAN_LEVEL 250
#define Y_BL_LEVEL 20
#define X_LOG_LEVEL 250
#define Y_SERIAL_LOGGING 60

class Setting
{
Expand All @@ -21,42 +21,35 @@ class Setting
void setBacklightLevel(uint8_t level);
void setBacklightLevel(uint8_t level, bool edit);
uint8_t _setBacklightLevel(uint8_t level);
uint8_t setFanLevel(void);
void setFanLevel(uint8_t level);
uint16_t setLogInterval(void);
void setLogIntervalValue(uint16_t val);
uint32_t setSerialBaud(uint32_t baud);
uint32_t setSerialBaud();

uint8_t getBacklightLevel(void);
uint8_t getFanLevel(void);
uint16_t getLogInterval(void);
uint16_t getLogIntervalValue(void);
uint32_t getSerialBaud(void);
uint8_t getSerialBaudLevel(void);

void changeBacklight(uint8_t level=255);
void restoreBacklight();
void changeFan(uint8_t level=255);
void changeLogInterval(uint16_t log_interval);
void changeSerialBaud(uint8_t baud_level);
void restoreSerialBaud(void);
void restoreLogInterval(void);

void activateBLLevel(uint16_t color=TFT_YELLOW);
void activateFanLevel(uint16_t color=TFT_YELLOW);
void activateLogInterval(uint16_t color=TFT_YELLOW);
void activateSerialBaud(uint16_t color=TFT_YELLOW);
void activateSerialLogging(uint16_t color=TFT_YELLOW);

void deActivateBLLevel(uint16_t color=TFT_BLACK);
void deActivateFanLevel(uint16_t color=TFT_BLACK);
void deActivateLogInterval(uint16_t color=TFT_BLACK);
void deActivateSerialBaud(uint16_t color=TFT_BLACK);
void deActivateSerialLogging(uint16_t color=TFT_BLACK);

void drawBacklightLevel(uint8_t level);
void drawFanLevel(uint8_t level);
void drawLogInterval(uint16_t log_interval);
void drawSerialBaud(uint32_t serial_baud);
void popUp(void);
Expand All @@ -70,12 +63,9 @@ class Setting
uint16_t y;
uint8_t backlight_level = 0;
uint8_t backlight_level_edit = 0;
uint8_t fan_level = 0;
uint8_t fan_level_edit = 0;
uint16_t log_interval = 0;
uint16_t log_interval_edit = 0;
uint8_t bl_value[7] = {10, 25, 50, 75, 100, 125, 150};
uint8_t fan_value[7] = {0, 50, 75, 100, 125, 150, 175};
uint16_t log_value[7] = {0, 5, 10, 50, 100, 500, 1000};
uint32_t serial_value[10] = {9600, 19200, 38400, 57600, 115200, 230400, 460800, 500000, 576000, 921600};
uint32_t serial_baud = 0;
Expand Down

0 comments on commit f91d845

Please sign in to comment.