Skip to content

Commit

Permalink
Merge pull request #653 from visualapproach/development_v4
Browse files Browse the repository at this point in the history
Development v4
  • Loading branch information
visualapproach authored Nov 19, 2023
2 parents 2ac558e + a18bfab commit c3300ee
Show file tree
Hide file tree
Showing 39 changed files with 536 additions and 276 deletions.
7 changes: 4 additions & 3 deletions Code/data/hwtestinfo.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@
</div>

<section>
<p>Connect the cables to together. Do not connect USB.</p>
<p>Prepare to connect the cables to together, but don't do it yet.</p>
<img src="hwtest2.jpg" width="300">
<br>
<p>Feed +5V and GND to the PCB (red and black wires in the picture)</p>
<p>Feed +5V and GND to the PCB (red and black wires in the picture). If your board bypasses the 5V from USB to Vin pin you can use USB instead. Don't use both methods!</p>
<img src="hwtest1.jpg" width="300">
<br>
<br><br>After clicking on the link below you will get the instruction to connect the cables.<br>
<p></p><a href="./hwtest/">Make the test</a></p>

</section>
</div>

Expand Down
1 change: 1 addition & 0 deletions Code/lib/BWC_unified/FW_VERSION.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define FW_VERSION "2023-11-19-1330"
77 changes: 51 additions & 26 deletions Code/lib/BWC_unified/bwc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ void BWC::on_scroll_text()
}

void BWC::setup(void){
if(cio != nullptr) delete cio;
if(dsp != nullptr) delete dsp;
Models ciomodel;
Models dspmodel;

Expand Down Expand Up @@ -176,16 +178,17 @@ void BWC::loop(){
dsp->text.remove(0,1);
_scroll = false;
}
cio->updateStates();
dsp->dsp_states = cio->cio_states;
cio->updateStates(); //checking serial line
dsp->dsp_states = cio->cio_states; //

/*Modify and use dsp->dsp_states here if we want to show text or something*/
dsp->setRawPayload(cio->getRawPayload());
dsp->setSerialReceived(cio->getSerialReceived());
/*Increase screen brightness when pressing buttons*/
adjust_brightness();
dsp->handleStates();

dsp->updateToggles();
dsp->handleStates(); //transmits to dsp if serial received from cio
dsp->updateToggles(); //checking serial line
cio->cio_toggles = dsp->dsp_toggles;

play_sound();
Expand All @@ -202,9 +205,11 @@ void BWC::loop(){

/*following method will change target temp and set _dsp_tgt_used to false if target temp is changed*/
_handleCommandQ();

/*If new target was not set above, use whatever the cio says*/
cio->setRawPayload(dsp->getRawPayload());
cio->handleToggles();
cio->setSerialReceived(dsp->getSerialReceived());
cio->handleToggles(); //transmits to cio if serial received from dsp

if(_save_settings_needed) saveSettings();
if(_save_cmdq_needed) _saveCommandQueue();
Expand All @@ -221,11 +226,18 @@ void BWC::_log()
static uint32_t writes = 0;
static std::vector<uint8_t> prev_fromcio;
static std::vector<uint8_t> prev_fromdsp;
static std::vector<uint8_t> prev_tocio;
static std::vector<uint8_t> prev_todsp;
std::vector<uint8_t> fromcio = cio->getRawPayload();
std::vector<uint8_t> fromdsp = dsp->getRawPayload();
if((fromcio == prev_fromcio) && (fromdsp == prev_fromdsp)) return;
std::vector<uint8_t> tocio = cio->_raw_payload_to_cio;
std::vector<uint8_t> todsp = dsp->_raw_payload_to_dsp;

if((fromcio == prev_fromcio) && (fromdsp == prev_fromdsp) && (tocio == prev_tocio) && (todsp == prev_todsp)) return;
prev_fromcio = fromcio;
prev_fromdsp = fromdsp;
prev_tocio = tocio;
prev_todsp = todsp;

File file = LittleFS.open(F("log.txt"), "a");
if (!file) {
Expand All @@ -234,19 +246,31 @@ void BWC::_log()
}
if(++writes > 1000) return;
file.print(_timestamp_secs);
file.print(':');
file.printf_P(PSTR("SW:%s CIO-ESP:"), FW_VERSION);
for(unsigned int i = 0; i< fromcio.size(); i++)
{
if(i>0)file.print(",");
if(i>0)file.print(',');
file.print(fromcio[i], HEX);
}
file.print('\t');
file.print(F("\t DSP-ESP:"));
for(unsigned int i = 0; i< fromdsp.size(); i++)
{
file.print(",");
if(i>0)file.print(',');
file.print(fromdsp[i], HEX);
}
file.print('\n');
file.print(F(" ESP-CIO:"));
for(unsigned int i = 0; i< tocio.size(); i++)
{
if(i>0)file.print(',');
file.print(tocio[i], HEX);
}
file.print(F("\t ESP-DSP:"));
for(unsigned int i = 0; i< todsp.size(); i++)
{
if(i>0)file.print(',');
file.print(todsp[i], HEX);
}
file.printf_P(PSTR("\ncio msg count: %d dsp msg count: %d\n"), cio->good_packets_count, dsp->good_packets_count);
file.close();
}

Expand Down Expand Up @@ -301,19 +325,19 @@ void BWC::stop(){
_save_settings_ticker.detach();
_scroll_text_ticker.detach();
if(cio != nullptr){
Serial.println(F("stopping cio"));
cio->stop();
Serial.println(F("del cio"));
delete cio;
cio = nullptr;
Serial.println(F("stopping cio"));
cio->stop();
Serial.println(F("del cio"));
delete cio;
cio = nullptr;
}
if(dsp != nullptr)
{
Serial.println(F("stopping dsp"));
dsp->stop();
Serial.println(F("del dsp"));
delete dsp;
dsp = nullptr;
Serial.println(F("stopping dsp"));
dsp->stop();
Serial.println(F("del dsp"));
delete dsp;
dsp = nullptr;
}
}

Expand All @@ -328,8 +352,10 @@ void BWC::pause_all(bool action)
_save_settings_ticker.attach(3600.0f, save_settings_cb, this);
_scroll_text_ticker.attach(0.25f, scroll_text_cb, this);
}
cio->pause_all(action);
dsp->pause_all(action);
if(cio != nullptr)
cio->pause_all(action);
if(dsp != nullptr)
dsp->pause_all(action);
}

/*Sort by xtime, ascending*/
Expand Down Expand Up @@ -1312,7 +1338,6 @@ void BWC::_restoreStates() {

void BWC::reloadCommandQueue(){
loadCommandQueue();
return;
}

void BWC::loadCommandQueue(){
Expand Down Expand Up @@ -1415,10 +1440,10 @@ void BWC::_saveCommandQueue(){
#endif
File file = LittleFS.open(F("cmdq.json"), "w");
if (!file) {
// Serial.println(F("Failed to save cmdq.json"));
Serial.println(F("Failed to save cmdq.json"));
return;
} else {
// Serial.println(F("Wrote cmdq.json"));
Serial.println(F("Wrote cmdq.json"));
}
/*Do not save instant reboot command. Don't ask me how I know.*/
if(_command_que.size())
Expand Down
58 changes: 30 additions & 28 deletions Code/lib/BWC_unified/bwc.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
#include "DSP_54138.h"
#include "DSP_54123.h"

#include "FW_VERSION.h"

constexpr int MAXCOMMANDS = 20;

struct command_que_item
{
Commands cmd;
int64_t val;
uint64_t xtime;
Commands cmd;
uint32_t interval;
String text = "";
};
Expand Down Expand Up @@ -92,16 +94,16 @@ class BWC {
// String getDebugData();

public:
String reboot_time_str;
time_t reboot_time_t;
String reboot_time_str;
int pins[8];
int tempSensorPin;
unsigned int loop_count = 0;
CIO* cio = nullptr;
DSP* dsp = nullptr;
bool hasjets, hasgod;
CIO* cio;
DSP* dsp;
bool BWC_DEBUG = false;
bool hasTempSensor = false;
int tempSensorPin;

private:
bool _loadHardware(Models& cioNo, Models& dspNo, int pins[]);
Expand Down Expand Up @@ -129,17 +131,15 @@ class BWC {
void _log();

private:
bool _notify;
int _notification_time, _next_notification_time;
uint64_t _timestamp_secs; // seconds
double _energy_daily_Ws; //Wattseconds internally
unsigned long _temp_change_timestamp_ms, _heatred_change_timestamp_ms;
unsigned long _pump_change_timestamp_ms, _bubbles_change_timestamp_ms;
Ticker _save_settings_ticker;
Ticker _scroll_text_ticker;
bool _scroll = false;
uint64_t _timestamp_secs; // seconds
uint8_t _dsp_brightness;
int16_t _override_dsp_brt_timer;
std::vector<command_que_item> _command_que;
std::vector<sNote> _notes;
int _note_duration;
sStates _prev_cio_states, _prev_dsp_states;
uint32_t _cl_timestamp_s;
uint32_t _filter_timestamp_s;
uint32_t _uptime;
Expand All @@ -152,33 +152,35 @@ class BWC {
uint32_t _heatingtime_ms;
uint32_t _airtime_ms;
uint32_t _jettime_ms;
float _price;
uint32_t _filter_interval;
uint32_t _cl_interval;
bool _audio_enabled;
float _energy_total_kWh;
double _energy_daily_Ws; //Wattseconds internally
uint32_t _virtual_temp_fix_age;
int _note_duration;
int _notification_time, _next_notification_time;
int _energy_power_W;
bool _restore_states_on_start = false;
bool _save_settings_needed = false;
bool _save_cmdq_needed = false;
bool _save_states_needed = false;
int _ticker_count;
int _btn_sequence[4] = {NOBTN,NOBTN,NOBTN,NOBTN}; //keep track of the four latest button presses
float _R_COOLING = 40;
int _ambient_temp; //always in C internally
int _deltatemp;
float _price;
float _energy_total_kWh;
float _R_COOLING = 40;
float _heating_degperhour = 1.5; //always in C internally
float _virtual_temp; //=virtualtempfix+calculated diff, always in C internally
float _virtual_temp_fix; //last fixed data point to add or subtract temp from, always in C internally
uint32_t _virtual_temp_fix_age;
Buttons _prevbutton = NOBTN;
int16_t _override_dsp_brt_timer;
uint8_t _dsp_brightness;
uint8_t _web_target = 20;
bool _scroll = false;
bool _audio_enabled;
bool _restore_states_on_start = false;
bool _save_settings_needed = false;
bool _save_cmdq_needed = false;
bool _save_states_needed = false;
bool _new_data_available = false;
bool _dsp_tgt_used = true;
uint8_t _web_target = 20;
sStates _prev_cio_states, _prev_dsp_states;
Buttons _prevbutton = NOBTN;
unsigned long _temp_change_timestamp_ms, _heatred_change_timestamp_ms;
unsigned long _pump_change_timestamp_ms, _bubbles_change_timestamp_ms;
int _deltatemp;
bool _notify;
bool _vt_calibrated = false;
};

Expand Down
14 changes: 7 additions & 7 deletions Code/lib/BWC_unified/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ struct sStates
uint8_t timerled2 = 0;
uint8_t timerbuttonled = 0;
uint8_t brightness = 8;
bool gettarget = false;
// bool fullpower = false;
uint8_t no_of_heater_elements_on = 2;
bool gettarget = false;
bool godmode = false;

// String toString()
Expand Down Expand Up @@ -185,6 +185,9 @@ struct sStates

struct sToggles
{
Buttons pressed_button = NOBTN;
uint8_t target = 20;
uint8_t no_of_heater_elements_on = 2;
bool locked_pressed = 0;
bool power_change = 0;
bool unit_change = 0;
Expand All @@ -195,13 +198,10 @@ struct sToggles
bool timer_pressed = 0;
bool up_pressed = 0;
bool down_pressed = 0;
Buttons pressed_button = NOBTN;
/*Requested state, not toggled*/
bool godmode = false;
/*Requested state, not toggled*/
uint8_t target = 20;
/*Requested state, not toggled*/
uint8_t no_of_heater_elements_on = 2;

// String toString()
// {
Expand Down Expand Up @@ -238,15 +238,15 @@ struct sNote

struct sWifi_info
{
bool enableAp;
bool enableWmApFallback = true;
String apSsid;
String apPwd;
bool enableStaticIp4 = false;
String ip4Address_str;
String ip4Gateway_str;
String ip4Subnet_str;
String ip4DnsPrimary_str;
String ip4DnsSecondary_str;
String ip4NTP_str;
bool enableAp;
bool enableWmApFallback = true;
bool enableStaticIp4 = false;
};
Loading

0 comments on commit c3300ee

Please sign in to comment.