Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #5

Merged
merged 6 commits into from
Jan 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/PulseWelder/lib/INA219/INA219.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/******************************************************************************
* Sept-17-2019: Minor edits by T. Black.
* Sep-17-2019: Minor edits by thomastech for Sparky Welding Project.
* Jan-14-2020: Improved response time, by hogthrob for Sparky Welding Project.
* Added arduino.h to supress _delay() warnings.
* Fixed math in INA219::calibrate() to support shunt values less than 0.001 ohms.
*
Expand Down
1 change: 1 addition & 0 deletions src/PulseWelder/lib/INA219/INA219.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* http://www.ti.com/product/ina219
*
* 6 May 2012 by John De Cristofaro
* Jan-14-2020: Improved response time, by hogthrob for Sparky Welding Project.
*
*
* Tested at standard i2c 100kbps signaling rate.
Expand Down
10 changes: 8 additions & 2 deletions src/PulseWelder/src/PulseWelder.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
File: PulseWelder.cpp
Project: ZX7-200 MMA Stick Welder Controller with Pulse Mode.
Version: 1.1
Version: 1.2
Creation: Sep-11-2019
Revised: Dec-29-2019.
Public Release: Jan-03-2020
Expand Down Expand Up @@ -44,6 +44,12 @@
Lift PIN-10 on SG3525A PWM Controller IC. Connect lifted pin to ESP32's SHDN_PIN (default is ESP32 GPIO-15).
PWM Shutdown feature must be enabled in config.h (via PWM_ARC_CTRL define).
- Added hogthrob's checkAndUpdateEEPROM() function & IS_IN_BOX() macro to streamline screen.cpp code.
V1.2, Jan-14-2020:
- Incorporated hogthrob's PR #5:
No functional changes, maintanence only.
Updated INA219 library, improved response time.
Removed monitor port directive from platformio.ini.
Sound and Screen Handling refactoring.

Notes:
1. This "Arduino" project must be compiled with VSCode / Platformio. Do not use the Arduino IDE.
Expand Down Expand Up @@ -232,7 +238,7 @@ void setup()

// Welcome the user with a promotional voice message.
spkr.play(promoMsg);

// Done with initialization. Show Home Page or Hardware Error Page.
if (systemError == ERROR_NONE) { // Hardware is OK.
drawHomePage();
Expand Down
10 changes: 5 additions & 5 deletions src/PulseWelder/src/PulseWelder.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
File: PulseWelder.h
Project: ZX7-200 MMA Stick Welder Controller with Pulse Mode.
Version: 1.1
Version: 1.2
Creation: Sep-11-2019
Revised: Dec-29-2019
Public Release: Jan-03-2020
Revised: Jan-14-2020
Public Release: Jan-15-2020
Revision History: See PulseWelder.cpp
Project Leader: T. Black (thomastech)
Contributors: thomastech, hogthrob
Expand All @@ -18,8 +18,8 @@
#include "BLEDevice.h"

// *********************************************************************************************
// VERSION STRING: Must be updated with each release! The version is shown on the boot screen.
#define VERSION_STR "V1.1"
// VERSION STRING: Must be updated with each public release! The version is shown on the boot screen.
#define VERSION_STR "V1.2"

// *********************************************************************************************
// GPIO Pin Definitions
Expand Down
23 changes: 16 additions & 7 deletions src/PulseWelder/src/misc.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
File: misc.cpp
Project: ZX7-200 MMA Stick Welder Controller with Pulse Mode.
Version: 1.1
Version: 1.2
Creation: Sep-11-2019
Revised: Dec-29-2019.
Public Release: Jan-03-2020
Revised: Jan-14-2020
Public Release: Jan-15-2020
Revision History: See PulseWelder.cpp
Project Leader: T. Black (thomastech)
Contributors: thomastech, hogthrob
Expand Down Expand Up @@ -140,6 +140,7 @@ int getFobClick(bool rst)
void remoteControl(void)
{
int click = CLICK_NONE;
int amps1, amps10, amps100;

processFobClick(); // Update button detection status on BLE FOB.
click = getFobClick(true); // Get Button Click value.
Expand All @@ -152,40 +153,48 @@ void remoteControl(void)
}

if(overTempAlert){
if(overHeatMsg.Playing==false) {
spkr.stopSounds(); // Override existing announcement.
}
spkr.playToEnd(overHeatMsg);
Serial.println("Announce: Alarm");
}
else if(arcSwitch != ARC_ON) {
arcSwitch = ARC_ON;
drawHomePage();
spkr.addSoundList({&silence100ms, &ding, &beep, &silence100ms, &currentOnMsg});
spkr.playSoundList();
Serial.println("Announce: Arc Current Turned On.");
}
else {
int changeVal = 0;
if (click == CLICK_SINGLE) {
changeVal = REMOTE_AMP_CHG;
}
else if (click == CLICK_DOUBLE) {
else if (click == CLICK_DOUBLE) {
changeVal = -REMOTE_AMP_CHG;
}

byte newSetAmps = constrain((int)setAmps + changeVal, MIN_SET_AMPS, MAX_SET_AMPS);
// explicitly cast setAmps to int in order to handle going into negative amps when subtracting changeVal
// gracefully.
// gracefully.

if (setAmps != newSetAmps) {
setAmps = newSetAmps;
spkr.addSoundList({(setAmps < newSetAmps) ? &increaseMsg : &decreaseMsg});
Serial.print(setAmps < newSetAmps ? "Announce: Increase ": "Announce: Decrease ");
setAmps = newSetAmps;
}
else {
Serial.print("Announce <no change>: ");
}

amps100 = setAmps / 100;
amps10 = (setAmps - amps100 * 100) / 10;
amps1 = setAmps - (amps100 * 100 + amps10 * 10);
Serial.println(String(setAmps / 100) + "-" + String((setAmps - amps100 * 100) / 10) + "-" + String(amps1));

setPotAmps(setAmps, VERBOSE_ON); // Refresh Digital Pot.
spkr.addDigitSounds(setAmps);

spkr.playSoundList();
}
}
Expand Down
51 changes: 26 additions & 25 deletions src/PulseWelder/src/screen.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
File: screen.cpp
Project: ZX7-200 MMA Stick Welder Controller with Pulse Mode.
Version: 1.1
Version: 1.2
Creation: Sep-11-2019
Revised: Dec-29-2019.
Public Release: Jan-03-2020
Revised: Jan-14-2020.
Public Release: Jan-15-2020
Revision History: See PulseWelder.cpp
Project Leader: T. Black (thomastech)
Contributors: thomastech, hogthrob
Expand Down Expand Up @@ -48,7 +48,7 @@ static char StringBuff[32]; // General purpose Char Buffer
static bool eepromActive = false; // EEProm Write Requested.
static int page = PG_HOME; // Current Menu Page.
static int x, y; // Screen's Touch coordinates.
static long abortMillis = 0; // Info Page Abort Timer, in mS.
static long abortMillis = 0; // Info Page Abort Timer, in mS.
static long previousEepMillis = 0; // Previous Home Page time.

#define COORD(BOXNAME) BOXNAME ## _X , BOXNAME ## _Y , BOXNAME ## _W , BOXNAME ## _H
Expand Down Expand Up @@ -116,13 +116,13 @@ bool adjustPulseFreq(bool direction)

// Check for out of bounds values. Constrain in necessary.
byte constrainedPulseFreqX10 = constrain(pulseFreqX10, MIN_PULSE_FRQ_X10, MAX_PULSE_FRQ_X10);

limitHit = constrainedPulseFreqX10 != pulseFreqX10;
// if constrained freq is not equal original frequency we are out of bounds

pulseFreqX10 = constrainedPulseFreqX10;
// always use constrained frequency

// Refresh the Pulse Entry display (if on page PG_SET)
drawPulseHzSettings(true);

Expand Down Expand Up @@ -212,11 +212,11 @@ void getTouchPoints(void)
Serial.println("[Touch Coordinates] X: " + String(x) + " Y:" + String(y));
}

void drawCenteredText(int x, int y, int w, int h, String label, uint32_t bgcolor)
void drawCenteredText(int x, int y, int w, int h, String label, uint32_t bgcolor)
{
int16_t lx,ly;
uint16_t lw, lh;

// calculate text length
tft.getTextBounds(label, x , y , &lx, &ly, &lw, &lh);
int nxd = (w - lw)/2; // calculate offset from left margin to print label centered
Expand All @@ -226,13 +226,13 @@ void drawCenteredText(int x, int y, int w, int h, String label, uint32_t bgcolor
tft.println(label);
}

void drawBasicButton(int x, int y, int w, int h, uint color)
void drawBasicButton(int x, int y, int w, int h, uint color)
{
tft.drawRoundRect(x - 2, y - 4, w+4, h + 8, 5, color);
tft.drawRoundRect(x - 1, y - 3, w+2, h + 6, 5, color);
}

void drawPlusMinusButtons(int x, int y, int w, int h, String label, bool update_only)
void drawPlusMinusButtons(int x, int y, int w, int h, String label, bool update_only)
{
tft.setFont(&FreeSansBold12pt7b);
tft.setTextSize(1);
Expand Down Expand Up @@ -774,7 +774,7 @@ void displayAmps(bool forceRefresh)
oldAmps = Amps;
}
}
else
else
{
oldAmps = -1; // Force burn current refresh on next rod burn.

Expand Down Expand Up @@ -879,6 +879,7 @@ void displayOverTempAlert(void)
detFlag = true;
Serial.println("Warning: Over-Temperature has been detected!");
drawOverTempAlert();
spkr.stopSounds(); // Override existing announcement.
spkr.playToEnd(overHeatMsg);
// Don't interrupt a over-heat alarm message playback.
}
Expand Down Expand Up @@ -982,13 +983,13 @@ void drawSubPage(String title, int pg, uint32_t bgColor, uint32_t marginColor) {
void drawInfoPage(void)
{
drawSubPage("ROD INFORMATION", PG_INFO, ILI9341_BLACK, ILI9341_WHITE);

tft.setFont(&FreeSans12pt7b);
tft.setTextSize(1);
tft.setTextColor(ILI9341_YELLOW);

tft.drawRoundRect(43, 60, 234, 50, 8, WHITE);

tft.drawRoundRect(44, 61, 232, 48, 8, WHITE);
tft.fillRoundRect(45, 62, 230, 46, 8, 0x2A86);
tft.setCursor(120, 93);
Expand Down Expand Up @@ -1034,7 +1035,7 @@ void drawInfoPageRod(int pageNum, const char* rodName, const char* mainInfo[4],
// *********************************************************************************************
// Information page for 6011 rod.
void drawInfoPage6011(void) {
const char* mainInfo[4] = {
const char* mainInfo[4] = {
"3/32\" 2.4mm 40-90A",
"1/8\" 3.2mm 75-125A",
"5/32\" 4.0mm 110-165A",
Expand All @@ -1052,7 +1053,7 @@ void drawInfoPage6011(void) {
// *********************************************************************************************
// Information page for 6013 rod.
void drawInfoPage6013(void) {
const char* mainInfo[4] = {
const char* mainInfo[4] = {
"1/16\" 1.6mm 20-45A",
"3/32\" 2.4mm 40-90A",
"1/8\" 3.2mm 80-130A",
Expand All @@ -1069,7 +1070,7 @@ void drawInfoPage6013(void) {

// Information page for 7018 rod.
void drawInfoPage7018(void) {
const char* mainInfo[4] = {
const char* mainInfo[4] = {
"3/32\" 2.4mm 70-120A",
"1/8\" 3.2mm 110-165A",
"5/32\" 4.0mm 150-220A",
Expand All @@ -1096,8 +1097,8 @@ void drawCaution(int x, int y, bool state)
}
else {
switch(page) {
case PG_HOME:
color = arcSwitch == ARC_ON ? ARC_BG_COLOR : ILI9341_BLUE;
case PG_HOME:
color = arcSwitch == ARC_ON ? ARC_BG_COLOR : ILI9341_BLUE;
break;
case PG_INFO:
case PG_INFO_6011:
Expand All @@ -1109,7 +1110,7 @@ void drawCaution(int x, int y, bool state)
color = ILI9341_RED;
break;
default:
color = ILI9341_WHITE;
color = ILI9341_WHITE;
}
}

Expand Down Expand Up @@ -1188,7 +1189,7 @@ void drawHomePage()

unsigned int color = arcSwitch == ARC_ON ? ARC_BG_COLOR : ILI9341_BLUE;
drawPageFrame(color, ILI9341_CYAN);

drawAmpsBox();
displayOverTempAlert(); // Display temperature warning if too hot.

Expand Down Expand Up @@ -1386,12 +1387,12 @@ void showBleStatus(int msgNumber)

tft.setFont(&FreeSansBold12pt7b);
tft.setTextSize(1);
tft.setTextColor(color);
tft.setTextColor(color);
drawCenteredText(COORD(FBBOX), label, ILI9341_WHITE);

// Update Bluetooth On/Off Switch button
tft.drawBitmap(FBBOX_X + FBBOX_W + 17, FBBOX_Y, PowerSwBitmap, 40, 40, bleSwitch == BLE_OFF ? ILI9341_RED : ILI9341_GREEN);

}

// *********************************************************************************************
Expand Down Expand Up @@ -1431,7 +1432,7 @@ void updateVolumeIcon(void)

if (spkrVolSwitch >= VOL_MED) {
fillArc(SNDBOX_X + 8, SNDBOX_Y + 25, 62, 8, 25, 25, 2, ILI9341_WHITE); // 1st Short arc

if ((spkrVolSwitch >= VOL_HI) && (spkrVolSwitch < XHI_VOL)) { // Audio High
fillArc(SNDBOX_X + 18, SNDBOX_Y + 25, 56, 10, 25, 25, 2, ILI9341_WHITE); // 2nd Short arc
}
Expand Down
6 changes: 3 additions & 3 deletions src/PulseWelder/src/screen.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
File: screen.h
Project: ZX7-200 MMA Stick Welder Controller with Pulse Mode.
Version: 1.1
Version: 1.2
Creation: Sep-11-2019
Revised: Dec-29-2019.
Public Release: Jan-03-2020
Revised: Jan-14-2020.
Public Release: Jan-15-2020
Revision History: See PulseWelder.cpp
Project Leader: T. Black (thomastech)
Contributors: thomastech, hogthrob
Expand Down
21 changes: 11 additions & 10 deletions src/PulseWelder/src/speaker.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
File: speaker.cpp
Project: ZX7-200 MMA Stick Welder Controller with Pulse Mode.
Version: 1.1
Creation: Jan-15-2020
Revised:
Public Release:
Version: 1.2
Creation: Jan-14-2020
Revised: Jan-14-2020
Public Release: Jan-15-2020
Revision History: See PulseWelder.cpp
Project Leader: T. Black (thomastech)
Contributors: thomastech, hogthrob
Expand Down Expand Up @@ -56,7 +56,7 @@ Speaker::Speaker() {
promoMsg.Volume = 127; // Maximum Sub-Volume (0-127 allowed).
Sequence.Volume = 127; // Maximum sub-volume.
Sequence.Repeat = 0; // Don't Repeat.

}
void Speaker::stopSounds() {
DacAudio.StopAllSounds();
Expand Down Expand Up @@ -124,13 +124,13 @@ void Speaker::limitHit(XT_PlayListItem_Class& sound, boolean condition) {
}

// *********************************************************************************************
// Add the wav file item for the 0-9 number passed by calller
// Add the wav file item for the 0-9 number passed by caller
static void AddNumberToSequence(int theNumber) {
static XT_Wav_Class* digit[10] = { &n000, &n001, &n002, &n003, &n004, &n005, &n006, &n007, &n008, &n009 };
Sequence.AddPlayItem( (theNumber < 10 && theNumber >= 0) ? digit[theNumber] : &silence100ms );
}

void Speaker::addDigitSounds(uint32_t val) {
void Speaker::addDigitSounds(uint32_t val) {
if (spkrVolSwitch != VOL_OFF) {
const int max_num_digits = 10; // 32 bits == 10 base10 digits max.
uint32_t digits[max_num_digits];
Expand All @@ -140,9 +140,10 @@ void Speaker::addDigitSounds(uint32_t val) {
val /= 10; // shift to next digit
}
if (count == 0) { count = 1; digits[0] = 0; }
// special case for value == 0

for (; count; count-- ) { AddNumberToSequence(digits[count]); }
// special case for value == 0
for (; count; count-- ) {
AddNumberToSequence(digits[count-1]);
thomastech marked this conversation as resolved.
Show resolved Hide resolved
}
DacAudio.Play(&Sequence, true);
}
}
Expand Down
Loading