Display code

Dependencies:   mbed reScale RotaryEncoder RPG Adafruit_ST7735 Adafruit_GFX PinDetect Ee24xx08 mRotaryEncoder

Committer:
BETZtechnik
Date:
Sun Sep 15 18:41:03 2019 +0000
Revision:
11:ce51026d8702
Parent:
10:dd8d89133b28
Child:
12:1e974964272e
N1 N2 dir enabled. now sending that to inputs over 485.

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