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 all commits
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
15 changes: 10 additions & 5 deletions 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 Expand Up @@ -42,7 +43,7 @@
#include <Arduino.h>


INA219::INA219() {
INA219::INA219(): last_addr(-1) {
}


Expand All @@ -51,6 +52,7 @@ void INA219::begin(uint8_t addr)
Wire.begin();
i2c_address = addr;
gain = D_GAIN;
last_addr = -1;
}


Expand Down Expand Up @@ -118,6 +120,7 @@ void INA219::configure(uint8_t range, uint8_t gain, uint8_t bus_adc, uint8_t shu
void INA219::reset()
{
write16(CONFIG_R, INA_RESET);
last_addr = -1;
delay(2); // Now using Arduino library mS delay. Mod by TEB, Sep-17-2019.
}

Expand Down Expand Up @@ -174,6 +177,7 @@ void INA219::write16(uint8_t a, uint16_t d) {
temp = (uint8_t)d;
d >>= 8;
Wire.beginTransmission(i2c_address); // start transmission to device
last_addr = a;

#if ARDUINO >= 100
Wire.write(a); // sends register address to read from
Expand All @@ -186,15 +190,16 @@ void INA219::write16(uint8_t a, uint16_t d) {
#endif

Wire.endTransmission(); // end transmission
delay(1);
}


int16_t INA219::read16(uint8_t a) {
uint16_t ret;

// move the pointer to reg. of interest, null argument
write16(a, 0);
if (last_addr != a) {
// move the pointer to reg. of interest, null argument
write16(a, 0);
}

Wire.requestFrom((int)i2c_address, 2); // request 2 data bytes

Expand Down
3 changes: 3 additions & 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 Expand Up @@ -120,6 +121,8 @@ class INA219
int16_t read16(uint8_t addr);
void write16(uint8_t addr, uint16_t data);

int last_addr;

};

#endif
1 change: 0 additions & 1 deletion src/PulseWelder/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ platform = espressif32@>=1.11.1
framework = arduino
board = lolin_d32_pro
monitor_speed = 115200
monitor_port = COM[4]
upload_speed = 921600
board_build.f_cpu = 160000000L
board_upload.flash_size = 16MB
Expand Down
31 changes: 14 additions & 17 deletions src/PulseWelder/src/PulseWelder.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
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
Revised: Jan-14-2020
Public Release: Jan-15-2020
Project Leader: T. Black (thomastech)
Contributors: thomastech, hogthrob

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 All @@ -62,11 +68,10 @@
#include <WiFi.h>
#include "INA219.h"
#include "PulseWelder.h"
#include "XT_DAC_Audio.h"
#include "dacAudio.h"
#include "screen.h"
#include "digPot.h"
#include "config.h"
#include "speaker.h"

// INA219 Current Sensor
INA219 ina219;
Expand Down Expand Up @@ -226,21 +231,13 @@ void setup()
// attachInterrupt(interruptPin, isr, FALLING);

// Initialize Audio Voice and tones.
promoMsg.Speed = 1.0; // Normal Playback Speed.
promoMsg.Volume = 127; // Maximum Sub-Volume (0-127 allowed).
DacAudio.DacVolume = spkrVolSwitch; // Set Master-Volume (0-100 allowed). This is a Menu setting.
DacAudio.Play(&beep, false); // Init audio, Beep user.
spkr.volume(spkrVolSwitch); // Set Master-Volume (0-100 allowed). This is a Menu setting.
spkr.playToEnd(beep); // Init audio, Beep user.

while (beep.TimeLeft) // Wait until beep tone has finished playing.
{
DacAudio.FillBuffer();
}
Serial.println("Initialized Audio Playback System.");

// Welcome the user with a promotional voice message.
if (spkrVolSwitch != VOL_OFF) {
DacAudio.Play(&promoMsg, true);
}
spkr.play(promoMsg);

// Done with initialization. Show Home Page or Hardware Error Page.
if (systemError == ERROR_NONE) { // Hardware is OK.
Expand Down Expand Up @@ -290,7 +287,7 @@ void loop()
}

// Background tasks
DacAudio.FillBuffer(); // Fill the sound buffer with data.
spkr.fillBuffer(); // Fill the sound buffer with data.
showHeartbeat(); // Display Flashing Heartbeat icon.
checkForAlerts(); // Check for alert conditions.
processScreen(); // Process Menu System (touch screen).
Expand Down
27 changes: 18 additions & 9 deletions src/PulseWelder/src/PulseWelder.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
/*
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

(c) copyright T. Black 2019-2020, Licensed under GNU GPL 3.0 and later, under this license absolutely no warranty is given.
This Code was formatted with the uncrustify extension.
*/
#ifndef __PULSE_WELDER_H__
#define __PULSE_WELDER_H__

#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 Expand Up @@ -139,11 +141,17 @@
#define DOUBLE_CLICK_TIME 750 // Bluetooth FOB Button Click Timer, in mS.
#define EEP_DELAY_TIME 3500 // Delay Time before writing Volume value to EEPROM.
#define HB_FLASH_TIME 500 // Heartbeat & LED FLASH Update Time, in mS.
#define MEAS_TIME 65 // Measurement Refresh Time, in mS. Must exceed INA219 conversion Time.
#define MEAS_TIME 5 // Measurement Refresh Time, in mS.
#define RECONNECT_DLY_TIME 20000 // Delay time before attempting a Bluetooth re-connect.
#define SPLASH_TIME 2500 // Timespan for showing Splash Screen at boot.

// *********************************************************************************************
enum StartMode {
SCRATCH_START,
LIFT_START
};

extern StartMode startMode;

// Amps & Volts Measurement Prototypes
void initVdcAdc(void);
Expand Down Expand Up @@ -199,8 +207,8 @@ void drawInfoPage6011(void);
void drawInfoPage6013(void);
void drawInfoPage7018(void);
void drawOverTempAlert(void);
void drawPulseAmpsSettings(void);
void drawPulseHzSettings(void);
void drawPulseAmpsSettings(bool update_only);
void drawPulseHzSettings(bool update_only);
void drawPulseIcon(void);
void drawPulseLightning(void);
void drawSettingsPage(void);
Expand All @@ -221,7 +229,6 @@ void fillArc(int x,
unsigned int color);

// Misc Prototypes
void AddNumberToSequence(int theNumber);
void controlArc(bool state,
bool verbose);
void disableArc(bool verbose);
Expand All @@ -232,8 +239,10 @@ void checkForAlerts(void);
float PulseFreqHz(void);
void pulseModulation(void);
void remoteControl(void);
void detectArcState(void);

// SPIFFS Prototypes
void spiffsInit(void);

#endif
// EOF
Loading