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
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
18 changes: 11 additions & 7 deletions Classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,20 @@ class MenuItem

class Menu
{ public:
void displayStart();
void control();
void displayAll();
void displayName(int itemNr, String &name);
void displayValue(int itemNr, int value, bool focus, bool background);
void displayDot(bool on);
void drawColorTextLine(int line, int left, String str, uint16_t color=COLOR_WHITE, uint16_t backgroundColor=COLOR_BLACK);

void TFTinit();
private:
bool editValue=0;
const int txtLeft = 17;
void displayName(int itemNr, String &name);
void displayValue(int itemNr, int value, bool focus, bool edit);
void drawColorTextLine(int line, int left, String str, uint16_t textColor=TFT_WHITE, uint16_t backgroundColor=TFT_BLACK); // line 0..8
void displayContinuously();

bool editValueMode=0;
const int textLeft = 20, fontSize=4, fontHeight=26;
const int vertOffset=3; // 240-9*26)/2
};

#endif
106 changes: 66 additions & 40 deletions Classes.ino
Original file line number Diff line number Diff line change
@@ -1,77 +1,91 @@
#include "Classes.h"
#include <Arduino.h>

void Menu::drawColorTextLine(int line, int left, String str, uint16_t color=COLOR_WHITE, uint16_t backgroundColor)
{ tft.fillRectangle(left, 20*line, 175, 20*line+19, backgroundColor); // line <= 10
tft.setBackgroundColor(backgroundColor);
tft.drawText(left, 20*line+2, str, color);
}

void Menu::control()
{ if(!editValue)
{ if(!editValueMode)
{ if(upButton.pushed())
{ menu.displayValue(upDownItemNr, menuItems[upDownItemNr].upDownVal, 0, editValue); // un-focus old item
menu.displayValue(upDownItemNr, menuItems[upDownItemNr.down()].upDownVal, 1, editValue); // focus
{ displayValue(WeldItemNr, menuItems[WeldItemNr].upDownVal, 0, editValueMode); // un-focus old item
displayValue(WeldItemNr, menuItems[WeldItemNr.down()].upDownVal, 1, editValueMode); // focus
return;
}
if(downButton.pushed())
{ menu.displayValue(upDownItemNr, menuItems[upDownItemNr].upDownVal, 0, editValue); // un-focus old item
menu.displayValue(upDownItemNr, menuItems[upDownItemNr.up()].upDownVal, 1, editValue); // focus
{ displayValue(WeldItemNr, menuItems[WeldItemNr].upDownVal, 0, editValueMode); // un-focus old item
displayValue(WeldItemNr, menuItems[WeldItemNr.up()].upDownVal, 1, editValueMode); // focus
return;
}
if(selectButton.pushed())
{ menu.displayValue(upDownItemNr, menuItems[upDownItemNr].upDownVal, 1, editValue=1); // add backgound
{ displayValue(WeldItemNr, menuItems[WeldItemNr].upDownVal, 1, editValueMode=1); // add backgound
return;
}
}
if(editValue)
}

if(editValueMode)
{ if(upButton.pushed())
{ menu.displayValue(upDownItemNr, menuItems[upDownItemNr].upDownVal.up(), 1, editValue);
{ displayValue(WeldItemNr, menuItems[WeldItemNr].upDownVal.up(), 1, editValueMode);
return;
}
if(downButton.pushed())
{ menu.displayValue(upDownItemNr, menuItems[upDownItemNr].upDownVal.down(), 1, editValue);
{ displayValue(WeldItemNr, menuItems[WeldItemNr].upDownVal.down(), 1, editValueMode);
return;
}
if(selectButton.pushed())
{ menu.displayValue(upDownItemNr, menuItems[upDownItemNr].upDownVal, 1, editValue=0); // delete backgound
{ displayValue(WeldItemNr, menuItems[WeldItemNr].upDownVal, 1, editValueMode=0); // delete backgound
eeprom.write();
return;
}
}
}

void Menu::displayAll()
{ if(!continuously)
void Menu::displayStart()
{ drawColorTextLine(0, textLeft, version, TFT_YELLOW);
delay(1000);
TFTinit();

if(!continuously)
{ for(int i=0; i<3; i++)
{ upDownItemNr.value=i;
displayName(upDownItemNr, menuItems[upDownItemNr].name);
menu.displayValue(upDownItemNr, menuItems[upDownItemNr].upDownVal, 0, 0);
}
upDownItemNr.value=0;
menu.displayValue(upDownItemNr, menuItems[upDownItemNr].upDownVal, 1, 0); // item 0 has focus
{ WeldItemNr.value=i;
displayName(WeldItemNr, menuItems[WeldItemNr].name);
displayValue(WeldItemNr, menuItems[WeldItemNr].upDownVal, 0, 0);
}
WeldItemNr.value = 0;
displayValue(WeldItemNr, menuItems[WeldItemNr].upDownVal, 1, 0); // item 0 has focus
displayDot(0);
drawColorTextLine(10, 0, "- + sel weld", COLOR_YELLOW, COLOR_BLUEVIOLET);
}
else
{ drawColorTextLine(4, 0, " Continuously", COLOR_WHITE, COLOR_RED);
drawColorTextLine(5, 0, " mode", COLOR_WHITE, COLOR_RED);
drawColorTextLine(6, 0, " Take care!", COLOR_WHITE, COLOR_RED);
drawColorTextLine(8, 0, " down up sel ", TFT_YELLOW, TFT_BLUE); // to long text is ok
}
else displayContinuously();
}

void Menu::displayContinuously()
{ tft.fillScreen(TFT_RED);
drawColorTextLine(2, 0, " Continuously", TFT_WHITE, TFT_RED);
drawColorTextLine(3, 0, " mode", TFT_WHITE, TFT_RED);
drawColorTextLine(4, 0, " Take care!", TFT_WHITE, TFT_RED);
displayDot(0);
}

void Menu::displayDot(bool on)
{ tft.fillCircle(87, 170, 12, on? COLOR_WHITE : COLOR_DARKBLUE);
{ tft.fillCircle(148, 180, 20, on? TFT_WHITE : 0x64A7/*green*/); // https://ee-programming-notepad.blogspot.nl/2016/10/16-bit-color-generator-picker.html
}

void Menu::displayName(int upDownItemNr, String &name)
{ drawColorTextLine(2*upDownItemNr, txtLeft, name, TXT_COLOR);
void Menu::drawColorTextLine(int line, int left, String str, uint16_t textColor, uint16_t backgroundColor)
{ tft.setTextColor(textColor, backgroundColor);
tft.drawString(str.c_str(), left, fontHeight*line+vertOffset, fontSize);
}

void Menu::displayValue(int upDownItemNr, int value, bool focus, bool background)
{ menu.drawColorTextLine(2*upDownItemNr+1, txtLeft, String(" ")); // clear line
menu.drawColorTextLine(2*upDownItemNr+1, 0, focus? ">" : " ", TXT_COLOR);
menu.drawColorTextLine(2*upDownItemNr+1, txtLeft, String(value), background? COLOR_BLACK : TXT_COLOR, background? COLOR_CYAN : COLOR_BLACK);
void Menu::displayName(int WeldItemNr, String &name)
{ drawColorTextLine(2*WeldItemNr, textLeft, name, TFT_YELLOW);
}

void Menu::displayValue(int WeldItemNr, int value, bool focus, bool edit)
{ drawColorTextLine(2*WeldItemNr+1, textLeft, " ", TFT_WHITE); // clear line, can't be BLACK (bug?)
drawColorTextLine(2*WeldItemNr+1, 0, ">", focus? TFT_WHITE : TFT_BLACK); // BLACK on BLACK = BLACK
drawColorTextLine(2*WeldItemNr+1, textLeft, String(value), edit? TFT_BLACK : TFT_WHITE, edit? TFT_CYAN : TFT_BLACK);
}

void Menu::TFTinit()
{ tft.init();
tft.setRotation(orientation);
tft.fillScreen(TFT_BLACK);
}

// ---------------------------------------------------------------------------
Expand All @@ -80,13 +94,15 @@ UpDownValue::UpDownValue(int value, int step, int minValue, int maxValue):
value(value), step(step), minValue(minValue), maxValue(maxValue)
{
}

int UpDownValue::up()
{ value += step;
return value = min(max(value, minValue), maxValue);
return value = (value > maxValue) ? minValue : value;
}

int UpDownValue::down()
{ value -= step;
return value = min(max(value, minValue), maxValue);
return value = (value < minValue ) ? maxValue : value;
}

UpDownValue::operator int() // conversion operator, object returns value
Expand All @@ -100,4 +116,14 @@ name(name), upDownVal(value)
{
}

/*
if(downButton.on() && selectButton.on())
{ preferencesControl();
return;
}

drawColorTextLine(2, textLeft, "Set preferences:", TFT_YELLOW);
drawColorTextLine(3, textLeft, "press down + sel", TFT_YELLOW);
*/


33 changes: 12 additions & 21 deletions Definitions.h
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
#ifndef _Definitions_H_
#define _Definitions_H_

const byte BCDswitch0pin = 8;
const byte BCDswitch1pin = 7;
const byte BCDswitch2pin = 6;
const byte BCDswitch3pin = 5;
const byte weldPin = 2;
const byte weldButtonPin = 4;
const byte upButtonPin = 7;
const byte downButtonPin = 8;
const byte selectButtonPin = 6;
const byte ledPin = 12;
const byte zeroCrossPin = 3;
const byte tftJumperOutPin = A5;
const byte tftJumperInPin = A4;
const byte weldPin = 5;
const byte ledPin = A3;
const byte weldButtonPin = 7;
const byte upButtonPin = 9;
const byte downButtonPin = 8;
const byte selectButtonPin = 10;
const byte foodSwitchPin = A5;
const byte zeroCrossPin = 2;

const byte TFT_RSTpin = 9;
const byte TFT_RSpin = 10;
const byte TFT_CSpin = 5;
//const byte TFT_CLKpin = 13; // for SW SDI, doesn't work
//const byte TFT_SDIpin = 11; // for SW SDI, doesn't work
const byte TFT_RSTpin = A1; // set in user.h, todo: do in TFT_ILI9341 constructor
const byte TFT_DCpin = A0;
const byte TFT_CSpin = A2;

const int step_ms = 50;
const int sinusMax_us = 4583;

#define TXT_COLOR COLOR_YELLOW
const int sinusMax_us = 4583; // average between 0.25/50Hz and 0.25/60Hz

#endif
2 changes: 1 addition & 1 deletion Eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ class Eeprom: public EEPROMClassEx
void write();
bool initialized();

unsigned storedInitValue, preweld_ms, pause_ms, weld_ms; // EEPROM addresses
unsigned storedInitValue_addr, preweld_ms_addr, pause_ms_addr, weld_ms_addr; // EEPROM addresses
};
35 changes: 18 additions & 17 deletions Eeprom.ino
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
const unsigned maxWrites = 100;
const unsigned initValue = 12341; // take another value for new initialization
const unsigned maxWrites = 100;
const unsigned initValue = 4; // take another value for factory default settings

void Eeprom::init()
{ setMemPool(0, EEPROMSizeATmega328);
setMaxAllowedWrites(maxWrites);
storedInitValue = getAddress(sizeof(unsigned));
preweld_ms = getAddress(sizeof(unsigned));
pause_ms = getAddress(sizeof(unsigned));
weld_ms = getAddress(sizeof(unsigned));
orientation = getAddress(sizeof(unsigned));
if(!initialized()) write(); // fill an empty EEPROM
storedInitValue_addr = getAddress(sizeof(unsigned));
preweld_ms_addr = getAddress(sizeof(unsigned));
pause_ms_addr = getAddress(sizeof(unsigned));
weld_ms_addr = getAddress(sizeof(unsigned));
orientation_addr = getAddress(sizeof(unsigned));
if(!initialized()) write(); // fill an empty EEPROM with factory default settings
}

void Eeprom::read()
{ menuItems[0].upDownVal.value = readInt(preweld_ms);
menuItems[1].upDownVal.value = readInt(pause_ms);
menuItems[2].upDownVal.value = readInt(weld_ms);
{ menuItems[0].upDownVal.value = readInt(preweld_ms_addr);
menuItems[1].upDownVal.value = readInt(pause_ms_addr);
menuItems[2].upDownVal.value = readInt(weld_ms_addr);
orientation = readInt(orientation_addr);
}

void Eeprom::write()
{ writeInt(storedInitValue, initValue); // todo with update()?
writeInt(preweld_ms, menuItems[0].upDownVal.value);
writeInt(pause_ms, menuItems[1].upDownVal.value);
writeInt(weld_ms, menuItems[2].upDownVal.value);
writeInt(orientation, 0);
{ writeInt(storedInitValue_addr, initValue);
writeInt(preweld_ms_addr, menuItems[0].upDownVal.value);
writeInt(pause_ms_addr, menuItems[1].upDownVal.value);
writeInt(weld_ms_addr, menuItems[2].upDownVal.value);
writeInt(orientation_addr, orientation);
}

bool Eeprom::initialized()
{ return readInt(storedInitValue) == initValue;
{ return readInt(storedInitValue_addr) == initValue;
}

Loading