Display code

Dependencies:   mbed reScale RotaryEncoder RPG Adafruit_ST7735 Adafruit_GFX PinDetect Ee24xx08 mRotaryEncoder

Committer:
BETZtechnik
Date:
Sun Oct 06 21:18:42 2019 +0000
Revision:
13:83cb3b5c69de
Parent:
12:1e974964272e
twitch hold working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BETZtechnik 11:ce51026d8702 1 #include "mbed.h"
BETZtechnik 0:09419d572e90 2 #include "Adafruit_ST7735.h"
BETZtechnik 1:e8452b75301e 3 #include "RPG.h"
BETZtechnik 0:09419d572e90 4 #include "reScale.h"
BETZtechnik 0:09419d572e90 5 #include "Ee24xx08.h"
BETZtechnik 6:84ea3ec0660d 6 #include "mRotaryEncoder.h"
BETZtechnik 0:09419d572e90 7
BETZtechnik 0:09419d572e90 8
BETZtechnik 0:09419d572e90 9 // DISPLAY INIT:
BETZtechnik 0:09419d572e90 10
BETZtechnik 0:09419d572e90 11 #define BLACK 0x0000
BETZtechnik 0:09419d572e90 12 #define BLUE 0x001F
BETZtechnik 0:09419d572e90 13 #define RED 0xF800
BETZtechnik 0:09419d572e90 14 #define GREEN 0x07E0
BETZtechnik 0:09419d572e90 15 #define CYAN 0x07FF
BETZtechnik 0:09419d572e90 16 #define MAGENTA 0xF81F
BETZtechnik 11:ce51026d8702 17 #define YELLOW 0xFFE0
BETZtechnik 0:09419d572e90 18 #define WHITE 0xFFFF
BETZtechnik 0:09419d572e90 19
BETZtechnik 6:84ea3ec0660d 20 /* EEPROM Memory map:
BETZtechnik 6:84ea3ec0660d 21
BETZtechnik 11:ce51026d8702 22 1 - 50: N1 angles
BETZtechnik 6:84ea3ec0660d 23 51 - 100: Settings
BETZtechnik 6:84ea3ec0660d 24 101- 150: N2 angles
BETZtechnik 6:84ea3ec0660d 25 151- 200: Twitch settings
BETZtechnik 6:84ea3ec0660d 26 200- 250: unused
BETZtechnik 11:ce51026d8702 27 */
BETZtechnik 6:84ea3ec0660d 28
BETZtechnik 1:e8452b75301e 29 #define currentToolAddress 51
BETZtechnik 1:e8452b75301e 30 #define numToolsAddress 52
BETZtechnik 1:e8452b75301e 31 #define numNozAddress 53
BETZtechnik 6:84ea3ec0660d 32 #define versionAddress 54 // 0= basic, 1=pro
BETZtechnik 6:84ea3ec0660d 33 #define syncAddress 55
BETZtechnik 6:84ea3ec0660d 34 #define n1DirAddress 56
BETZtechnik 6:84ea3ec0660d 35 #define n2DirAddress 57
BETZtechnik 13:83cb3b5c69de 36 #define autoModeAddress 58 //
BETZtechnik 13:83cb3b5c69de 37 #define aux2ModeAddress 59
BETZtechnik 0:09419d572e90 38
BETZtechnik 0:09419d572e90 39
BETZtechnik 1:e8452b75301e 40 //DigitalOut myled(P1_13);
BETZtechnik 1:e8452b75301e 41
BETZtechnik 0:09419d572e90 42
BETZtechnik 0:09419d572e90 43 I2C iic(P0_5, P0_4);
BETZtechnik 5:69155b34efd6 44
BETZtechnik 1:e8452b75301e 45
BETZtechnik 1:e8452b75301e 46 DigitalOut dir(P0_21);
BETZtechnik 1:e8452b75301e 47
BETZtechnik 0:09419d572e90 48
BETZtechnik 0:09419d572e90 49 Ee24xx08 eeprom(&iic);
BETZtechnik 0:09419d572e90 50
BETZtechnik 1:e8452b75301e 51 Adafruit_ST7735 tft(P0_9, P0_8, P0_6, P0_2, P0_22, P0_7); // MOSI, MISO, SCLK, SSEL, TFT_DC, TFT_RST
BETZtechnik 0:09419d572e90 52
BETZtechnik 6:84ea3ec0660d 53 int maxServo = 2500;
BETZtechnik 6:84ea3ec0660d 54 int minServo = 500;
BETZtechnik 6:84ea3ec0660d 55 reScale servo1Scale(-90,90,minServo,maxServo); //
BETZtechnik 0:09419d572e90 56
BETZtechnik 11:ce51026d8702 57 PwmOut myServo(P1_13); //display board
BETZtechnik 1:e8452b75301e 58 //PwmOut myServo(D4);
BETZtechnik 0:09419d572e90 59
BETZtechnik 1:e8452b75301e 60 //DigitalIn tUpButton(P2_11);
BETZtechnik 1:e8452b75301e 61 //DigitalIn tDownButton(P2_12);
BETZtechnik 1:e8452b75301e 62 DigitalIn encoderFalseButton(P0_23); // FALSE!!! push button of knob
BETZtechnik 1:e8452b75301e 63 DigitalIn encoderButton(P0_20); // push button of knob
BETZtechnik 1:e8452b75301e 64 DigitalIn backButton(P0_15); // back button
BETZtechnik 6:84ea3ec0660d 65 DigitalIn aButton(P0_1); // ISP and A button
BETZtechnik 0:09419d572e90 66
BETZtechnik 1:e8452b75301e 67 Timer t;
BETZtechnik 6:84ea3ec0660d 68 Timer tw;
BETZtechnik 1:e8452b75301e 69 int lastBackButton;
BETZtechnik 1:e8452b75301e 70 int lastDownButton;
BETZtechnik 1:e8452b75301e 71 int lastEncoderButton;
BETZtechnik 12:1e974964272e 72 int encoderPressed =0; // flag for state
BETZtechnik 12:1e974964272e 73 int encoderPressedTime= 0;
BETZtechnik 1:e8452b75301e 74
BETZtechnik 11:ce51026d8702 75 int encoderMove = 0;
BETZtechnik 6:84ea3ec0660d 76
BETZtechnik 1:e8452b75301e 77 int dirt = 0;
BETZtechnik 0:09419d572e90 78
BETZtechnik 11:ce51026d8702 79 int main()
BETZtechnik 11:ce51026d8702 80 {
BETZtechnik 1:e8452b75301e 81
BETZtechnik 1:e8452b75301e 82 // ************************************** SCREEN INIT *************************************************
BETZtechnik 1:e8452b75301e 83
BETZtechnik 11:ce51026d8702 84 tft.initR(INITR_GREENTAB); // initialize a ST7735S chip, black tab
BETZtechnik 11:ce51026d8702 85
BETZtechnik 11:ce51026d8702 86 tft.setRotation(3);
BETZtechnik 11:ce51026d8702 87 tft.fillScreen(BLACK);
BETZtechnik 11:ce51026d8702 88 tft.setCursor(30,120);
BETZtechnik 11:ce51026d8702 89 tft.setTextColor(BLUE);
BETZtechnik 11:ce51026d8702 90 tft.setTextWrap(false);
BETZtechnik 13:83cb3b5c69de 91 tft.printf("AccuBlast v1.4");
BETZtechnik 11:ce51026d8702 92
BETZtechnik 11:ce51026d8702 93 tft.setCursor(4, 4);
BETZtechnik 11:ce51026d8702 94 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 95 tft.setTextSize(2);
BETZtechnik 11:ce51026d8702 96 tft.printf("N1");
BETZtechnik 11:ce51026d8702 97
BETZtechnik 11:ce51026d8702 98 tft.setCursor(80, 4);
BETZtechnik 11:ce51026d8702 99 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 100 tft.setTextSize(2);
BETZtechnik 11:ce51026d8702 101 tft.printf("N2");
BETZtechnik 11:ce51026d8702 102
BETZtechnik 11:ce51026d8702 103 tft.setCursor(4, 28);
BETZtechnik 11:ce51026d8702 104 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 105 tft.setTextSize(2);
BETZtechnik 11:ce51026d8702 106 tft.printf("T");
BETZtechnik 11:ce51026d8702 107
BETZtechnik 11:ce51026d8702 108 tft.setCursor(4, 50);
BETZtechnik 11:ce51026d8702 109 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 110 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 111 tft.printf("Twitch:");
BETZtechnik 11:ce51026d8702 112
BETZtechnik 11:ce51026d8702 113 tft.setCursor(4, 65);
BETZtechnik 11:ce51026d8702 114 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 115 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 116 tft.printf("Sync:");
BETZtechnik 11:ce51026d8702 117
BETZtechnik 11:ce51026d8702 118 tft.setCursor(4, 80);
BETZtechnik 11:ce51026d8702 119 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 120 tft.setTextSize(1);
BETZtechnik 13:83cb3b5c69de 121 tft.printf("AUTO:");
BETZtechnik 11:ce51026d8702 122
BETZtechnik 11:ce51026d8702 123 tft.setCursor(4, 95);
BETZtechnik 11:ce51026d8702 124 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 125 tft.setTextSize(1);
BETZtechnik 13:83cb3b5c69de 126 tft.printf("IN2mode:");
BETZtechnik 11:ce51026d8702 127
BETZtechnik 11:ce51026d8702 128 tft.setCursor(4, 110);
BETZtechnik 11:ce51026d8702 129 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 130 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 131 tft.printf("AUX 3:");
BETZtechnik 11:ce51026d8702 132
BETZtechnik 11:ce51026d8702 133 tft.setCursor(75, 95);
BETZtechnik 11:ce51026d8702 134 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 135 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 136 tft.printf("Num Tls");
BETZtechnik 11:ce51026d8702 137
BETZtechnik 11:ce51026d8702 138 tft.setCursor(75, 110);
BETZtechnik 11:ce51026d8702 139 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 140 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 141 tft.printf("Num Noz");
BETZtechnik 11:ce51026d8702 142
BETZtechnik 11:ce51026d8702 143 tft.setCursor(75, 50);
BETZtechnik 11:ce51026d8702 144 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 145 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 146 tft.printf("N1 dir:");
BETZtechnik 11:ce51026d8702 147
BETZtechnik 11:ce51026d8702 148 tft.setCursor(75, 65);
BETZtechnik 11:ce51026d8702 149 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 150 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 151 tft.printf("N2 dir:");
BETZtechnik 11:ce51026d8702 152
BETZtechnik 11:ce51026d8702 153 tft.setCursor(75, 80);
BETZtechnik 11:ce51026d8702 154 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 155 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 156 tft.printf("version:");
BETZtechnik 6:84ea3ec0660d 157
BETZtechnik 11:ce51026d8702 158 // **************************************************************************************************************
BETZtechnik 11:ce51026d8702 159 int version = 0; // 0= basic, 1=pro
BETZtechnik 11:ce51026d8702 160 int lastVersion = 99;
BETZtechnik 11:ce51026d8702 161
BETZtechnik 11:ce51026d8702 162 int sync = 0; // sync setting for N1 and N1
BETZtechnik 11:ce51026d8702 163 int lastSync = 99;
BETZtechnik 11:ce51026d8702 164 int syncSpread = 0;
BETZtechnik 11:ce51026d8702 165 int syncFlag =0; ///// for count/ sync = 2 issue. 2019-09-11
BETZtechnik 11:ce51026d8702 166
BETZtechnik 11:ce51026d8702 167 int n1Dir = 0; // direction of knob for N1
BETZtechnik 11:ce51026d8702 168 int lastN1Dir = 99;
BETZtechnik 11:ce51026d8702 169
BETZtechnik 11:ce51026d8702 170 int n2Dir = 0; // direction of knob for N2
BETZtechnik 11:ce51026d8702 171 int lastN2Dir = 99;
BETZtechnik 13:83cb3b5c69de 172
BETZtechnik 13:83cb3b5c69de 173 int autoMode = 0;
BETZtechnik 13:83cb3b5c69de 174 int lastAutoMode = 99;
BETZtechnik 13:83cb3b5c69de 175
BETZtechnik 13:83cb3b5c69de 176 int aux2Mode = 0;
BETZtechnik 13:83cb3b5c69de 177 int lastAux2Mode = 99;
BETZtechnik 11:ce51026d8702 178
BETZtechnik 11:ce51026d8702 179 int index = 0;
BETZtechnik 6:84ea3ec0660d 180
BETZtechnik 11:ce51026d8702 181 int count = 0;
BETZtechnik 11:ce51026d8702 182 int maxCount = 12; //max number of menu items
BETZtechnik 11:ce51026d8702 183 int lastCount = 99;
BETZtechnik 6:84ea3ec0660d 184
BETZtechnik 11:ce51026d8702 185 int twitch = 0;
BETZtechnik 11:ce51026d8702 186 int lastTwitch = 300;
BETZtechnik 11:ce51026d8702 187 int lastTwitchMove = 0;
BETZtechnik 11:ce51026d8702 188 int twitchStart = 0; // has twitching begun?
BETZtechnik 11:ce51026d8702 189 int twitchDirection = 0; // 0 is up, 1 is down.
BETZtechnik 11:ce51026d8702 190 int maxTwitch = 0;
BETZtechnik 11:ce51026d8702 191 int minTwitch = 0;
BETZtechnik 13:83cb3b5c69de 192 int twitchHold = 0; //marker for hold message recieved from Inputs board.
BETZtechnik 11:ce51026d8702 193
BETZtechnik 11:ce51026d8702 194 int tw1 = 5; // stages of servo write to control speed of sweep. 11.11 Ms = 1 degree
BETZtechnik 11:ce51026d8702 195 int tw2 = 10;
BETZtechnik 11:ce51026d8702 196 int tw3 = 15;
BETZtechnik 11:ce51026d8702 197
BETZtechnik 11:ce51026d8702 198 int twReadMs = 100; // interval of twitch changes us.
BETZtechnik 11:ce51026d8702 199
BETZtechnik 11:ce51026d8702 200 //************* Pull previous setting from eeprom *******************
BETZtechnik 6:84ea3ec0660d 201
BETZtechnik 11:ce51026d8702 202 char tempToolNo = 0; // last tool in spindle
BETZtechnik 11:ce51026d8702 203 eeprom.read(currentToolAddress, &tempToolNo);
BETZtechnik 11:ce51026d8702 204 int currentToolNo = (int)tempToolNo;
BETZtechnik 11:ce51026d8702 205
BETZtechnik 11:ce51026d8702 206 char tempNumTools = 0; // number of tools in ATC
BETZtechnik 11:ce51026d8702 207 eeprom.read(numToolsAddress, &tempNumTools);
BETZtechnik 11:ce51026d8702 208 int numTools = (int)tempNumTools;
BETZtechnik 11:ce51026d8702 209
BETZtechnik 11:ce51026d8702 210 char tempNumNoz = 0; // number of nozzles installed
BETZtechnik 11:ce51026d8702 211 eeprom.read(numNozAddress, &tempNumNoz);
BETZtechnik 11:ce51026d8702 212 int numNoz = (int)tempNumNoz;
BETZtechnik 11:ce51026d8702 213
BETZtechnik 11:ce51026d8702 214 char tempLastAngle = 0; // last angle of last tool in spindle N1
BETZtechnik 11:ce51026d8702 215 eeprom.read(currentToolNo, &tempLastAngle);
BETZtechnik 11:ce51026d8702 216 int lastAngle = (int)tempLastAngle;
BETZtechnik 11:ce51026d8702 217 lastAngle = lastAngle - 90; // Not storing signed int, so signed value is 45 less than what was stored to memory.
BETZtechnik 11:ce51026d8702 218
BETZtechnik 11:ce51026d8702 219 char tempLastAngleN2 = 0; // last angle of last tool in spindle
BETZtechnik 11:ce51026d8702 220 eeprom.read(currentToolNo+100, &tempLastAngleN2);
BETZtechnik 11:ce51026d8702 221 int lastAngleN2 = (int)tempLastAngleN2;
BETZtechnik 11:ce51026d8702 222 lastAngleN2 = lastAngleN2 - 90; // Not storing signed int, so signed value is 45 less than what was stored to memory.
BETZtechnik 11:ce51026d8702 223
BETZtechnik 11:ce51026d8702 224 char tempLastTwitch = 0; // last Twitch setting for the current tool in spindle
BETZtechnik 11:ce51026d8702 225 eeprom.read(currentToolNo + 150, &tempLastTwitch);
BETZtechnik 11:ce51026d8702 226 twitch = (int)tempLastTwitch; // should be 1, 2 or 3.
BETZtechnik 11:ce51026d8702 227
BETZtechnik 11:ce51026d8702 228 char tempLastVersion = 0; // version of system. 0=basic, 1=pro
BETZtechnik 11:ce51026d8702 229 eeprom.read(versionAddress, &tempLastVersion);
BETZtechnik 11:ce51026d8702 230 version = (int)tempLastVersion;
BETZtechnik 11:ce51026d8702 231
BETZtechnik 11:ce51026d8702 232 char tempLastSync = 0; // previous sync setting
BETZtechnik 11:ce51026d8702 233 eeprom.read(syncAddress, &tempLastSync);
BETZtechnik 11:ce51026d8702 234 sync = (int)tempLastSync;
BETZtechnik 11:ce51026d8702 235
BETZtechnik 11:ce51026d8702 236 char tempLastN1Dir = 0; // previous N1 knob direction setting
BETZtechnik 11:ce51026d8702 237 eeprom.read(n1DirAddress, &tempLastN1Dir);
BETZtechnik 11:ce51026d8702 238 n1Dir = (int)tempLastN1Dir;
BETZtechnik 11:ce51026d8702 239
BETZtechnik 6:84ea3ec0660d 240 char tempLastN2Dir = 0; // previous N2 knob direction setting
BETZtechnik 11:ce51026d8702 241 eeprom.read(n2DirAddress, &tempLastN2Dir);
BETZtechnik 11:ce51026d8702 242 n2Dir = (int)tempLastN2Dir;
BETZtechnik 0:09419d572e90 243
BETZtechnik 13:83cb3b5c69de 244 char tempLastAuto = 0; // previous N2 knob direction setting
BETZtechnik 13:83cb3b5c69de 245 eeprom.read(autoModeAddress, &tempLastAuto);
BETZtechnik 13:83cb3b5c69de 246 autoMode = (int)tempLastAuto;
BETZtechnik 13:83cb3b5c69de 247
BETZtechnik 13:83cb3b5c69de 248 char tempLastAux2 = 0; // previous N2 knob direction setting
BETZtechnik 13:83cb3b5c69de 249 eeprom.read(aux2ModeAddress, &tempLastAux2);
BETZtechnik 13:83cb3b5c69de 250 aux2Mode = (int)tempLastAux2;
BETZtechnik 13:83cb3b5c69de 251
BETZtechnik 1:e8452b75301e 252
BETZtechnik 11:ce51026d8702 253 /*EEprom test over 2 digits:
BETZtechnik 11:ce51026d8702 254 int test1 = 150;
BETZtechnik 11:ce51026d8702 255 eeprom.write(199, test1);
BETZtechnik 11:ce51026d8702 256 wait(1);
BETZtechnik 11:ce51026d8702 257 char tempN2char = 0;
BETZtechnik 11:ce51026d8702 258 eeprom.read(199, &tempN2char);
BETZtechnik 11:ce51026d8702 259 int tempN2 = (int)tempN2char;
BETZtechnik 11:ce51026d8702 260 tft.setCursor(130,120);
BETZtechnik 11:ce51026d8702 261 tft.setTextColor(RED);
BETZtechnik 11:ce51026d8702 262 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 263 tft.printf("%d", tempN2);
BETZtechnik 11:ce51026d8702 264 */
BETZtechnik 11:ce51026d8702 265
BETZtechnik 11:ce51026d8702 266
BETZtechnik 11:ce51026d8702 267 //******************** Button debounce *********************************
BETZtechnik 11:ce51026d8702 268
BETZtechnik 11:ce51026d8702 269
BETZtechnik 11:ce51026d8702 270
BETZtechnik 11:ce51026d8702 271 backButton.mode(PullUp); // button pull up
BETZtechnik 11:ce51026d8702 272 //tDownButton.mode(PullUp); // button pull up
BETZtechnik 11:ce51026d8702 273 encoderButton.mode(PullUp);
BETZtechnik 11:ce51026d8702 274 encoderFalseButton.mode(PullUp);
BETZtechnik 11:ce51026d8702 275 aButton.mode(PullUp);
BETZtechnik 11:ce51026d8702 276
BETZtechnik 11:ce51026d8702 277 t.start(); // starts timer
BETZtechnik 11:ce51026d8702 278 lastBackButton = t.read_ms();
BETZtechnik 11:ce51026d8702 279 lastDownButton = t.read_ms();
BETZtechnik 11:ce51026d8702 280 lastEncoderButton = t.read_ms();
BETZtechnik 12:1e974964272e 281 encoderPressedTime= t.read_ms();
BETZtechnik 11:ce51026d8702 282
BETZtechnik 11:ce51026d8702 283 //****************************************************************************
BETZtechnik 11:ce51026d8702 284
BETZtechnik 11:ce51026d8702 285 int lastToolNo = 99;
BETZtechnik 11:ce51026d8702 286 int lastNumTools = -1; // trigger to write eeprom value for number of tools
BETZtechnik 11:ce51026d8702 287
BETZtechnik 11:ce51026d8702 288 int lastNumNoz = 0; //trigger display for number of nozzles after startup
BETZtechnik 11:ce51026d8702 289
BETZtechnik 11:ce51026d8702 290 int n1Pos = lastAngle; //Set servo to last known postition prior to power off
BETZtechnik 11:ce51026d8702 291 int lastN1Pos = 150;
BETZtechnik 0:09419d572e90 292
BETZtechnik 11:ce51026d8702 293 int n2Pos = lastAngleN2;
BETZtechnik 11:ce51026d8702 294 int lastN2Pos = 150;
BETZtechnik 11:ce51026d8702 295
BETZtechnik 11:ce51026d8702 296 int servo1Pos = 0;
BETZtechnik 11:ce51026d8702 297
BETZtechnik 11:ce51026d8702 298
BETZtechnik 11:ce51026d8702 299 // RPG rpg1(P2_2,P1_20,P0_23); // RPG (PinName pA, PinName pB, PinName pPB)P0_23 is unconnected!! ;
BETZtechnik 11:ce51026d8702 300 //mRotaryEncoder Enc(P2_2,P1_20,P0_23, PullUp, 500);
BETZtechnik 11:ce51026d8702 301 mRotaryEncoder Enc(P1_20,P2_2,P0_23, PullUp, 1000);
BETZtechnik 11:ce51026d8702 302
BETZtechnik 11:ce51026d8702 303 myServo.period_ms(20);
BETZtechnik 11:ce51026d8702 304
BETZtechnik 11:ce51026d8702 305 /*
BETZtechnik 11:ce51026d8702 306 char t1Ang = 200;
BETZtechnik 11:ce51026d8702 307 char t1Read = 0;
BETZtechnik 11:ce51026d8702 308
BETZtechnik 11:ce51026d8702 309 eeprom.write(1, t1Ang);
BETZtechnik 11:ce51026d8702 310 wait(1);
BETZtechnik 11:ce51026d8702 311 eeprom.read(1, &t1Read);
BETZtechnik 11:ce51026d8702 312
BETZtechnik 0:09419d572e90 313
BETZtechnik 11:ce51026d8702 314 tft.setCursor(30,110);
BETZtechnik 11:ce51026d8702 315 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 316 tft.setTextWrap(true);
BETZtechnik 11:ce51026d8702 317 // tft.printf("%s\r\n",t1Read);
BETZtechnik 11:ce51026d8702 318 tft.printf("%d", currentTool);
BETZtechnik 11:ce51026d8702 319 */
BETZtechnik 11:ce51026d8702 320
BETZtechnik 11:ce51026d8702 321 uint8_t c = 0; // for 485 link
BETZtechnik 11:ce51026d8702 322
BETZtechnik 11:ce51026d8702 323
BETZtechnik 11:ce51026d8702 324 int serialToolNumber = 0;
BETZtechnik 11:ce51026d8702 325 int stage = 0; // for serial parsing
BETZtechnik 11:ce51026d8702 326 int Tens = 0;
BETZtechnik 11:ce51026d8702 327 int Ones = 0;
BETZtechnik 11:ce51026d8702 328
BETZtechnik 11:ce51026d8702 329 dir = 0;
BETZtechnik 11:ce51026d8702 330
BETZtechnik 11:ce51026d8702 331 wait(2);
BETZtechnik 11:ce51026d8702 332 Serial device(P0_14, P0_13, 19200); // RS 485 TX RX?
BETZtechnik 11:ce51026d8702 333
BETZtechnik 0:09419d572e90 334 while(1) {
BETZtechnik 11:ce51026d8702 335
BETZtechnik 11:ce51026d8702 336
BETZtechnik 11:ce51026d8702 337
BETZtechnik 11:ce51026d8702 338 /*
BETZtechnik 11:ce51026d8702 339 while (device.readable())
BETZtechnik 11:ce51026d8702 340 {
BETZtechnik 11:ce51026d8702 341 c = device.getc();
BETZtechnik 11:ce51026d8702 342
BETZtechnik 11:ce51026d8702 343
BETZtechnik 11:ce51026d8702 344 if (c == '+'){
BETZtechnik 11:ce51026d8702 345 currentToolNo = currentToolNo +1;
BETZtechnik 11:ce51026d8702 346 if (currentToolNo > numTools){
BETZtechnik 11:ce51026d8702 347 currentToolNo = 1;
BETZtechnik 11:ce51026d8702 348 }
BETZtechnik 11:ce51026d8702 349 }
BETZtechnik 11:ce51026d8702 350
BETZtechnik 11:ce51026d8702 351 else if (c == '-'){
BETZtechnik 11:ce51026d8702 352 currentToolNo = currentToolNo - 1;
BETZtechnik 11:ce51026d8702 353 if (currentToolNo > 1){
BETZtechnik 11:ce51026d8702 354 currentToolNo = numTools;
BETZtechnik 11:ce51026d8702 355 }
BETZtechnik 11:ce51026d8702 356 }
BETZtechnik 11:ce51026d8702 357 }
BETZtechnik 11:ce51026d8702 358 */
BETZtechnik 11:ce51026d8702 359
BETZtechnik 11:ce51026d8702 360 /*
BETZtechnik 11:ce51026d8702 361 while (device.readable())
BETZtechnik 11:ce51026d8702 362 {
BETZtechnik 11:ce51026d8702 363
BETZtechnik 11:ce51026d8702 364
BETZtechnik 11:ce51026d8702 365 c = device.getc();
BETZtechnik 11:ce51026d8702 366
BETZtechnik 11:ce51026d8702 367 if (c == 'M'){
BETZtechnik 11:ce51026d8702 368 // stage = 1;
BETZtechnik 2:bbbacfd62773 369
BETZtechnik 11:ce51026d8702 370 c = device.getc();
BETZtechnik 11:ce51026d8702 371 if (c == '+'){
BETZtechnik 11:ce51026d8702 372
BETZtechnik 11:ce51026d8702 373 // tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 374 // tft.setCursor(100, 100);
BETZtechnik 11:ce51026d8702 375 // tft.printf("%d", c);
BETZtechnik 11:ce51026d8702 376 currentToolNo = currentToolNo +1;
BETZtechnik 11:ce51026d8702 377 if (currentToolNo > numTools){
BETZtechnik 11:ce51026d8702 378 currentToolNo = 1;
BETZtechnik 11:ce51026d8702 379 }
BETZtechnik 11:ce51026d8702 380 }
BETZtechnik 11:ce51026d8702 381
BETZtechnik 11:ce51026d8702 382 else if (c == '-'){
BETZtechnik 11:ce51026d8702 383 currentToolNo = currentToolNo - 1;
BETZtechnik 11:ce51026d8702 384 if (currentToolNo < 1){
BETZtechnik 11:ce51026d8702 385 currentToolNo = numTools;
BETZtechnik 11:ce51026d8702 386 }
BETZtechnik 11:ce51026d8702 387 }
BETZtechnik 11:ce51026d8702 388
BETZtechnik 11:ce51026d8702 389 }
BETZtechnik 11:ce51026d8702 390 }
BETZtechnik 11:ce51026d8702 391
BETZtechnik 11:ce51026d8702 392 */
BETZtechnik 11:ce51026d8702 393
BETZtechnik 11:ce51026d8702 394
BETZtechnik 11:ce51026d8702 395
BETZtechnik 11:ce51026d8702 396 //myled = 1;
BETZtechnik 11:ce51026d8702 397
BETZtechnik 11:ce51026d8702 398 if (t.read() > 1200) { // timer can only hold 30 min, so reset after 20
BETZtechnik 11:ce51026d8702 399 t.reset();
BETZtechnik 11:ce51026d8702 400 lastBackButton = t.read_ms();
BETZtechnik 11:ce51026d8702 401 lastDownButton = t.read_ms();
BETZtechnik 11:ce51026d8702 402 lastEncoderButton = t.read_ms();
BETZtechnik 11:ce51026d8702 403 }
BETZtechnik 1:e8452b75301e 404
BETZtechnik 6:84ea3ec0660d 405
BETZtechnik 6:84ea3ec0660d 406
BETZtechnik 11:ce51026d8702 407 if (backButton == 0) { //Back button was pressed so back to default selection
BETZtechnik 11:ce51026d8702 408 count = 0;
BETZtechnik 11:ce51026d8702 409 }
BETZtechnik 11:ce51026d8702 410
BETZtechnik 12:1e974964272e 411 // ************************* encoder button
BETZtechnik 12:1e974964272e 412 if (encoderButton == 0 && encoderPressed == 0 && (t.read_ms() > (lastEncoderButton + 200))) {
BETZtechnik 12:1e974964272e 413 encoderPressed = 1;
BETZtechnik 12:1e974964272e 414 encoderPressedTime = t.read_ms();
BETZtechnik 12:1e974964272e 415 }
BETZtechnik 12:1e974964272e 416
BETZtechnik 12:1e974964272e 417 if (encoderButton == 0 && encoderPressed == 1 && (t.read_ms() < (encoderPressedTime + 20))) {
BETZtechnik 12:1e974964272e 418 count = count + 1; //Reset count if PB pressed
BETZtechnik 12:1e974964272e 419 lastEncoderButton = t.read_ms();
BETZtechnik 12:1e974964272e 420 encoderPressed = 0;
BETZtechnik 12:1e974964272e 421 }
BETZtechnik 12:1e974964272e 422
BETZtechnik 12:1e974964272e 423 if (encoderButton == 1 && encoderPressed == 1 && (t.read_ms() < (encoderPressedTime + 10))) {
BETZtechnik 12:1e974964272e 424 encoderPressed = 0;
BETZtechnik 12:1e974964272e 425 }
BETZtechnik 12:1e974964272e 426
BETZtechnik 12:1e974964272e 427
BETZtechnik 12:1e974964272e 428 if (count > maxCount) {
BETZtechnik 12:1e974964272e 429 count = 0;
BETZtechnik 12:1e974964272e 430 }
BETZtechnik 12:1e974964272e 431
BETZtechnik 12:1e974964272e 432 if (count > maxCount) {
BETZtechnik 12:1e974964272e 433 count = 0;
BETZtechnik 12:1e974964272e 434 }
BETZtechnik 12:1e974964272e 435
BETZtechnik 12:1e974964272e 436
BETZtechnik 12:1e974964272e 437
BETZtechnik 12:1e974964272e 438
BETZtechnik 12:1e974964272e 439 // ******************************
BETZtechnik 12:1e974964272e 440 /*
BETZtechnik 11:ce51026d8702 441 if (encoderButton == 0) {
BETZtechnik 11:ce51026d8702 442 if (t.read_ms() > (lastEncoderButton + 50)) { // from 200
BETZtechnik 11:ce51026d8702 443 count = count + 1; //Reset count if PB pressed
BETZtechnik 11:ce51026d8702 444 }
BETZtechnik 11:ce51026d8702 445 if (count > maxCount) {
BETZtechnik 11:ce51026d8702 446 count = 0;
BETZtechnik 11:ce51026d8702 447 }
BETZtechnik 11:ce51026d8702 448 lastEncoderButton = t.read_ms();
BETZtechnik 11:ce51026d8702 449
BETZtechnik 11:ce51026d8702 450 if (count > maxCount) {
BETZtechnik 11:ce51026d8702 451 count = 0;
BETZtechnik 11:ce51026d8702 452 }
BETZtechnik 11:ce51026d8702 453 }
BETZtechnik 12:1e974964272e 454 */
BETZtechnik 12:1e974964272e 455 //************************************
BETZtechnik 11:ce51026d8702 456
BETZtechnik 11:ce51026d8702 457 //****************************************************************************************
BETZtechnik 11:ce51026d8702 458
BETZtechnik 11:ce51026d8702 459 if (version == 0) { //Basic runs the servo direct from the display unit
BETZtechnik 11:ce51026d8702 460 if (twitch == 0) {
BETZtechnik 11:ce51026d8702 461 tw.stop();
BETZtechnik 11:ce51026d8702 462 twitchStart = 0;
BETZtechnik 11:ce51026d8702 463 twitchDirection = 0;
BETZtechnik 11:ce51026d8702 464 servo1Pos = servo1Scale.from(n1Pos);
BETZtechnik 11:ce51026d8702 465 }
BETZtechnik 11:ce51026d8702 466
BETZtechnik 11:ce51026d8702 467 if (twitch > 0) {
BETZtechnik 11:ce51026d8702 468 if (twitchStart == 0) {
BETZtechnik 11:ce51026d8702 469 tw.start(); // start timer for nozzle sweep
BETZtechnik 11:ce51026d8702 470 servo1Pos = servo1Scale.from(n1Pos);
BETZtechnik 11:ce51026d8702 471 lastTwitchMove = tw.read_ms(); // store time of last nozzle movement
BETZtechnik 11:ce51026d8702 472 minTwitch = servo1Pos; // store original servo postion for bottom of sweep
BETZtechnik 11:ce51026d8702 473 maxTwitch = servo1Pos + 1000; // 11.11mS per degree of sweep, 55 = 5 degrees of sweep. This should be a viariable set on the display.
BETZtechnik 11:ce51026d8702 474 twitchStart = 1;
BETZtechnik 11:ce51026d8702 475 }
BETZtechnik 11:ce51026d8702 476 if ((twitchStart == 1) && (tw.read_ms() > (lastTwitchMove + twReadMs))) {
BETZtechnik 11:ce51026d8702 477 if (twitchDirection == 0) { //going up
BETZtechnik 11:ce51026d8702 478 servo1Pos = servo1Pos + 100; // add variable amount of uS to the servo signal
BETZtechnik 11:ce51026d8702 479
BETZtechnik 11:ce51026d8702 480 tft.setCursor(130,120);
BETZtechnik 11:ce51026d8702 481 tft.setTextColor(RED);
BETZtechnik 11:ce51026d8702 482 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 483 tft.printf("%d", servo1Pos);
BETZtechnik 11:ce51026d8702 484
BETZtechnik 11:ce51026d8702 485
BETZtechnik 11:ce51026d8702 486 if (servo1Pos > maxServo) {
BETZtechnik 11:ce51026d8702 487 servo1Pos = maxServo;
BETZtechnik 11:ce51026d8702 488 twitchDirection = 1; //reverse direction
BETZtechnik 11:ce51026d8702 489 }
BETZtechnik 11:ce51026d8702 490 if (servo1Pos > maxTwitch) {
BETZtechnik 11:ce51026d8702 491 servo1Pos = maxTwitch;
BETZtechnik 11:ce51026d8702 492 twitchDirection = 1; //reverse direction
BETZtechnik 11:ce51026d8702 493 }
BETZtechnik 11:ce51026d8702 494 lastTwitchMove = tw.read_ms();
BETZtechnik 11:ce51026d8702 495 }
BETZtechnik 11:ce51026d8702 496
BETZtechnik 11:ce51026d8702 497 if (twitchDirection == 1) { // going down
BETZtechnik 11:ce51026d8702 498 servo1Pos = servo1Pos - 100; // add variable amount of Ms to the servo signal
BETZtechnik 11:ce51026d8702 499 if (servo1Pos < minServo) {
BETZtechnik 11:ce51026d8702 500 servo1Pos = minServo;
BETZtechnik 11:ce51026d8702 501 twitchDirection = 0; //reverse direction
BETZtechnik 11:ce51026d8702 502 }
BETZtechnik 11:ce51026d8702 503 if (servo1Pos < minTwitch) {
BETZtechnik 11:ce51026d8702 504 servo1Pos = minTwitch;
BETZtechnik 11:ce51026d8702 505 twitchDirection = 0; //reverse direction
BETZtechnik 11:ce51026d8702 506 }
BETZtechnik 11:ce51026d8702 507 lastTwitchMove = tw.read_ms();
BETZtechnik 11:ce51026d8702 508 }
BETZtechnik 11:ce51026d8702 509 }
BETZtechnik 11:ce51026d8702 510 }
BETZtechnik 11:ce51026d8702 511
BETZtechnik 11:ce51026d8702 512 myServo.pulsewidth_us(servo1Pos);
BETZtechnik 11:ce51026d8702 513 }
BETZtechnik 11:ce51026d8702 514
BETZtechnik 11:ce51026d8702 515
BETZtechnik 11:ce51026d8702 516 //********************** update display values **********************************************
BETZtechnik 11:ce51026d8702 517
BETZtechnik 11:ce51026d8702 518
BETZtechnik 11:ce51026d8702 519 if (currentToolNo != lastToolNo) {
BETZtechnik 11:ce51026d8702 520 /*
BETZtechnik 11:ce51026d8702 521 tft.fillRect(103, 2, 55,25, BLACK);
BETZtechnik 11:ce51026d8702 522 tft.setCursor(105, 4);
BETZtechnik 11:ce51026d8702 523 */
BETZtechnik 11:ce51026d8702 524 tft.setCursor(22, 28);
BETZtechnik 11:ce51026d8702 525 tft.setTextColor(BLACK);
BETZtechnik 11:ce51026d8702 526 tft.setTextSize(2);
BETZtechnik 11:ce51026d8702 527 tft.printf("%d", lastToolNo);
BETZtechnik 11:ce51026d8702 528 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 529 //tft.setTextSize(2);
BETZtechnik 11:ce51026d8702 530 // tft.printf("T");
BETZtechnik 11:ce51026d8702 531 tft.setCursor(22,28);
BETZtechnik 11:ce51026d8702 532 tft.printf("%d", currentToolNo);
BETZtechnik 11:ce51026d8702 533
BETZtechnik 11:ce51026d8702 534 tempLastAngle = 0;
BETZtechnik 11:ce51026d8702 535 eeprom.read(currentToolNo, &tempLastAngle);
BETZtechnik 11:ce51026d8702 536 lastAngle = (int)tempLastAngle;
BETZtechnik 11:ce51026d8702 537 lastAngle = lastAngle - 90; // Not storing signed int, so signed value is 90 less than what was stored to memory.
BETZtechnik 11:ce51026d8702 538 n1Pos = lastAngle;
BETZtechnik 11:ce51026d8702 539
BETZtechnik 11:ce51026d8702 540 tempLastAngleN2 = 0;
BETZtechnik 11:ce51026d8702 541 eeprom.read(currentToolNo+100, &tempLastAngleN2);
BETZtechnik 11:ce51026d8702 542 int lastAngleN2 = (int)tempLastAngleN2;
BETZtechnik 11:ce51026d8702 543 lastAngleN2 = lastAngleN2 - 90; // Not storing signed int, so signed value is 45 less than what was stored to memory.
BETZtechnik 11:ce51026d8702 544 n2Pos = lastAngleN2;
BETZtechnik 11:ce51026d8702 545
BETZtechnik 11:ce51026d8702 546 if (count == 0) { // if knob is on N1 adjust and ATC changes tools, update enc value)
BETZtechnik 11:ce51026d8702 547 Enc.Set(n1Pos); // test for ATC following issue!
BETZtechnik 11:ce51026d8702 548 }
BETZtechnik 11:ce51026d8702 549
BETZtechnik 11:ce51026d8702 550 eeprom.write(currentToolAddress, currentToolNo);
BETZtechnik 11:ce51026d8702 551 wait(0.1);
BETZtechnik 11:ce51026d8702 552 tempLastTwitch = 0;
BETZtechnik 11:ce51026d8702 553 eeprom.read(currentToolNo + 150, &tempLastTwitch); // pull up previous twitch setting.
BETZtechnik 11:ce51026d8702 554 twitch = (int)tempLastTwitch;
BETZtechnik 11:ce51026d8702 555 lastToolNo = currentToolNo;
BETZtechnik 11:ce51026d8702 556 }
BETZtechnik 11:ce51026d8702 557
BETZtechnik 11:ce51026d8702 558
BETZtechnik 11:ce51026d8702 559 if (n1Pos != lastN1Pos) {
BETZtechnik 11:ce51026d8702 560 tft.setCursor(40, 4);
BETZtechnik 11:ce51026d8702 561 tft.setTextColor(BLACK);
BETZtechnik 11:ce51026d8702 562 tft.setTextSize(2);
BETZtechnik 11:ce51026d8702 563 tft.printf("%d", lastN1Pos);
BETZtechnik 11:ce51026d8702 564 tft.setCursor(40,4);
BETZtechnik 11:ce51026d8702 565 tft.setTextColor(GREEN);
BETZtechnik 11:ce51026d8702 566 tft.setTextSize(2);
BETZtechnik 11:ce51026d8702 567 tft.printf("%d", n1Pos);
BETZtechnik 11:ce51026d8702 568 eeprom.write(currentToolNo, n1Pos + 90); // store new angle in eeprom, add 90 because its an unsigned value.
BETZtechnik 11:ce51026d8702 569 //wait(0.1); // adjusted from 1
BETZtechnik 11:ce51026d8702 570 dir=1;
BETZtechnik 11:ce51026d8702 571 device.printf("N");
BETZtechnik 11:ce51026d8702 572 device.printf("%d", n1Pos + 190); //send over RS485 add 190 so no negative values and always 3 digits.
BETZtechnik 11:ce51026d8702 573 //device.printf("N245"); // TEST!!!
BETZtechnik 11:ce51026d8702 574 // tft.setCursor(100, 50);
BETZtechnik 11:ce51026d8702 575 // tft.setTextSize(2);
BETZtechnik 11:ce51026d8702 576 // tft.printf("%d", n1Pos + 145);
BETZtechnik 11:ce51026d8702 577 wait(0.05);
BETZtechnik 11:ce51026d8702 578 dir=0;
BETZtechnik 11:ce51026d8702 579
BETZtechnik 11:ce51026d8702 580 //Enc.Set(n1Pos); // test!!
BETZtechnik 11:ce51026d8702 581
BETZtechnik 11:ce51026d8702 582 lastN1Pos = n1Pos;
BETZtechnik 11:ce51026d8702 583 syncFlag =1; // set the flag after lastN1Pos has run once to allow REV sync setting in count ==0 2019-09-11
BETZtechnik 11:ce51026d8702 584 }
BETZtechnik 11:ce51026d8702 585
BETZtechnik 11:ce51026d8702 586 if (n2Pos != lastN2Pos && numNoz == 2) {
BETZtechnik 11:ce51026d8702 587 tft.setCursor(115, 4);
BETZtechnik 11:ce51026d8702 588 tft.setTextColor(BLACK);
BETZtechnik 11:ce51026d8702 589 tft.setTextSize(2);
BETZtechnik 11:ce51026d8702 590 tft.printf("%d", lastN2Pos);
BETZtechnik 11:ce51026d8702 591 tft.setCursor(115, 4);
BETZtechnik 11:ce51026d8702 592 tft.setTextColor(GREEN);
BETZtechnik 11:ce51026d8702 593 tft.setTextSize(2);
BETZtechnik 11:ce51026d8702 594 tft.printf("%d", n2Pos);
BETZtechnik 11:ce51026d8702 595 eeprom.write(currentToolNo +100, n2Pos + 90); // store new angle in eeprom, add 90 because its an unsigned value.
BETZtechnik 11:ce51026d8702 596 //wait(0.1); // adjusted from 1
BETZtechnik 11:ce51026d8702 597 dir=1;
BETZtechnik 11:ce51026d8702 598 device.printf("N");
BETZtechnik 11:ce51026d8702 599 device.printf("%d", n2Pos + 390); //send over RS485 add 390 so no negative values and always 3 digits.
BETZtechnik 11:ce51026d8702 600 //device.printf("N245"); // TEST!!!
BETZtechnik 11:ce51026d8702 601 // tft.setCursor(100, 50);
BETZtechnik 11:ce51026d8702 602 // tft.setTextSize(2);
BETZtechnik 11:ce51026d8702 603 // tft.printf("%d", n1Pos + 145);
BETZtechnik 11:ce51026d8702 604 wait(0.05);
BETZtechnik 11:ce51026d8702 605 dir=0;
BETZtechnik 11:ce51026d8702 606 lastN2Pos = n2Pos;
BETZtechnik 11:ce51026d8702 607 }
BETZtechnik 11:ce51026d8702 608
BETZtechnik 11:ce51026d8702 609
BETZtechnik 11:ce51026d8702 610 if (numTools != lastNumTools) {
BETZtechnik 11:ce51026d8702 611 tft.setCursor(133, 95);
BETZtechnik 11:ce51026d8702 612 tft.setTextColor(BLACK);
BETZtechnik 11:ce51026d8702 613 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 614 tft.printf("%d", lastNumTools);
BETZtechnik 11:ce51026d8702 615 tft.setCursor(133,95);
BETZtechnik 11:ce51026d8702 616 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 617 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 618 tft.printf("%d", numTools);
BETZtechnik 11:ce51026d8702 619 eeprom.write(numToolsAddress, numTools); // store new angle in eeprom, add 45 because its an unsigned value.
BETZtechnik 11:ce51026d8702 620 //wait(0.1); // adjusted from 1
BETZtechnik 11:ce51026d8702 621 lastNumTools = numTools;
BETZtechnik 11:ce51026d8702 622 }
BETZtechnik 11:ce51026d8702 623
BETZtechnik 11:ce51026d8702 624 if (numNoz != lastNumNoz) {
BETZtechnik 11:ce51026d8702 625 tft.setCursor(133, 110);
BETZtechnik 11:ce51026d8702 626 tft.setTextColor(BLACK);
BETZtechnik 11:ce51026d8702 627 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 628 tft.printf("%d", lastNumNoz);
BETZtechnik 11:ce51026d8702 629 tft.setCursor(133,110);
BETZtechnik 11:ce51026d8702 630 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 631 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 632 tft.printf("%d", numNoz);
BETZtechnik 11:ce51026d8702 633 eeprom.write(numNozAddress, numNoz); // store new angle in eeprom, add 45 because its an unsigned value.
BETZtechnik 11:ce51026d8702 634 //wait(0.1); // adjusted from 1
BETZtechnik 11:ce51026d8702 635
BETZtechnik 11:ce51026d8702 636 if (numNoz == 2) {
BETZtechnik 11:ce51026d8702 637 tft.setCursor(80, 4);
BETZtechnik 11:ce51026d8702 638 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 639 tft.setTextSize(2);
BETZtechnik 11:ce51026d8702 640 tft.printf("N2");
BETZtechnik 11:ce51026d8702 641 tft.drawRect(78,2,74,18,WHITE);
BETZtechnik 11:ce51026d8702 642 }
BETZtechnik 11:ce51026d8702 643 if (numNoz == 1) {
BETZtechnik 11:ce51026d8702 644 tft.setCursor(80, 4);
BETZtechnik 11:ce51026d8702 645 tft.setTextColor(BLACK);
BETZtechnik 11:ce51026d8702 646 tft.setTextSize(2);
BETZtechnik 11:ce51026d8702 647 tft.printf("N2");
BETZtechnik 11:ce51026d8702 648 tft.setCursor(115, 4);
BETZtechnik 11:ce51026d8702 649 tft.printf("%d", n2Pos);
BETZtechnik 11:ce51026d8702 650 tft.drawRect(78,2,74,18,BLACK);
BETZtechnik 11:ce51026d8702 651 }
BETZtechnik 11:ce51026d8702 652 lastNumNoz = numNoz;
BETZtechnik 11:ce51026d8702 653 }
BETZtechnik 11:ce51026d8702 654
BETZtechnik 11:ce51026d8702 655
BETZtechnik 11:ce51026d8702 656 if (twitch != lastTwitch) {
BETZtechnik 11:ce51026d8702 657 tft.setCursor(52, 50);
BETZtechnik 11:ce51026d8702 658 tft.setTextColor(BLACK);
BETZtechnik 11:ce51026d8702 659 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 660 tft.printf("%d", lastTwitch);
BETZtechnik 11:ce51026d8702 661 tft.setCursor(52, 50);
BETZtechnik 11:ce51026d8702 662 tft.setTextColor(GREEN);
BETZtechnik 11:ce51026d8702 663 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 664 tft.printf("%d", twitch);
BETZtechnik 11:ce51026d8702 665 dir=1;
BETZtechnik 11:ce51026d8702 666 device.printf("W");
BETZtechnik 11:ce51026d8702 667 device.printf("%d", twitch);
BETZtechnik 11:ce51026d8702 668 wait(0.05);
BETZtechnik 11:ce51026d8702 669 dir=0;
BETZtechnik 11:ce51026d8702 670 eeprom.write(currentToolNo +150, twitch); // store new twitch setting
BETZtechnik 11:ce51026d8702 671 lastN1Pos = 999; // trigger sending servo values to module
BETZtechnik 11:ce51026d8702 672 lastN2Pos = 999;
BETZtechnik 11:ce51026d8702 673 lastTwitch = twitch;
BETZtechnik 11:ce51026d8702 674 }
BETZtechnik 11:ce51026d8702 675
BETZtechnik 11:ce51026d8702 676 if (sync != lastSync) { //
BETZtechnik 11:ce51026d8702 677 tft.setCursor(52, 65);
BETZtechnik 11:ce51026d8702 678 tft.setTextColor(BLACK);
BETZtechnik 11:ce51026d8702 679 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 680 if (lastSync == 0) {
BETZtechnik 11:ce51026d8702 681 tft.printf("OFF");
BETZtechnik 11:ce51026d8702 682 }
BETZtechnik 11:ce51026d8702 683 if (lastSync == 1) {
BETZtechnik 11:ce51026d8702 684 tft.printf("ON");
BETZtechnik 11:ce51026d8702 685 }
BETZtechnik 11:ce51026d8702 686
BETZtechnik 11:ce51026d8702 687 tft.setCursor(52, 65);
BETZtechnik 11:ce51026d8702 688 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 689 if (sync == 0) {
BETZtechnik 11:ce51026d8702 690 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 691 tft.printf("OFF");
BETZtechnik 11:ce51026d8702 692 }
BETZtechnik 11:ce51026d8702 693 if (sync == 1) {
BETZtechnik 11:ce51026d8702 694 tft.setTextColor(GREEN);
BETZtechnik 11:ce51026d8702 695 tft.printf("ON");
BETZtechnik 11:ce51026d8702 696 }
BETZtechnik 11:ce51026d8702 697
BETZtechnik 11:ce51026d8702 698
BETZtechnik 11:ce51026d8702 699 eeprom.write(syncAddress, sync); // store new twitch setting
BETZtechnik 11:ce51026d8702 700 syncSpread = (n2Pos - n1Pos);
BETZtechnik 11:ce51026d8702 701
BETZtechnik 11:ce51026d8702 702 lastSync = sync;
BETZtechnik 11:ce51026d8702 703
BETZtechnik 11:ce51026d8702 704 }
BETZtechnik 11:ce51026d8702 705
BETZtechnik 11:ce51026d8702 706 if (n1Dir != lastN1Dir) { //
BETZtechnik 11:ce51026d8702 707 tft.setCursor(132, 50);
BETZtechnik 11:ce51026d8702 708 tft.setTextColor(BLACK);
BETZtechnik 11:ce51026d8702 709 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 710 if (lastN1Dir == 0) {
BETZtechnik 11:ce51026d8702 711 tft.printf("NOR");
BETZtechnik 11:ce51026d8702 712 }
BETZtechnik 11:ce51026d8702 713 if (lastN1Dir == 1) {
BETZtechnik 11:ce51026d8702 714 tft.printf("REV");
BETZtechnik 11:ce51026d8702 715 }
BETZtechnik 11:ce51026d8702 716 tft.setCursor(132, 50);
BETZtechnik 11:ce51026d8702 717 if (n1Dir == 0) {
BETZtechnik 11:ce51026d8702 718 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 719 tft.printf("NOR");
BETZtechnik 11:ce51026d8702 720 }
BETZtechnik 11:ce51026d8702 721 if (n1Dir == 1) {
BETZtechnik 11:ce51026d8702 722 tft.setTextColor(GREEN);
BETZtechnik 11:ce51026d8702 723 tft.printf("REV");
BETZtechnik 11:ce51026d8702 724 }
BETZtechnik 11:ce51026d8702 725 eeprom.write(n1DirAddress, n1Dir); // store new twitch setting
BETZtechnik 11:ce51026d8702 726 lastN1Dir = n1Dir;
BETZtechnik 11:ce51026d8702 727
BETZtechnik 11:ce51026d8702 728 dir=1;
BETZtechnik 11:ce51026d8702 729 device.printf("D1");
BETZtechnik 11:ce51026d8702 730 device.printf("%d", n1Dir);
BETZtechnik 11:ce51026d8702 731 wait(0.05);
BETZtechnik 11:ce51026d8702 732 dir=0;
BETZtechnik 11:ce51026d8702 733
BETZtechnik 11:ce51026d8702 734 }
BETZtechnik 11:ce51026d8702 735
BETZtechnik 11:ce51026d8702 736 if (n2Dir != lastN2Dir) { //
BETZtechnik 11:ce51026d8702 737 tft.setCursor(132, 65);
BETZtechnik 11:ce51026d8702 738 tft.setTextColor(BLACK);
BETZtechnik 11:ce51026d8702 739 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 740 if (lastN2Dir == 0) {
BETZtechnik 11:ce51026d8702 741 tft.printf("NOR");
BETZtechnik 11:ce51026d8702 742 }
BETZtechnik 11:ce51026d8702 743 if (lastN2Dir == 1) {
BETZtechnik 11:ce51026d8702 744 tft.printf("REV");
BETZtechnik 11:ce51026d8702 745 }
BETZtechnik 11:ce51026d8702 746 tft.setCursor(132, 65);
BETZtechnik 11:ce51026d8702 747 if (n2Dir == 0) {
BETZtechnik 11:ce51026d8702 748 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 749 tft.printf("NOR");
BETZtechnik 11:ce51026d8702 750 }
BETZtechnik 11:ce51026d8702 751 if (n2Dir == 1) {
BETZtechnik 11:ce51026d8702 752 tft.setTextColor(GREEN);
BETZtechnik 11:ce51026d8702 753 tft.printf("REV");
BETZtechnik 11:ce51026d8702 754 }
BETZtechnik 11:ce51026d8702 755 eeprom.write(n2DirAddress, n2Dir); // store new twitch setting
BETZtechnik 11:ce51026d8702 756 lastN2Dir = n2Dir;
BETZtechnik 11:ce51026d8702 757
BETZtechnik 11:ce51026d8702 758 dir=1;
BETZtechnik 11:ce51026d8702 759 device.printf("D2");
BETZtechnik 11:ce51026d8702 760 device.printf("%d", n2Dir);
BETZtechnik 11:ce51026d8702 761 wait(0.05);
BETZtechnik 11:ce51026d8702 762 dir=0;
BETZtechnik 11:ce51026d8702 763
BETZtechnik 11:ce51026d8702 764 }
BETZtechnik 13:83cb3b5c69de 765
BETZtechnik 13:83cb3b5c69de 766 if (autoMode != lastAutoMode) { //
BETZtechnik 13:83cb3b5c69de 767 tft.setCursor(52, 80);
BETZtechnik 13:83cb3b5c69de 768 tft.setTextColor(BLACK);
BETZtechnik 13:83cb3b5c69de 769 tft.setTextSize(1);
BETZtechnik 13:83cb3b5c69de 770 if (lastAutoMode == 0) {
BETZtechnik 13:83cb3b5c69de 771 tft.printf("OFF");
BETZtechnik 13:83cb3b5c69de 772 }
BETZtechnik 13:83cb3b5c69de 773 if (lastAutoMode == 1) {
BETZtechnik 13:83cb3b5c69de 774 tft.printf("X7a");
BETZtechnik 13:83cb3b5c69de 775 }
BETZtechnik 13:83cb3b5c69de 776 if (lastAutoMode == 2) {
BETZtechnik 13:83cb3b5c69de 777 tft.printf("Pul");
BETZtechnik 13:83cb3b5c69de 778 }
BETZtechnik 13:83cb3b5c69de 779
BETZtechnik 13:83cb3b5c69de 780 tft.setCursor(52, 80);
BETZtechnik 13:83cb3b5c69de 781 if (autoMode == 0) {
BETZtechnik 13:83cb3b5c69de 782 tft.setTextColor(WHITE);
BETZtechnik 13:83cb3b5c69de 783 tft.printf("OFF");
BETZtechnik 13:83cb3b5c69de 784 }
BETZtechnik 13:83cb3b5c69de 785 if (autoMode == 1) {
BETZtechnik 13:83cb3b5c69de 786 tft.setTextColor(GREEN);
BETZtechnik 13:83cb3b5c69de 787 tft.printf("X7a");
BETZtechnik 13:83cb3b5c69de 788 }
BETZtechnik 13:83cb3b5c69de 789 if (autoMode == 2) {
BETZtechnik 13:83cb3b5c69de 790 tft.setTextColor(GREEN);
BETZtechnik 13:83cb3b5c69de 791 tft.printf("Pul");
BETZtechnik 13:83cb3b5c69de 792 }
BETZtechnik 13:83cb3b5c69de 793 eeprom.write(autoModeAddress, autoMode); // store new twitch setting
BETZtechnik 13:83cb3b5c69de 794 lastAutoMode = autoMode;
BETZtechnik 13:83cb3b5c69de 795
BETZtechnik 13:83cb3b5c69de 796 dir=1;
BETZtechnik 13:83cb3b5c69de 797 device.printf("A"); //A for auto mode
BETZtechnik 13:83cb3b5c69de 798 device.printf("%d", autoMode); // send 0,1,2 etc.
BETZtechnik 13:83cb3b5c69de 799 wait(0.05);
BETZtechnik 13:83cb3b5c69de 800 dir=0;
BETZtechnik 13:83cb3b5c69de 801
BETZtechnik 13:83cb3b5c69de 802 }
BETZtechnik 13:83cb3b5c69de 803
BETZtechnik 13:83cb3b5c69de 804 if (aux2Mode != lastAux2Mode) { //
BETZtechnik 13:83cb3b5c69de 805 tft.setCursor(52, 95);
BETZtechnik 13:83cb3b5c69de 806 tft.setTextColor(BLACK);
BETZtechnik 13:83cb3b5c69de 807 tft.setTextSize(1);
BETZtechnik 13:83cb3b5c69de 808 if (lastAux2Mode == 0) {
BETZtechnik 13:83cb3b5c69de 809 tft.printf("OFF");
BETZtechnik 13:83cb3b5c69de 810 }
BETZtechnik 13:83cb3b5c69de 811 if (lastAux2Mode == 1) {
BETZtechnik 13:83cb3b5c69de 812 tft.printf("TWP");
BETZtechnik 13:83cb3b5c69de 813 }
BETZtechnik 13:83cb3b5c69de 814
BETZtechnik 13:83cb3b5c69de 815
BETZtechnik 13:83cb3b5c69de 816 tft.setCursor(52, 95);
BETZtechnik 13:83cb3b5c69de 817 if (aux2Mode == 0) {
BETZtechnik 13:83cb3b5c69de 818 tft.setTextColor(WHITE);
BETZtechnik 13:83cb3b5c69de 819 tft.printf("OFF");
BETZtechnik 13:83cb3b5c69de 820 }
BETZtechnik 13:83cb3b5c69de 821 if (aux2Mode == 1) {
BETZtechnik 13:83cb3b5c69de 822 tft.setTextColor(GREEN);
BETZtechnik 13:83cb3b5c69de 823 tft.printf("TWP");
BETZtechnik 13:83cb3b5c69de 824 }
BETZtechnik 13:83cb3b5c69de 825
BETZtechnik 13:83cb3b5c69de 826 eeprom.write(aux2ModeAddress, aux2Mode); // store new twitch setting
BETZtechnik 13:83cb3b5c69de 827 lastAux2Mode = aux2Mode;
BETZtechnik 13:83cb3b5c69de 828
BETZtechnik 13:83cb3b5c69de 829 dir=1;
BETZtechnik 13:83cb3b5c69de 830 device.printf("I"); //I for input
BETZtechnik 13:83cb3b5c69de 831 device.printf("%d", aux2Mode); // send 0,1,2 etc.
BETZtechnik 13:83cb3b5c69de 832 wait(0.05);
BETZtechnik 13:83cb3b5c69de 833 dir=0;
BETZtechnik 13:83cb3b5c69de 834
BETZtechnik 13:83cb3b5c69de 835 }
BETZtechnik 13:83cb3b5c69de 836
BETZtechnik 11:ce51026d8702 837
BETZtechnik 11:ce51026d8702 838 if (version != lastVersion) { //
BETZtechnik 11:ce51026d8702 839 tft.setCursor(132, 80);
BETZtechnik 11:ce51026d8702 840 tft.setTextColor(BLACK);
BETZtechnik 11:ce51026d8702 841 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 842 if (lastVersion == 0) {
BETZtechnik 11:ce51026d8702 843 tft.printf("BAS");
BETZtechnik 11:ce51026d8702 844 }
BETZtechnik 11:ce51026d8702 845 if (lastVersion == 1) {
BETZtechnik 11:ce51026d8702 846 tft.printf("PRO");
BETZtechnik 11:ce51026d8702 847 }
BETZtechnik 11:ce51026d8702 848 tft.setCursor(132, 80);
BETZtechnik 11:ce51026d8702 849 if (version == 0) {
BETZtechnik 11:ce51026d8702 850 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 851 tft.setTextSize(1);
BETZtechnik 11:ce51026d8702 852 tft.printf("BAS");
BETZtechnik 11:ce51026d8702 853 }
BETZtechnik 11:ce51026d8702 854 if (version == 1) {
BETZtechnik 11:ce51026d8702 855 tft.setTextColor(RED);
BETZtechnik 11:ce51026d8702 856 tft.printf("PRO");
BETZtechnik 11:ce51026d8702 857 }
BETZtechnik 11:ce51026d8702 858 eeprom.write(versionAddress, version); // store new twitch setting
BETZtechnik 11:ce51026d8702 859 lastVersion = version;
BETZtechnik 11:ce51026d8702 860 }
BETZtechnik 6:84ea3ec0660d 861
BETZtechnik 6:84ea3ec0660d 862 // ************* Rectangles for identifying active selection *****************************
BETZtechnik 6:84ea3ec0660d 863
BETZtechnik 11:ce51026d8702 864 if (count != lastCount) {
BETZtechnik 11:ce51026d8702 865
BETZtechnik 11:ce51026d8702 866 if (count ==0) {
BETZtechnik 11:ce51026d8702 867 Enc.Set(n1Pos);
BETZtechnik 11:ce51026d8702 868 lastN1Pos = n1Pos; ////*******************************2019-09-11 WAS FIX FOR SYNC REV RST = 90
BETZtechnik 11:ce51026d8702 869 }
BETZtechnik 11:ce51026d8702 870
BETZtechnik 11:ce51026d8702 871 else if (count == 1) {
BETZtechnik 11:ce51026d8702 872 Enc.Set(n2Pos);
BETZtechnik 11:ce51026d8702 873 }
BETZtechnik 11:ce51026d8702 874
BETZtechnik 11:ce51026d8702 875 else if (count == 2) {
BETZtechnik 11:ce51026d8702 876 Enc.Set(currentToolNo);
BETZtechnik 11:ce51026d8702 877 }
BETZtechnik 11:ce51026d8702 878
BETZtechnik 11:ce51026d8702 879 else if (count == 3) {
BETZtechnik 11:ce51026d8702 880 Enc.Set(twitch);
BETZtechnik 11:ce51026d8702 881 }
BETZtechnik 11:ce51026d8702 882
BETZtechnik 11:ce51026d8702 883 else if (count == 4) {
BETZtechnik 11:ce51026d8702 884 Enc.Set(sync);
BETZtechnik 11:ce51026d8702 885 }
BETZtechnik 13:83cb3b5c69de 886
BETZtechnik 13:83cb3b5c69de 887 else if (count == 5) {
BETZtechnik 13:83cb3b5c69de 888 Enc.Set(autoMode);
BETZtechnik 13:83cb3b5c69de 889 }
BETZtechnik 13:83cb3b5c69de 890
BETZtechnik 13:83cb3b5c69de 891 else if (count == 6) {
BETZtechnik 13:83cb3b5c69de 892 Enc.Set(aux2Mode);
BETZtechnik 13:83cb3b5c69de 893 }
BETZtechnik 11:ce51026d8702 894
BETZtechnik 11:ce51026d8702 895 else if (count == 8) {
BETZtechnik 11:ce51026d8702 896 Enc.Set(n1Dir);
BETZtechnik 11:ce51026d8702 897 }
BETZtechnik 11:ce51026d8702 898
BETZtechnik 11:ce51026d8702 899 else if (count == 9) {
BETZtechnik 11:ce51026d8702 900 Enc.Set(n2Dir);
BETZtechnik 11:ce51026d8702 901 }
BETZtechnik 11:ce51026d8702 902
BETZtechnik 11:ce51026d8702 903 else if (count == 10) {
BETZtechnik 11:ce51026d8702 904 Enc.Set(version);
BETZtechnik 11:ce51026d8702 905 }
BETZtechnik 6:84ea3ec0660d 906
BETZtechnik 11:ce51026d8702 907 else if (count == 11) {
BETZtechnik 11:ce51026d8702 908 Enc.Set(numTools);
BETZtechnik 11:ce51026d8702 909 }
BETZtechnik 11:ce51026d8702 910
BETZtechnik 11:ce51026d8702 911 else if (count == 12) {
BETZtechnik 11:ce51026d8702 912 Enc.Set(numNoz);
BETZtechnik 11:ce51026d8702 913 }
BETZtechnik 11:ce51026d8702 914
BETZtechnik 11:ce51026d8702 915
BETZtechnik 11:ce51026d8702 916
BETZtechnik 11:ce51026d8702 917 // clear old boxes (white or black)
BETZtechnik 11:ce51026d8702 918 if (lastCount == 0) {
BETZtechnik 11:ce51026d8702 919 tft.drawRect(2,2,74,18,WHITE);
BETZtechnik 11:ce51026d8702 920 }
BETZtechnik 11:ce51026d8702 921
BETZtechnik 11:ce51026d8702 922 else if ((lastCount == 1) && (numNoz == 2)) {
BETZtechnik 11:ce51026d8702 923 tft.drawRect(78,2,74,18,WHITE);
BETZtechnik 11:ce51026d8702 924 }
BETZtechnik 11:ce51026d8702 925
BETZtechnik 11:ce51026d8702 926 else if (lastCount == 2) {
BETZtechnik 11:ce51026d8702 927 tft.drawRect(20,26,28,18,BLACK);
BETZtechnik 11:ce51026d8702 928 }
BETZtechnik 11:ce51026d8702 929
BETZtechnik 11:ce51026d8702 930 else if (lastCount == 3) {
BETZtechnik 11:ce51026d8702 931 tft.drawRect(50,48,20,12,BLACK);
BETZtechnik 11:ce51026d8702 932 }
BETZtechnik 11:ce51026d8702 933
BETZtechnik 11:ce51026d8702 934 else if (lastCount == 4) {
BETZtechnik 11:ce51026d8702 935 tft.drawRect(50,63,20,12,BLACK);
BETZtechnik 11:ce51026d8702 936 }
BETZtechnik 11:ce51026d8702 937
BETZtechnik 11:ce51026d8702 938 else if (lastCount == 5) {
BETZtechnik 11:ce51026d8702 939 tft.drawRect(50,78,20,12,BLACK);
BETZtechnik 11:ce51026d8702 940 }
BETZtechnik 11:ce51026d8702 941
BETZtechnik 11:ce51026d8702 942 else if (lastCount == 6) {
BETZtechnik 11:ce51026d8702 943 tft.drawRect(50,93,20,12,BLACK);
BETZtechnik 11:ce51026d8702 944 }
BETZtechnik 6:84ea3ec0660d 945
BETZtechnik 11:ce51026d8702 946 else if (lastCount == 7) {
BETZtechnik 11:ce51026d8702 947 tft.drawRect(50,108,20,12,BLACK);
BETZtechnik 11:ce51026d8702 948 }
BETZtechnik 11:ce51026d8702 949
BETZtechnik 11:ce51026d8702 950 else if (lastCount == 8) {
BETZtechnik 11:ce51026d8702 951 tft.drawRect(130,48,20,12,BLACK);
BETZtechnik 11:ce51026d8702 952 }
BETZtechnik 11:ce51026d8702 953
BETZtechnik 11:ce51026d8702 954 else if (lastCount == 9) {
BETZtechnik 11:ce51026d8702 955 tft.drawRect(130,63,20,12,BLACK);
BETZtechnik 11:ce51026d8702 956 }
BETZtechnik 11:ce51026d8702 957
BETZtechnik 11:ce51026d8702 958 else if (lastCount == 10) {
BETZtechnik 11:ce51026d8702 959 tft.drawRect(130,78,20,12,BLACK);
BETZtechnik 11:ce51026d8702 960 }
BETZtechnik 6:84ea3ec0660d 961
BETZtechnik 11:ce51026d8702 962 else if (lastCount == 11) {
BETZtechnik 11:ce51026d8702 963 tft.drawRect(130,93,20,12,BLACK);
BETZtechnik 11:ce51026d8702 964 }
BETZtechnik 11:ce51026d8702 965
BETZtechnik 11:ce51026d8702 966 else if (lastCount == 12) {
BETZtechnik 11:ce51026d8702 967 tft.drawRect(130,108,20,12,BLACK);
BETZtechnik 11:ce51026d8702 968 }
BETZtechnik 11:ce51026d8702 969
BETZtechnik 11:ce51026d8702 970 // Set new box
BETZtechnik 6:84ea3ec0660d 971
BETZtechnik 11:ce51026d8702 972 if (count == 0) { // N1 adjust
BETZtechnik 11:ce51026d8702 973 tft.drawRect(2,2,74,18,GREEN);
BETZtechnik 11:ce51026d8702 974 }
BETZtechnik 11:ce51026d8702 975
BETZtechnik 11:ce51026d8702 976 else if ((count == 1) && (numNoz == 2)) { // N2 adjust
BETZtechnik 11:ce51026d8702 977 tft.drawRect(78,2,74,18,GREEN);
BETZtechnik 11:ce51026d8702 978 }
BETZtechnik 11:ce51026d8702 979
BETZtechnik 11:ce51026d8702 980 else if (count == 2) {
BETZtechnik 11:ce51026d8702 981 tft.drawRect(20,26,28,18,GREEN);
BETZtechnik 11:ce51026d8702 982 }
BETZtechnik 6:84ea3ec0660d 983
BETZtechnik 11:ce51026d8702 984 else if (count == 3) {
BETZtechnik 11:ce51026d8702 985 tft.drawRect(50,48,20,12,GREEN);
BETZtechnik 11:ce51026d8702 986 }
BETZtechnik 6:84ea3ec0660d 987
BETZtechnik 11:ce51026d8702 988 else if (count == 4) {
BETZtechnik 11:ce51026d8702 989 tft.drawRect(50,63,20,12,GREEN);
BETZtechnik 11:ce51026d8702 990 }
BETZtechnik 6:84ea3ec0660d 991
BETZtechnik 11:ce51026d8702 992 else if (count == 5) {
BETZtechnik 11:ce51026d8702 993 tft.drawRect(50,78,20,12,GREEN);
BETZtechnik 11:ce51026d8702 994 }
BETZtechnik 6:84ea3ec0660d 995
BETZtechnik 11:ce51026d8702 996 else if (count == 6) {
BETZtechnik 11:ce51026d8702 997 tft.drawRect(50,93,20,12,GREEN);
BETZtechnik 11:ce51026d8702 998 }
BETZtechnik 6:84ea3ec0660d 999
BETZtechnik 11:ce51026d8702 1000 else if (count == 7) {
BETZtechnik 11:ce51026d8702 1001 tft.drawRect(50,108,20,12,GREEN);
BETZtechnik 11:ce51026d8702 1002 }
BETZtechnik 6:84ea3ec0660d 1003
BETZtechnik 11:ce51026d8702 1004 else if (count == 8) {
BETZtechnik 11:ce51026d8702 1005 tft.drawRect(130,48,20,12,GREEN);
BETZtechnik 11:ce51026d8702 1006 }
BETZtechnik 6:84ea3ec0660d 1007
BETZtechnik 11:ce51026d8702 1008 else if (count == 9) {
BETZtechnik 11:ce51026d8702 1009 tft.drawRect(130,63,20,12,GREEN);
BETZtechnik 11:ce51026d8702 1010 }
BETZtechnik 6:84ea3ec0660d 1011
BETZtechnik 11:ce51026d8702 1012 else if (count == 10) {
BETZtechnik 11:ce51026d8702 1013 tft.drawRect(130,78,20,12,GREEN);
BETZtechnik 11:ce51026d8702 1014 }
BETZtechnik 6:84ea3ec0660d 1015
BETZtechnik 11:ce51026d8702 1016 else if (count == 11) {
BETZtechnik 11:ce51026d8702 1017 tft.drawRect(130,93,20,12,GREEN);
BETZtechnik 11:ce51026d8702 1018 }
BETZtechnik 6:84ea3ec0660d 1019
BETZtechnik 11:ce51026d8702 1020 else if (count == 12) {
BETZtechnik 11:ce51026d8702 1021 tft.drawRect(130,108,20,12,GREEN);
BETZtechnik 11:ce51026d8702 1022 }
BETZtechnik 6:84ea3ec0660d 1023
BETZtechnik 11:ce51026d8702 1024 lastCount = count;
BETZtechnik 11:ce51026d8702 1025 }
BETZtechnik 6:84ea3ec0660d 1026
BETZtechnik 6:84ea3ec0660d 1027
BETZtechnik 6:84ea3ec0660d 1028
BETZtechnik 6:84ea3ec0660d 1029
BETZtechnik 11:ce51026d8702 1030
BETZtechnik 11:ce51026d8702 1031 //****************** ENCODER ACTIONS ************************************************
BETZtechnik 11:ce51026d8702 1032 if (count == 0) { // knob controls servo value
BETZtechnik 11:ce51026d8702 1033
BETZtechnik 11:ce51026d8702 1034 if (n1Pos != Enc.Get()) {
BETZtechnik 11:ce51026d8702 1035 //n1Pos = Enc.Get(); 2019-09-12
BETZtechnik 11:ce51026d8702 1036 if (sync == 0 && n1Dir ==0) { // n1 fwd
BETZtechnik 11:ce51026d8702 1037 n1Pos = Enc.Get();
BETZtechnik 11:ce51026d8702 1038 }
BETZtechnik 11:ce51026d8702 1039
BETZtechnik 11:ce51026d8702 1040 if (sync == 0 && n1Dir ==1) { // n1 rev
BETZtechnik 11:ce51026d8702 1041 n1Pos = n1Pos + (n1Pos - Enc.Get());
BETZtechnik 11:ce51026d8702 1042 Enc.Set(n1Pos);
BETZtechnik 11:ce51026d8702 1043 }
BETZtechnik 11:ce51026d8702 1044
BETZtechnik 11:ce51026d8702 1045
BETZtechnik 11:ce51026d8702 1046 if (n1Pos > 90) {
BETZtechnik 11:ce51026d8702 1047 n1Pos = 90;
BETZtechnik 11:ce51026d8702 1048 Enc.Set(90);
BETZtechnik 11:ce51026d8702 1049 }
BETZtechnik 11:ce51026d8702 1050
BETZtechnik 11:ce51026d8702 1051 if (n1Pos < -90) {
BETZtechnik 11:ce51026d8702 1052 n1Pos = -90;
BETZtechnik 11:ce51026d8702 1053 Enc.Set(-90);
BETZtechnik 11:ce51026d8702 1054 }
BETZtechnik 11:ce51026d8702 1055
BETZtechnik 11:ce51026d8702 1056 //***
BETZtechnik 11:ce51026d8702 1057
BETZtechnik 11:ce51026d8702 1058 if (sync == 1 && n1Dir == 0 && n2Dir == 0) { // PASS 2019-09-12
BETZtechnik 11:ce51026d8702 1059 encoderMove = (Enc.Get() - n1Pos); // save direction change, positive or negative
BETZtechnik 11:ce51026d8702 1060 if (encoderMove > 0 && n1Pos < 90 && n2Pos <90) { // Move is positive // stop both nozzles once ONE reaches limit.
BETZtechnik 11:ce51026d8702 1061 n1Pos = Enc.Get();
BETZtechnik 11:ce51026d8702 1062 n2Pos = n2Pos + encoderMove;
BETZtechnik 11:ce51026d8702 1063 encoderMove =0;
BETZtechnik 11:ce51026d8702 1064 //Enc.Set(n1Pos);
BETZtechnik 11:ce51026d8702 1065 }
BETZtechnik 11:ce51026d8702 1066
BETZtechnik 11:ce51026d8702 1067 if (encoderMove < 0 && n1Pos > -90 && n2Pos >-90) { // Move is positive // stop both nozzles once ONE reaches limit.
BETZtechnik 11:ce51026d8702 1068 n1Pos = Enc.Get();
BETZtechnik 11:ce51026d8702 1069 n2Pos = n2Pos + encoderMove;
BETZtechnik 11:ce51026d8702 1070 encoderMove =0;
BETZtechnik 11:ce51026d8702 1071 // Enc.Set(n1Pos);
BETZtechnik 11:ce51026d8702 1072 }
BETZtechnik 11:ce51026d8702 1073 Enc.Set(n1Pos); // reset encoder so it doesnt store counts past +90/ -90
BETZtechnik 11:ce51026d8702 1074
BETZtechnik 11:ce51026d8702 1075 }
BETZtechnik 11:ce51026d8702 1076
BETZtechnik 11:ce51026d8702 1077 if (sync == 1 && n1Dir == 1 && n2Dir == 0) {
BETZtechnik 11:ce51026d8702 1078 encoderMove = ( n1Pos - Enc.Get()); // save direction change, positive or negative
BETZtechnik 11:ce51026d8702 1079 if (encoderMove > 0 && n1Pos > -90 && n2Pos <90) { // Move is positive // stop both nozzles once ONE reaches limit.
BETZtechnik 11:ce51026d8702 1080 n1Pos = (n1Pos + encoderMove);
BETZtechnik 11:ce51026d8702 1081 Enc.Set(n1Pos);
BETZtechnik 11:ce51026d8702 1082 n2Pos = (n2Pos - encoderMove);
BETZtechnik 11:ce51026d8702 1083 encoderMove=0;
BETZtechnik 11:ce51026d8702 1084 }
BETZtechnik 6:84ea3ec0660d 1085
BETZtechnik 11:ce51026d8702 1086 if (encoderMove < 0 && n1Pos < 90 && n2Pos > -90) { // Move is positive // stop both nozzles once ONE reaches limit.
BETZtechnik 11:ce51026d8702 1087 n1Pos = (n1Pos + encoderMove);
BETZtechnik 11:ce51026d8702 1088 Enc.Set(n1Pos);
BETZtechnik 11:ce51026d8702 1089 n2Pos = (n2Pos - encoderMove);
BETZtechnik 11:ce51026d8702 1090 encoderMove=0;
BETZtechnik 11:ce51026d8702 1091 }
BETZtechnik 11:ce51026d8702 1092 Enc.Set(n1Pos); // reset encoder so it doesnt store counts past +90/ -90
BETZtechnik 11:ce51026d8702 1093
BETZtechnik 11:ce51026d8702 1094 }
BETZtechnik 11:ce51026d8702 1095
BETZtechnik 11:ce51026d8702 1096
BETZtechnik 11:ce51026d8702 1097 if (sync == 1 && n1Dir == 0 && n2Dir == 1) {
BETZtechnik 11:ce51026d8702 1098 encoderMove = (Enc.Get() - n1Pos); // save direction change, positive or negative
BETZtechnik 11:ce51026d8702 1099 if (encoderMove < 0 && n1Pos > -90 && n2Pos <90) { // Move is positive // stop both nozzles once ONE reaches limit.
BETZtechnik 11:ce51026d8702 1100 n1Pos = (n1Pos + encoderMove);
BETZtechnik 11:ce51026d8702 1101 Enc.Set(n1Pos);
BETZtechnik 11:ce51026d8702 1102 n2Pos = (n2Pos - encoderMove);
BETZtechnik 11:ce51026d8702 1103 encoderMove=0;
BETZtechnik 11:ce51026d8702 1104 }
BETZtechnik 11:ce51026d8702 1105
BETZtechnik 11:ce51026d8702 1106 if (encoderMove > 0 && n1Pos < 90 && n2Pos > -90) { // Move is positive // stop both nozzles once ONE reaches limit.
BETZtechnik 11:ce51026d8702 1107 n1Pos = (n1Pos + encoderMove);
BETZtechnik 11:ce51026d8702 1108 Enc.Set(n1Pos);
BETZtechnik 11:ce51026d8702 1109 n2Pos = (n2Pos - encoderMove);
BETZtechnik 11:ce51026d8702 1110 encoderMove=0;
BETZtechnik 11:ce51026d8702 1111 }
BETZtechnik 11:ce51026d8702 1112 Enc.Set(n1Pos); // reset encoder so it doesnt store counts past +90/ -90
BETZtechnik 11:ce51026d8702 1113 }
BETZtechnik 11:ce51026d8702 1114
BETZtechnik 11:ce51026d8702 1115
BETZtechnik 1:e8452b75301e 1116
BETZtechnik 11:ce51026d8702 1117 if (sync == 1 && n1Dir == 1 && n2Dir == 1) {
BETZtechnik 11:ce51026d8702 1118 encoderMove = (Enc.Get() - n1Pos); // save direction change, positive or negative
BETZtechnik 11:ce51026d8702 1119 if (encoderMove > 0 && n1Pos > -90 && n2Pos >-90) { // Move is positive // stop both nozzles once ONE reaches limit.
BETZtechnik 11:ce51026d8702 1120 n1Pos = (n1Pos - encoderMove);
BETZtechnik 11:ce51026d8702 1121 Enc.Set(n1Pos);
BETZtechnik 11:ce51026d8702 1122 n2Pos = (n2Pos - encoderMove);
BETZtechnik 11:ce51026d8702 1123 encoderMove=0;
BETZtechnik 11:ce51026d8702 1124 }
BETZtechnik 1:e8452b75301e 1125
BETZtechnik 11:ce51026d8702 1126 if (encoderMove < 0 && n1Pos < 90 && n2Pos < 90) { // Move is positive // stop both nozzles once ONE reaches limit.
BETZtechnik 11:ce51026d8702 1127 n1Pos = (n1Pos - encoderMove);
BETZtechnik 11:ce51026d8702 1128 Enc.Set(n1Pos);
BETZtechnik 11:ce51026d8702 1129 n2Pos = (n2Pos - encoderMove);
BETZtechnik 11:ce51026d8702 1130 encoderMove=0;
BETZtechnik 11:ce51026d8702 1131 }
BETZtechnik 11:ce51026d8702 1132 Enc.Set(n1Pos); // reset encoder so it doesnt store counts past +90/ -90
BETZtechnik 11:ce51026d8702 1133 }
BETZtechnik 11:ce51026d8702 1134
BETZtechnik 6:84ea3ec0660d 1135 }
BETZtechnik 11:ce51026d8702 1136 if (n1Pos > 90) {
BETZtechnik 11:ce51026d8702 1137 n1Pos =90;
BETZtechnik 11:ce51026d8702 1138 }
BETZtechnik 11:ce51026d8702 1139 if (n1Pos < -90) {
BETZtechnik 11:ce51026d8702 1140 n1Pos = -90;
BETZtechnik 6:84ea3ec0660d 1141 }
BETZtechnik 11:ce51026d8702 1142 if (n2Pos > 90) {
BETZtechnik 11:ce51026d8702 1143 n2Pos =90;
BETZtechnik 6:84ea3ec0660d 1144 }
BETZtechnik 11:ce51026d8702 1145 if (n2Pos < -90) {
BETZtechnik 11:ce51026d8702 1146 n2Pos = -90;
BETZtechnik 11:ce51026d8702 1147 }
BETZtechnik 11:ce51026d8702 1148 }
BETZtechnik 1:e8452b75301e 1149
BETZtechnik 0:09419d572e90 1150
BETZtechnik 11:ce51026d8702 1151 //***************************
BETZtechnik 11:ce51026d8702 1152 if (count == 1) { // knob controls servo value
BETZtechnik 11:ce51026d8702 1153
BETZtechnik 11:ce51026d8702 1154 if (n2Pos != Enc.Get()) {
BETZtechnik 11:ce51026d8702 1155 encoderMove = (Enc.Get() - n2Pos); // save direction change, positive or negative
BETZtechnik 11:ce51026d8702 1156
BETZtechnik 11:ce51026d8702 1157 if (n2Dir == 0 && encoderMove >0 && n2Pos < 90){ // normal direction
BETZtechnik 11:ce51026d8702 1158 n2Pos = n2Pos + encoderMove;
BETZtechnik 11:ce51026d8702 1159 encoderMove=0;
BETZtechnik 11:ce51026d8702 1160 }
BETZtechnik 11:ce51026d8702 1161 if (n2Dir == 0 && encoderMove <0 && n2Pos > -90){ // normal direction
BETZtechnik 11:ce51026d8702 1162 n2Pos = n2Pos + encoderMove;
BETZtechnik 11:ce51026d8702 1163 encoderMove=0;
BETZtechnik 11:ce51026d8702 1164 }
BETZtechnik 1:e8452b75301e 1165
BETZtechnik 11:ce51026d8702 1166 if (n2Dir == 1 && encoderMove <0 && n2Pos < 90){ // reverse direction
BETZtechnik 11:ce51026d8702 1167 n2Pos = n2Pos - encoderMove;
BETZtechnik 11:ce51026d8702 1168 encoderMove=0;
BETZtechnik 11:ce51026d8702 1169 }
BETZtechnik 11:ce51026d8702 1170 if (n2Dir == 1 && encoderMove >0 && n2Pos > -90){ // reverse direction
BETZtechnik 11:ce51026d8702 1171 n2Pos = n2Pos - encoderMove;
BETZtechnik 11:ce51026d8702 1172 encoderMove=0;
BETZtechnik 11:ce51026d8702 1173 }
BETZtechnik 11:ce51026d8702 1174 Enc.Set(n2Pos); // reset encoder so it doesnt store counts past +90/ -90
BETZtechnik 11:ce51026d8702 1175 if (n2Pos > 90){
BETZtechnik 11:ce51026d8702 1176 n2Pos = 90;
BETZtechnik 11:ce51026d8702 1177 }
BETZtechnik 11:ce51026d8702 1178 if (n2Pos < -90){
BETZtechnik 11:ce51026d8702 1179 n2Pos = -90;
BETZtechnik 11:ce51026d8702 1180 }
BETZtechnik 10:dd8d89133b28 1181 }
BETZtechnik 10:dd8d89133b28 1182
BETZtechnik 11:ce51026d8702 1183 }
BETZtechnik 11:ce51026d8702 1184 //****************************
BETZtechnik 11:ce51026d8702 1185 if (count == 2) { //knob controls tool number
BETZtechnik 11:ce51026d8702 1186
BETZtechnik 11:ce51026d8702 1187 currentToolNo = Enc.Get();
BETZtechnik 11:ce51026d8702 1188 if (currentToolNo > numTools) {
BETZtechnik 11:ce51026d8702 1189 currentToolNo = numTools;
BETZtechnik 11:ce51026d8702 1190 }
BETZtechnik 11:ce51026d8702 1191 if (currentToolNo < 1) {
BETZtechnik 11:ce51026d8702 1192 currentToolNo = 1;
BETZtechnik 11:ce51026d8702 1193 Enc.Set(1);
BETZtechnik 11:ce51026d8702 1194 }
BETZtechnik 11:ce51026d8702 1195 }
BETZtechnik 11:ce51026d8702 1196 //****************************
BETZtechnik 11:ce51026d8702 1197 if (count == 3) { // Knob controls twitch setting
BETZtechnik 11:ce51026d8702 1198 twitch = Enc.Get();
BETZtechnik 11:ce51026d8702 1199 if (twitch < 0) {
BETZtechnik 11:ce51026d8702 1200 twitch = 0;
BETZtechnik 11:ce51026d8702 1201 Enc.Set(0);
BETZtechnik 11:ce51026d8702 1202 }
BETZtechnik 11:ce51026d8702 1203 if (twitch > 3) {
BETZtechnik 11:ce51026d8702 1204 twitch = 3;
BETZtechnik 11:ce51026d8702 1205 Enc.Set(3);
BETZtechnik 11:ce51026d8702 1206 }
BETZtechnik 0:09419d572e90 1207 }
BETZtechnik 11:ce51026d8702 1208 //****************************
BETZtechnik 11:ce51026d8702 1209 if (count == 4) { // Knob controls sync setting. 1=off, 2=sync, 3=rev
BETZtechnik 11:ce51026d8702 1210 sync = Enc.Get();
BETZtechnik 11:ce51026d8702 1211 if (sync < 0) {
BETZtechnik 11:ce51026d8702 1212 sync= 0;
BETZtechnik 11:ce51026d8702 1213 Enc.Set(0);
BETZtechnik 11:ce51026d8702 1214 }
BETZtechnik 11:ce51026d8702 1215 if (sync > 1) {
BETZtechnik 11:ce51026d8702 1216 sync = 1;
BETZtechnik 11:ce51026d8702 1217 Enc.Set(1);
BETZtechnik 11:ce51026d8702 1218 }
BETZtechnik 11:ce51026d8702 1219 }
BETZtechnik 11:ce51026d8702 1220 //****************************
BETZtechnik 13:83cb3b5c69de 1221 if (count == 5) { // Knob controls auto setting. 1=off, 2=sync, 3=rev
BETZtechnik 13:83cb3b5c69de 1222 autoMode = Enc.Get();
BETZtechnik 13:83cb3b5c69de 1223 if (autoMode < 0) {
BETZtechnik 13:83cb3b5c69de 1224 autoMode= 0;
BETZtechnik 13:83cb3b5c69de 1225 Enc.Set(0);
BETZtechnik 13:83cb3b5c69de 1226 }
BETZtechnik 13:83cb3b5c69de 1227 if (autoMode > 2) {
BETZtechnik 13:83cb3b5c69de 1228 autoMode = 2;
BETZtechnik 13:83cb3b5c69de 1229 Enc.Set(2);
BETZtechnik 13:83cb3b5c69de 1230 }
BETZtechnik 13:83cb3b5c69de 1231 }
BETZtechnik 13:83cb3b5c69de 1232
BETZtechnik 13:83cb3b5c69de 1233 //****************************
BETZtechnik 13:83cb3b5c69de 1234 if (count == 6) { // Knob controls auto setting. 1=off, 2=sync, 3=rev
BETZtechnik 13:83cb3b5c69de 1235 aux2Mode = Enc.Get();
BETZtechnik 13:83cb3b5c69de 1236 if (aux2Mode < 0) {
BETZtechnik 13:83cb3b5c69de 1237 aux2Mode= 0;
BETZtechnik 13:83cb3b5c69de 1238 Enc.Set(0);
BETZtechnik 13:83cb3b5c69de 1239 }
BETZtechnik 13:83cb3b5c69de 1240 if (aux2Mode > 1) {
BETZtechnik 13:83cb3b5c69de 1241 aux2Mode = 1;
BETZtechnik 13:83cb3b5c69de 1242 Enc.Set(1);
BETZtechnik 13:83cb3b5c69de 1243 }
BETZtechnik 13:83cb3b5c69de 1244 }
BETZtechnik 13:83cb3b5c69de 1245
BETZtechnik 13:83cb3b5c69de 1246
BETZtechnik 13:83cb3b5c69de 1247 //****************************
BETZtechnik 13:83cb3b5c69de 1248
BETZtechnik 11:ce51026d8702 1249 // 5,6,7 AUX?
BETZtechnik 11:ce51026d8702 1250 if (count == 8) { // knob controls the direction of rotation for N1
BETZtechnik 11:ce51026d8702 1251 n1Dir = Enc.Get();
BETZtechnik 0:09419d572e90 1252
BETZtechnik 11:ce51026d8702 1253 if (n1Dir > 1) {
BETZtechnik 11:ce51026d8702 1254 n1Dir = 1;
BETZtechnik 11:ce51026d8702 1255 Enc.Set(1);
BETZtechnik 11:ce51026d8702 1256 }
BETZtechnik 11:ce51026d8702 1257
BETZtechnik 11:ce51026d8702 1258 if (n1Dir < 0) {
BETZtechnik 11:ce51026d8702 1259 n1Dir =0;
BETZtechnik 11:ce51026d8702 1260 Enc.Set(0);
BETZtechnik 11:ce51026d8702 1261 }
BETZtechnik 1:e8452b75301e 1262 }
BETZtechnik 11:ce51026d8702 1263 //****************************
BETZtechnik 11:ce51026d8702 1264 if (count == 9) { // knob controls the direction of rotation for N2
BETZtechnik 11:ce51026d8702 1265 n2Dir = Enc.Get();
BETZtechnik 11:ce51026d8702 1266
BETZtechnik 11:ce51026d8702 1267 if (n2Dir > 1) {
BETZtechnik 11:ce51026d8702 1268 n2Dir = 1;
BETZtechnik 11:ce51026d8702 1269 Enc.Set(1);
BETZtechnik 11:ce51026d8702 1270 }
BETZtechnik 0:09419d572e90 1271
BETZtechnik 11:ce51026d8702 1272 if (n2Dir < 0) {
BETZtechnik 11:ce51026d8702 1273 n2Dir =0;
BETZtechnik 11:ce51026d8702 1274 Enc.Set(0);
BETZtechnik 11:ce51026d8702 1275 }
BETZtechnik 6:84ea3ec0660d 1276 }
BETZtechnik 11:ce51026d8702 1277 //****************************
BETZtechnik 11:ce51026d8702 1278 if (count == 10) { // knob controls the version
BETZtechnik 11:ce51026d8702 1279 version = Enc.Get();
BETZtechnik 11:ce51026d8702 1280
BETZtechnik 11:ce51026d8702 1281 if (version > 1) {
BETZtechnik 11:ce51026d8702 1282 version = 1;
BETZtechnik 11:ce51026d8702 1283 Enc.Set(1);
BETZtechnik 11:ce51026d8702 1284 }
BETZtechnik 1:e8452b75301e 1285
BETZtechnik 11:ce51026d8702 1286 if (version < 0) {
BETZtechnik 11:ce51026d8702 1287 version =0;
BETZtechnik 11:ce51026d8702 1288 Enc.Set(0);
BETZtechnik 11:ce51026d8702 1289 }
BETZtechnik 6:84ea3ec0660d 1290 }
BETZtechnik 11:ce51026d8702 1291 //****************************
BETZtechnik 11:ce51026d8702 1292 if (count == 11) { //knob controls tool number
BETZtechnik 11:ce51026d8702 1293 numTools = Enc.Get();
BETZtechnik 11:ce51026d8702 1294 if (numTools > 50) {
BETZtechnik 11:ce51026d8702 1295 numTools = 50;
BETZtechnik 11:ce51026d8702 1296 Enc.Set(50);
BETZtechnik 11:ce51026d8702 1297 }
BETZtechnik 11:ce51026d8702 1298 if (numTools < 1) {
BETZtechnik 11:ce51026d8702 1299 numTools = 1;
BETZtechnik 11:ce51026d8702 1300 Enc.Set(1);
BETZtechnik 11:ce51026d8702 1301 }
BETZtechnik 6:84ea3ec0660d 1302 }
BETZtechnik 11:ce51026d8702 1303 //****************************
BETZtechnik 11:ce51026d8702 1304 if (count == 12) { //knob controls tool number
BETZtechnik 11:ce51026d8702 1305 numNoz = Enc.Get();
BETZtechnik 11:ce51026d8702 1306 if (numNoz> 2) {
BETZtechnik 11:ce51026d8702 1307 numNoz = 2;
BETZtechnik 11:ce51026d8702 1308 Enc.Set(2);
BETZtechnik 11:ce51026d8702 1309 }
BETZtechnik 11:ce51026d8702 1310 if (numNoz < 1) {
BETZtechnik 11:ce51026d8702 1311 numNoz = 1;
BETZtechnik 11:ce51026d8702 1312 Enc.Set(1);
BETZtechnik 11:ce51026d8702 1313 }
BETZtechnik 6:84ea3ec0660d 1314 }
BETZtechnik 6:84ea3ec0660d 1315
BETZtechnik 6:84ea3ec0660d 1316
BETZtechnik 1:e8452b75301e 1317
BETZtechnik 1:e8452b75301e 1318 //**************************** RS485 link ***************************************
BETZtechnik 4:d3c19705042b 1319
BETZtechnik 11:ce51026d8702 1320 while (device.readable()) {
BETZtechnik 11:ce51026d8702 1321 c = device.getc();
BETZtechnik 11:ce51026d8702 1322
BETZtechnik 11:ce51026d8702 1323 if (c == 'T') { // Actual tool number sent over serial
BETZtechnik 11:ce51026d8702 1324
BETZtechnik 11:ce51026d8702 1325 index = 1;
BETZtechnik 11:ce51026d8702 1326 }
BETZtechnik 11:ce51026d8702 1327
BETZtechnik 11:ce51026d8702 1328
BETZtechnik 11:ce51026d8702 1329 if (c == 'M') { // magazine + or - sent over serial
BETZtechnik 11:ce51026d8702 1330 index = 5;
BETZtechnik 11:ce51026d8702 1331 }
BETZtechnik 13:83cb3b5c69de 1332
BETZtechnik 13:83cb3b5c69de 1333 if (c == 'X') { // magazine + or - sent over serial
BETZtechnik 13:83cb3b5c69de 1334 tft.setCursor(50, 30);
BETZtechnik 13:83cb3b5c69de 1335 tft.setTextColor(RED);
BETZtechnik 13:83cb3b5c69de 1336 tft.setTextSize(1.5);
BETZtechnik 13:83cb3b5c69de 1337 tft.printf("TWITCH HOLD");
BETZtechnik 13:83cb3b5c69de 1338 index=0;
BETZtechnik 13:83cb3b5c69de 1339 }
BETZtechnik 13:83cb3b5c69de 1340
BETZtechnik 13:83cb3b5c69de 1341 if (c == 'Y') { // magazine + or - sent over serial
BETZtechnik 13:83cb3b5c69de 1342 tft.setCursor(50, 30);
BETZtechnik 13:83cb3b5c69de 1343 tft.setTextColor(BLACK);
BETZtechnik 13:83cb3b5c69de 1344 tft.setTextSize(1.5);
BETZtechnik 13:83cb3b5c69de 1345 tft.printf("TWITCH HOLD");
BETZtechnik 13:83cb3b5c69de 1346 index=0;
BETZtechnik 13:83cb3b5c69de 1347 }
BETZtechnik 13:83cb3b5c69de 1348
BETZtechnik 2:bbbacfd62773 1349
BETZtechnik 11:ce51026d8702 1350 if (index == 1) {
BETZtechnik 11:ce51026d8702 1351 c = device.getc();
BETZtechnik 11:ce51026d8702 1352 if (c == '1') { // hundreds place to know we are sending 3 digits
BETZtechnik 11:ce51026d8702 1353 index = 2;
BETZtechnik 11:ce51026d8702 1354 }
BETZtechnik 11:ce51026d8702 1355 }
BETZtechnik 13:83cb3b5c69de 1356
BETZtechnik 13:83cb3b5c69de 1357
BETZtechnik 11:ce51026d8702 1358
BETZtechnik 11:ce51026d8702 1359
BETZtechnik 11:ce51026d8702 1360
BETZtechnik 11:ce51026d8702 1361 if (index == 2) { // tool number 10's column
BETZtechnik 11:ce51026d8702 1362
BETZtechnik 11:ce51026d8702 1363 c = device.getc();
BETZtechnik 11:ce51026d8702 1364
BETZtechnik 11:ce51026d8702 1365 if (c=='0') {
BETZtechnik 11:ce51026d8702 1366 Tens = 0;
BETZtechnik 11:ce51026d8702 1367 index = 4;
BETZtechnik 11:ce51026d8702 1368
BETZtechnik 11:ce51026d8702 1369 }
BETZtechnik 11:ce51026d8702 1370
BETZtechnik 11:ce51026d8702 1371 else if (c=='1') {
BETZtechnik 11:ce51026d8702 1372 Tens = 1;
BETZtechnik 2:bbbacfd62773 1373 index = 4;
BETZtechnik 11:ce51026d8702 1374
BETZtechnik 11:ce51026d8702 1375 }
BETZtechnik 11:ce51026d8702 1376
BETZtechnik 11:ce51026d8702 1377 else if (c=='2') {
BETZtechnik 11:ce51026d8702 1378 Tens = 2;
BETZtechnik 11:ce51026d8702 1379 index = 4;
BETZtechnik 11:ce51026d8702 1380
BETZtechnik 11:ce51026d8702 1381 }
BETZtechnik 11:ce51026d8702 1382
BETZtechnik 11:ce51026d8702 1383 else if (c=='3') {
BETZtechnik 11:ce51026d8702 1384 Tens = 3;
BETZtechnik 11:ce51026d8702 1385 index = 4;
BETZtechnik 11:ce51026d8702 1386
BETZtechnik 11:ce51026d8702 1387 }
BETZtechnik 11:ce51026d8702 1388
BETZtechnik 11:ce51026d8702 1389 else if (c=='4') {
BETZtechnik 11:ce51026d8702 1390 Tens = 4;
BETZtechnik 11:ce51026d8702 1391 index = 4;
BETZtechnik 2:bbbacfd62773 1392 }
BETZtechnik 11:ce51026d8702 1393
BETZtechnik 11:ce51026d8702 1394 else if (c=='5') { //max number of tools is 50
BETZtechnik 11:ce51026d8702 1395 Tens = 5;
BETZtechnik 11:ce51026d8702 1396 index = 4;
BETZtechnik 11:ce51026d8702 1397 }
BETZtechnik 11:ce51026d8702 1398
BETZtechnik 11:ce51026d8702 1399 }
BETZtechnik 13:83cb3b5c69de 1400
BETZtechnik 13:83cb3b5c69de 1401
BETZtechnik 13:83cb3b5c69de 1402
BETZtechnik 11:ce51026d8702 1403
BETZtechnik 11:ce51026d8702 1404 if (index == 4) { // tool number ones column
BETZtechnik 2:bbbacfd62773 1405
BETZtechnik 11:ce51026d8702 1406 c = device.getc();
BETZtechnik 11:ce51026d8702 1407
BETZtechnik 11:ce51026d8702 1408 if (c=='0') {
BETZtechnik 11:ce51026d8702 1409 Ones = 0;
BETZtechnik 2:bbbacfd62773 1410
BETZtechnik 11:ce51026d8702 1411 }
BETZtechnik 11:ce51026d8702 1412
BETZtechnik 11:ce51026d8702 1413 else if (c=='1') {
BETZtechnik 11:ce51026d8702 1414 Ones = 1;
BETZtechnik 2:bbbacfd62773 1415
BETZtechnik 2:bbbacfd62773 1416
BETZtechnik 11:ce51026d8702 1417 }
BETZtechnik 11:ce51026d8702 1418
BETZtechnik 11:ce51026d8702 1419 else if (c=='2') {
BETZtechnik 11:ce51026d8702 1420 Ones = 2;
BETZtechnik 11:ce51026d8702 1421
BETZtechnik 11:ce51026d8702 1422 }
BETZtechnik 11:ce51026d8702 1423
BETZtechnik 11:ce51026d8702 1424 else if (c=='3') {
BETZtechnik 11:ce51026d8702 1425 Ones = 3;
BETZtechnik 11:ce51026d8702 1426
BETZtechnik 11:ce51026d8702 1427 }
BETZtechnik 11:ce51026d8702 1428
BETZtechnik 11:ce51026d8702 1429 else if (c=='4') {
BETZtechnik 11:ce51026d8702 1430 Ones = 4;
BETZtechnik 11:ce51026d8702 1431 }
BETZtechnik 11:ce51026d8702 1432
BETZtechnik 11:ce51026d8702 1433 else if (c=='5') {
BETZtechnik 11:ce51026d8702 1434 Ones = 5;
BETZtechnik 11:ce51026d8702 1435 }
BETZtechnik 11:ce51026d8702 1436
BETZtechnik 11:ce51026d8702 1437 else if (c=='6') {
BETZtechnik 11:ce51026d8702 1438 Ones = 6;
BETZtechnik 11:ce51026d8702 1439 }
BETZtechnik 11:ce51026d8702 1440
BETZtechnik 11:ce51026d8702 1441 else if (c=='7') {
BETZtechnik 11:ce51026d8702 1442 Ones = 7;
BETZtechnik 11:ce51026d8702 1443 }
BETZtechnik 11:ce51026d8702 1444
BETZtechnik 11:ce51026d8702 1445 else if (c=='8') {
BETZtechnik 11:ce51026d8702 1446 Ones = 8;
BETZtechnik 11:ce51026d8702 1447 }
BETZtechnik 11:ce51026d8702 1448
BETZtechnik 11:ce51026d8702 1449 else if (c=='9') {
BETZtechnik 11:ce51026d8702 1450 Ones = 9;
BETZtechnik 11:ce51026d8702 1451 }
BETZtechnik 11:ce51026d8702 1452
BETZtechnik 11:ce51026d8702 1453 else if (c=='0') {
BETZtechnik 11:ce51026d8702 1454 Ones = 0;
BETZtechnik 2:bbbacfd62773 1455 }
BETZtechnik 11:ce51026d8702 1456
BETZtechnik 11:ce51026d8702 1457
BETZtechnik 11:ce51026d8702 1458
BETZtechnik 11:ce51026d8702 1459 serialToolNumber = ((Tens * 10) + Ones);
BETZtechnik 12:1e974964272e 1460
BETZtechnik 12:1e974964272e 1461 count = 0; // 2019-09-23 to make sure the new tool isn't overwritten.
BETZtechnik 11:ce51026d8702 1462
BETZtechnik 11:ce51026d8702 1463 currentToolNo = serialToolNumber; // update tool number
BETZtechnik 11:ce51026d8702 1464
BETZtechnik 11:ce51026d8702 1465 index=0;
BETZtechnik 11:ce51026d8702 1466
BETZtechnik 11:ce51026d8702 1467 }
BETZtechnik 11:ce51026d8702 1468
BETZtechnik 11:ce51026d8702 1469 if (index == 5) { // magazine monitoring
BETZtechnik 11:ce51026d8702 1470
BETZtechnik 11:ce51026d8702 1471
BETZtechnik 11:ce51026d8702 1472
BETZtechnik 11:ce51026d8702 1473 c = device.getc();
BETZtechnik 11:ce51026d8702 1474
BETZtechnik 11:ce51026d8702 1475 if (c == '+') {
BETZtechnik 11:ce51026d8702 1476
BETZtechnik 11:ce51026d8702 1477
BETZtechnik 11:ce51026d8702 1478 currentToolNo = (currentToolNo +1);
BETZtechnik 11:ce51026d8702 1479 if (currentToolNo > numTools) {
BETZtechnik 11:ce51026d8702 1480 currentToolNo = 1;
BETZtechnik 11:ce51026d8702 1481 }
BETZtechnik 11:ce51026d8702 1482 index = 0;
BETZtechnik 11:ce51026d8702 1483 } else if (c == '-') {
BETZtechnik 11:ce51026d8702 1484 /*
BETZtechnik 11:ce51026d8702 1485 tft.setTextColor(WHITE);
BETZtechnik 11:ce51026d8702 1486 tft.setCursor(100, 100);
BETZtechnik 11:ce51026d8702 1487 tft.printf("1");
BETZtechnik 11:ce51026d8702 1488 */
BETZtechnik 11:ce51026d8702 1489 currentToolNo = (currentToolNo -1);
BETZtechnik 11:ce51026d8702 1490 if (currentToolNo < 1) {
BETZtechnik 11:ce51026d8702 1491 currentToolNo = numTools;
BETZtechnik 11:ce51026d8702 1492 }
BETZtechnik 11:ce51026d8702 1493 index = 0;
BETZtechnik 11:ce51026d8702 1494 }
BETZtechnik 11:ce51026d8702 1495
BETZtechnik 11:ce51026d8702 1496 }
BETZtechnik 11:ce51026d8702 1497 }
BETZtechnik 11:ce51026d8702 1498
BETZtechnik 11:ce51026d8702 1499 }
BETZtechnik 2:bbbacfd62773 1500 }
BETZtechnik 4:d3c19705042b 1501