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

Restore master branch back to original content #1

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Update Functions.ino
avandalen authored Aug 24, 2017
commit 2160ef9623129734a14df62cd536bfcd8670777b
247 changes: 116 additions & 131 deletions Functions.ino
Original file line number Diff line number Diff line change
@@ -1,137 +1,122 @@
void weldControlNoTFT()
{ if(continuously && BCDswitch()==0) weld(weldButton.on()); // continuous welding
else
if(weldButton.pushed()) weldCyclus(BCDswitch() * step_ms);
}

void weldControlTFT()
{ //if(continuously && BCDswitch()==0) weld(weldButton.on());
if(continuously)
{
weld(weldButton.on());
}
else
if(weldButton.pushed()) weldCyclus(menuItems[2].upDownVal);
}

void weldCyclus(int weldTime_ms)
{ if(!sinMaxDisabled) sinusMax();
if(TFTused) menu.displayDot(1); // just once per weld cyclus
pulseWeld(menuItems[0].upDownVal);
delay(menuItems[1].upDownVal);
if(!sinMaxDisabled) sinusMax();
pulseWeld(weldTime_ms);
if(TFTused) menu.displayDot(0); // just once per weld cyclus
}

int BCDswitch()
{ int bcd;
bitWrite(bcd, 0, !digitalRead(BCDswitch0pin));
bitWrite(bcd, 1, !digitalRead(BCDswitch1pin));
bitWrite(bcd, 2, !digitalRead(BCDswitch2pin));
bitWrite(bcd, 3, !digitalRead(BCDswitch3pin));
return bcd;
}

void pulseWeld(int ms)
{ weld(1);
delay(ms);
weld(0);
if(printValuesToSerial) Serial << ms << endl;
}

void weld(bool b)
{
if (b)
menu.displayDot(1); // Indicates thyristors are on
void weldControlNoTFT()
{ if(continuously && BCDswitch()==0) weld(weldButton.on()); // continuous welding
else
menu.displayDot(0); // Indicates thyristors are off

if (b && !PrevWeld && !sinMaxDisabled) // If it is the first weld button press,
sinusMax(); // waits for voltage sinus max

digitalWrite(weldPin, b);
digitalWrite(ledPin, !b);
if(weldButton.pushed()) weldCyclus(BCDswitch() * step_ms);
}

void weldControlTFT()
{ if(continuously) weld(weldButton.on());
else
if(weldButton.pushed()) weldCyclus(menuItems[2].upDownVal);
}

void weldCyclus(int weldTime_ms)
{ if(!sinMaxDisabled) sinusMax();
pulseWeld(menuItems[0].upDownVal);
delay(menuItems[1].upDownVal);
if(!sinMaxDisabled) sinusMax();
pulseWeld(weldTime_ms);
}

int BCDswitch()
{ int bcd;
bitWrite(bcd, 0, !digitalRead(BCDswitch0pin));
bitWrite(bcd, 1, !digitalRead(BCDswitch1pin));
bitWrite(bcd, 2, !digitalRead(BCDswitch2pin));
bitWrite(bcd, 3, !digitalRead(BCDswitch3pin));
return bcd;
}

void pulseWeld(int ms)
{ weld(1);
delay(ms);
weld(0);
if(printValuesToSerial) Serial << ms << endl;
}

void weld(bool b)
{ if(b) menu.displayDot(1); // Indicates thyristors are on
else menu.displayDot(0); // Indicates thyristors are off
if (b && !PrevWeld && !sinMaxDisabled) sinusMax(); // If first weld button press, wait on sinus max
digitalWrite(weldPin, b);
digitalWrite(ledPin, !b);
PrevWeld = b;
}

void sinusMax()
{ while(digitalRead(zeroCrossPin));
while(!digitalRead(zeroCrossPin));
delayMicroseconds(sinusMax_us); // to prevent inrush current, turn-on at the sinus max
}

void blinkLed(int n)
{ pinMode(ledPin, OUTPUT);
for(byte i=0; i<n; i++)
{ digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
delay(200);
}
}

void setpinModes()
{ pinMode(BCDswitch0pin, INPUT_PULLUP);
pinMode(BCDswitch1pin, INPUT_PULLUP);
pinMode(BCDswitch2pin, INPUT_PULLUP);
pinMode(BCDswitch3pin, INPUT_PULLUP);
pinMode(weldButtonPin, INPUT_PULLUP);
pinMode(weldPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(zeroCrossPin, INPUT);
}

void pollAll()
{ weldButton.poll();
upButton.poll();
downButton.poll();
selectButton.poll();
}

void selectContinuously()
{ const unsigned long switchStable_ms = 200; // min = 50
const unsigned long weldButtonPressTime = 500; // push weldButton during 500ms at power up
unsigned long start_ms = millis();
pollAll();
delay(switchStable_ms);
int bcdswitch = BCDswitch();

while(weldButton.on())
{ pollAll();
if(!weldButton.on()) break;
}
if(millis()-start_ms > weldButtonPressTime) continuously = 1;
if(!TFTused) continuously &= bcdswitch==0; // bcdswitch has to be at position 0 too
}

void TFTinit()
{ tft.begin();
tft.setOrientation(eeprom.readInt(orientation));
tft.setFont(Terminal12x16);
}
}

void sinusMax()
{ while(digitalRead(zeroCrossPin));
while(!digitalRead(zeroCrossPin));
delayMicroseconds(sinusMax_us); // to prevent inrush current, turn-on at the sinus max
}

void blinkLed(int n)
{ pinMode(ledPin, OUTPUT);
for(byte i=0; i<n; i++)
{ digitalWrite(ledPin, HIGH);
delay(200);
digitalWrite(ledPin, LOW);
delay(200);
}
}

void setpinModes()
{ pinMode(BCDswitch0pin, INPUT_PULLUP);
pinMode(BCDswitch1pin, INPUT_PULLUP);
pinMode(BCDswitch2pin, INPUT_PULLUP);
pinMode(BCDswitch3pin, INPUT_PULLUP);
pinMode(weldButtonPin, INPUT_PULLUP);
pinMode(weldPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(zeroCrossPin, INPUT);
}

void pollAll()
{ weldButton.poll();
upButton.poll();
downButton.poll();
selectButton.poll();
}

void selectContinuously()
{ const unsigned long switchStable_ms = 200; // min = 50
const unsigned long weldButtonPressTime = 500; // push weldButton during 500ms at power up
unsigned long start_ms = millis();
pollAll();
delay(switchStable_ms);
int bcdswitch = BCDswitch();

while(weldButton.on())
{ pollAll();
if(!weldButton.on()) break;
}
if(millis()-start_ms > weldButtonPressTime) continuously = 1;
if(!TFTused) continuously &= bcdswitch==0; // bcdswitch has to be at position 0 too
}

void TFTinit()
{ tft.begin();
tft.setOrientation(eeprom.readInt(orientation));
tft.setFont(Terminal12x16);
}

// Detects if a PCB with or without LCD is being used
bool TFTusedJumper()
{ pinMode(tftJumperOutPin, OUTPUT); // Defines this pin as being an output
pinMode(tftJumperInPin, INPUT_PULLUP); // Defines this pin as being an input with a pull-up resistor
digitalWrite(tftJumperOutPin, 0);
return !digitalRead(tftJumperInPin); // no jumper = 1 (compatible with old software)
}

// Detects if old (no LCD) or new (with LCD) PCB is being used
bool TFTusedJumper()
{ pinMode(tftJumperOutPin, OUTPUT); // Defines this pin as bein an output
pinMode(tftJumperInPin, INPUT_PULLUP); // Defines this pin as being an input with a pull-up resistor
digitalWrite(tftJumperOutPin, 0);
return !digitalRead(tftJumperInPin); // no jumper = 1 (compatible with old software)
}

void printValuesToSerial()
{ Serial << "\npreweld " << menuItems[0].upDownVal << "ms, pause " << menuItems[1].upDownVal << "ms, weldTime "
<< menuItems[2].upDownVal << "ms, continuously " << continuously << endl;
}
void printValuesToSerial()
{ Serial << "\npreweld " << menuItems[0].upDownVal << "ms, pause " << menuItems[1].upDownVal << "ms, weldTime "
<< menuItems[2].upDownVal << "ms, continuously " << continuously << endl;
}

// LCD Orientation can only be either 0 or 2
void setOrientation()
{ pollAll(); // works without too
if(upButton.on() && downButton.on())
{ if(eeprom.readInt(orientation)==0) eeprom.writeInt(orientation, 2);
else eeprom.writeInt(orientation, 0);
}
}

void setOrientation()
{ pollAll(); // works without too
if(upButton.on() && downButton.on())
{ if(eeprom.readInt(orientation)==0) eeprom.writeInt(orientation, 2); // LCD Orientation can only be either 0 or 2
else eeprom.writeInt(orientation, 0);
}
}