-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathir_oled.cpp
executable file
·1312 lines (1166 loc) · 29.2 KB
/
ir_oled.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "common.h"
#ifdef WIFISERVER
#include <ESP8266WiFi.h>
#endif
#if defined(IR_OLED_MENU)
static int wait_job = 0;
static int wait_spindle = 0;
static String jobnum;
#include "ir_remote.h"
#include "ir_oled.h"
//#define OLEDDISPLAY_REDUCE_MEMORY
#ifndef LCD_SDA
#define LCD_SDA TX
#define LCD_SCL RX
#define LCD_CMD D1
#endif
#ifdef LCD_OLED_SSD
#include "SSD1306Wire.h"
SSD1306Wire xdisplay(0x3c, LCD_SDA, LCD_SCL); // d6,d5
#endif
#ifdef LCD_UC1609
#include "UC1609Wire.h"
UC1609Wire xdisplay(LCD_SDA, LCD_SCL, LCD_CMD);
#endif
#ifdef LCD_NK1202
#include "NK1202Wire.h"
NK1202Wire xdisplay(LCD_SDA, LCD_SCL, HAS_CS);
#endif
#ifdef LCD_NK1661
#define USERGB12
#include "NK1661Wire.h"
//#define HAS_CS D2
#ifdef laser_pin
#define HAS_RS D8
#else
#define HAS_RS D1
#endif
//NK1661Wire xdisplay(LCD_SDA, LCD_SCL, HAS_CS, HAS_RS, 20); //
NK1661Wire xdisplay(LCD_SDA, LCD_SCL, 255, HAS_RS, 20); //
//NK1661Wire xdisplay(LCD_SDA, LCD_SCL, D1, 255, 20); // RS using capacitor, CS using real PIN
#endif
#ifdef LCD_2004
#include "LiquidCrystal_PCF8574.h"
#include <Wire.h> // Only needed for Arduino 1.6.5 and earlier
LiquidCrystal_PCF8574 xdisplay(IR_OLED_MENU); // set the LCD address to 0x27 for a 16 chars and 2 line display
#endif
#include "fonts.h"
#include "gcodesave.h"
#include "gcode.h"
#include "eprom.h"
#include <math.h>
/*
U8g2lib Example Overview:
Frame Buffer Examples: clearBuffer/sendBuffer. Fast, but may not work with all Arduino boards because of RAM consumption
Page Buffer Examples: firstPage/nextPage. Less RAM usage, should work with all Arduino boards.
U8x8 Text Only Example: No RAM usage, direct communication with display controller. No graphics, 8x8 Text only.
*/
// End of constructor list
//
int menu_index = 1;
int menu_page_le = 0;
String* menu_t;
String IPA;
int* menu_pos;
int* menu_page;
int menu_col;
typedef void (*Tdrawmenu)(void);
typedef void (*Tclickmenu)(int);
Tdrawmenu menu_f;
Tclickmenu menu_click;
void load_menu(int index, String* menu, int le, int col, int* pos, int* page, void f(void), void fc(int))
{
menu_index = index;
menu_pos = pos;
menu_page_le = (le - col) / col - 1;
menu_page = page;
menu_t = menu;
menu_f = f;
menu_click = fc;
menu_col = col;
//REINIT;
f();
}
void draw_menu(void);
void menu_0_click(int a);
void menu_2_click(int a);
void menu_3_click(int a);
void menu_4_click(int a);
#define LEN(x) (sizeof(x) / sizeof(x[0]))
#define LOADINFO() load_menu(99, NULL, 0, 1, &menu_99_pos, &menu_99_page, draw_info, menu_99_click)
#define LOADMENU(xx) load_menu(xx, menu_##xx##_t, LEN(menu_##xx##_t), 1, \
&menu_##xx##_pos, &menu_##xx##_page, draw_menu, menu_##xx##_click)
int col2pos = 14;
float vmul = 1;
String jobname;
/*
MENU 99, INFO MENU
*/
// Standar menu is index 0: title, rest is the menu
int menu_99_pos = 0;
int menu_99_page = 0;
extern int avgpw, avgcnt;
String uptime(long w)
{
long days = 0;
long hours = 0;
long mins = 0;
long secs = 0;
secs = w / 1000; //convect milliseconds to seconds
mins = secs / 60; //convert seconds to minutes
hours = mins / 60; //convert minutes to hours
days = hours / 24; //convert hours to days
secs = secs - (mins * 60); //subtract the coverted seconds to minutes in order to display 59 secs max
mins = mins - (hours * 60); //subtract the coverted minutes to hours in order to display 59 minutes max
hours = hours - (days * 24); //subtract the coverted hours to days in order to display 23 hours max
//Display results
String ups = "";
if (days > 0) // days will displayed only if value is greater than zero
{
ups = days;
ups += " day ";
}
ups += (hours);
ups += (":");
ups += (mins);
ups += (":");
ups += (secs);
return ups;
}
extern int tmul;
extern int rmkey;
extern long lastjobt;
extern int spindle_pct, lastS;
extern long spindle_pwm;
uint8_t LCDturn;
int oldindex=0;
void draw_info(void)
{
extern bool inwaitbuffer;
//if (inwaitbuffer)return;
//if (oldindex!=menu_index){
d_clear(); // clear the internal memory
// oldindex=menu_index;
//}
d_setcolor(WHITE);
extern int ISWIFIOK;
#ifdef WIFISERVER
// if (ISWIFIOK && (WiFi.status() != WL_CONNECTED))
// d_text(0, 0, "Wifi disconnect"); // write something to the internal memory
// else
d_text(0, 0, IPA); // write something to the internal memory
#else
d_text(0, 0, "Karyacontroller"); // write something to the internal memory
#endif
// d_text(15, 0, String(rmkey)); // write something to the internal memory
// extern int thcread;
// d_text(15, 0, String(thcread)); // write something to the internal memory
d_text(13, 0, "S:"+String(info_ve)); // write something to the internal memory
//d_frect(0, LCD_Y - 1, d_w() * LCD_X, LCD_Y);
d_setcolor(WHITE);
d_text(1, 1, String(info_x)); // write something to the internal memory
d_text(8, 1, String(info_y)); // write something to the internal memory
d_text(15, 1, String(info_z)); // write something to the internal memory
extern int laserwason;
#ifdef RPM_COUNTER
extern uint32_t get_RPM();
uint32_t r = get_RPM();
int pw;
extern bool RPM_PID_MODE;
if (RPM_PID_MODE) {
if (avgcnt > 0) {
pw = avgpw / avgcnt;
avgpw = 0;
avgcnt = 1;
}
}
else
pw = spindle_pct;
d_text(0, 2, "SPDL " + String(r) + "/" + String(pw) + "%"); // write something to the internal memory
#else
#define r spindle_pct
#ifdef ANALOG_THC
d_text(0, 2, laserwason?"PLSM ON":"PLSM OFF"); // write something to the internal memory
#else
#ifdef laser_pin
#warning "LASER PIN ?"
d_text(0, 2, String("LSR ") + (laserwason?String(r)+"%":"OFF")); // write something to the internal memory
#else
d_text(0, 2, "SPDL " + String(r)+"%"); // write something to the internal memory
#endif
#endif
#endif
d_text(10, 2, "RT% " + String(int(f_multiplier * 100))); // write something to the internal memory
String L1, L2, L3;
if (uncompress) {
if (PAUSE)L1 = "Paused !"; else
L1 = jobname;
L1 += " " + String(100 * gcodepos / gcodesize) + "%";
}
else {
L1 = "JOG% " + String(tmul);
}
L2 = "Uptime " + uptime(millis());
L3 = "Last " + (lastjobt > 0 ? uptime(lastjobt) : "-");
if (LINES == 4) {
LCDturn++;
//d_text(0, 3, L1);
if (LCDturn > ((3 << 4) - 1))
LCDturn = 0;
if (LCDturn >> 4 == 0)
d_text(0, 3, L1); // write something to the internal memory
if (LCDturn >> 4 == 1)
d_text(0, 3, L2); // write something to the internal memory
if (LCDturn >> 4 == 2)
d_text(0, 3, L3); // write something to the internal memory
}
else if (LINES == 5) {
LCDturn++;
//d_text(0, 3, L1);
d_text(0, 3, L1);
if (LCDturn > ((2 << 4) - 1))
LCDturn = 0;
if (LCDturn >> 4 == 0)
d_text(0, 4, L2); // write something to the internal memory
if (LCDturn >> 4 == 1)
d_text(0, 4, L3); // write something to the internal memory
}
else {
d_text(0, 3, L1); // write something to the internal memory
d_text(0, 4, L2);
d_text(0, 5, L3);
}
d_show();
//tmul=tmr;
}
/*
MENU 0, HOME MENU
*/
// Standar menu is index 0: title, rest is the menu
int menu_0_pos = 0;
int menu_0_page = 0;
String menu_0_t[] = { "Main Menu", "1. Set Zero", "2. My jobs", "3. Tools", "4. Settings", "5. Retry WIFI" };
/*
MENU 3, Tools
*/
// Standar menu is index 0: title, rest is the menu
int menu_3_pos = 0;
int menu_3_page = 0;
String menu_3_t[] = { "Tools", "1. To zero", "2. To job zero" };
/*
ONCLICK
*/
Tclickmenu confirm_click;
/*
MENU 80, Confirmation
*/
// Standar menu is index 0: title, rest is the menu
int menu_80_pos = 0;
int menu_80_page = 0;
String menu_80_t[] = { "", "YES", "NO" };
void menu_80_click(int a)
{
if (a == IRK_OK || a == IRK_LF || a == IRK4_OK || a == IRK4_LF || a == IRK4_BACK2) {
int res = (a == IRK_OK || a == IRK4_OK) && (*menu_pos == 0);
confirm_click(res);
}
}
#define LOADCONFIRM(T, clickok) \
menu_80_t[0] = T; \
confirm_click = clickok; \
LOADMENU(80);
/*
============================================================================================
MENU 4, Settings
*/
/*
MENU 41, Speed
*/
int menu_4_pos = 0;
int menu_4_page = 0;
String menu_4_t[] = { "Settings", "1. Speed", "2. Acceleration", "3. Backlash", "4. Step/mm", "5. Homing",
#ifdef ANALOG_THC
"6. THC",
#endif
"Save to EEPROM", "Update firmware" };
// Standar menu is index 0: title, rest is the menu
int menu_41_pos = 0;
int menu_41_page = 0;
String menu_41_t[] = { "Max Speed", "mm/s", "Axis X", "50", "Axis Y", "50", "Axis Z", "5",
#ifdef laser_pin
"Laser %",
#else
"Spindle %",
#endif
"1" };
int xyzspeed[4];
int getSpeed(void)
{
xyzspeed[0] = maxf[MX];
xyzspeed[1] = maxf[MY];
xyzspeed[2] = maxf[MZ];
xyzspeed[3] = Lscale * 100;
menu_41_t[3] = xyzspeed[0];
menu_41_t[5] = xyzspeed[1];
menu_41_t[7] = xyzspeed[2];
menu_41_t[9] = xyzspeed[3];
return 10;
}
int menu_setvalue(int a)
{
if (a == IRK_LF || a == IRK4_LF)
return -1;
if (a == IRK_RG || a == IRK4_RG)
return 1;
if (a == IRK_4 || a == IRK4_4)
return -5;
if (a == IRK_6 || a == IRK4_6)
return 5;
if (a == IRK_X || a == IRK4_X)
return -1000;
return 0;
}
void menu_41_click(int a)
{
if (a == IRK_H || a == IRK4_H || a == IRK4_BACK2)
LOADMENU(4);
if (a == IRK_OK || a == IRK4_OK) {
// save config and back to menu 4
maxf[MX] = xyzspeed[0];
maxf[MY] = xyzspeed[1];
maxf[MZ] = xyzspeed[2];
Lscale = (float)xyzspeed[3] / 100.0;
eepromwrite(EE_max_x_feedrate, xyzspeed[0]); // accell
eepromwrite(EE_max_y_feedrate, xyzspeed[1]); // accell
eepromwrite(EE_max_z_feedrate, xyzspeed[2]); // accell
eepromwrite(EE_Lscale, ff(Lscale));
LOADMENU(4);
}
int v = menu_setvalue(a);
if (v != 0) {
if (v <= -1000) {
if (*menu_pos == 3)
xyzspeed[*menu_pos] = -xyzspeed[*menu_pos];
}
else {
xyzspeed[*menu_pos] += v;
if ((*menu_pos != 3) && (xyzspeed[*menu_pos] < 1))
xyzspeed[*menu_pos] = 1;
}
menu_41_t[(*menu_pos) * 2 + 3] = xyzspeed[*menu_pos];
draw_menu();
}
}
void LOADMENU41(void)
{
col2pos = 13;
load_menu(41, menu_41_t,
getSpeed(),
2,
&menu_41_pos, &menu_41_page, draw_menu, menu_41_click);
}
int menu_42_pos = 0;
int menu_42_page = 0;
String menu_42_t[] = { "Accel", "mm/s~", "Jerk", "0", "Accel", "250", "Corner", "15" };
int xyzaccel[3];
int getAccel(void)
{
xyzaccel[0] = 0;
xyzaccel[1] = accel;
xyzaccel[2] = xycorner;
menu_42_t[3] = xyzaccel[0];
menu_42_t[5] = xyzaccel[1];
menu_42_t[7] = xyzaccel[2];
return 8;
}
void menu_42_click(int a)
{
if (a == IRK_H || a == IRK4_H || a == IRK4_BACK2)
LOADMENU(4);
if (a == IRK_OK || a == IRK4_OK) {
accel = xyzaccel[1];
xycorner = xyzaccel[2];
eepromwrite(EE_accel, xyzaccel[1]); // accell
//eepromwrite(EE_jerk, xyzaccel[0]); // accell
eepromwrite(EE_corner, xyzaccel[2]); // accell
LOADMENU(4);
}
int v = menu_setvalue(a);
if (v != 0 && v > -1000) {
if (*menu_pos == 0)
v *= 1000;
if (*menu_pos == 1)
v *= 10;
xyzaccel[*menu_pos] += v;
int minv = (*menu_pos == 0) ? 0 : 5;
if (xyzaccel[*menu_pos] < minv)
xyzaccel[*menu_pos] = minv;
menu_42_t[(*menu_pos) * 2 + 3] = xyzaccel[*menu_pos];
draw_menu();
}
}
void LOADMENU42(void)
{
col2pos = 12;
load_menu(42, menu_42_t,
getAccel(),
2,
&menu_42_pos, &menu_42_page, draw_menu, menu_42_click);
}
int menu_43_pos = 0;
int menu_43_page = 0;
String menu_43_t[] = { "De-Backlash", "mm", "X", "0", "Y", "250", "Z", "15" };
int xyzback[3] = { 10, 10, 3 };
int getBacklash(void)
{
xyzback[0] = xback[MX];
xyzback[1] = xback[MY];
xyzback[2] = xback[MZ];
menu_43_t[3] = 0.001 * xyzback[0];
menu_43_t[5] = 0.001 * xyzback[1];
menu_43_t[7] = 0.001 * xyzback[2];
col2pos = 14;
return 8;
}
void menu_43_click(int a)
{
if (a == IRK_H || a == IRK4_H || a == IRK4_BACK2)
LOADMENU(4);
if (a == IRK_OK || a == IRK4_OK) {
// save config and back to menu 4
//EE_xbacklash
xback[MX] = xyzback[0];
xback[MY] = xyzback[1];
xback[MZ] = xyzback[2];
eepromwrite(EE_xbacklash, xyzback[0]); // *1000
eepromwrite(EE_ybacklash, xyzback[1]); // *1000
eepromwrite(EE_zbacklash, xyzback[2]); // *1000
LOADMENU(4);
}
int v = menu_setvalue(a);
if (v != 0 && v > -1000) {
xyzback[*menu_pos] += v * 10;
if (xyzback[*menu_pos] < 0)
xyzback[*menu_pos] = 0;
menu_43_t[(*menu_pos) * 2 + 3] = 0.001 * xyzback[*menu_pos];
draw_menu();
}
}
void LOADMENU43(void)
{
col2pos = 12;
load_menu(43, menu_43_t,
getBacklash(),
2,
&menu_43_pos, &menu_43_page, draw_menu, menu_43_click);
}
int menu_44_pos = 0;
int menu_44_page = 0;
String menu_44_t[] = { "1 mm =", "Step", "X", "0", "Y", "250", "Z", "15" };
int xyzsteps[3];
int getSteps(void)
{
xyzsteps[0] = stepmmx[0] * 1000;
xyzsteps[1] = stepmmx[1] * 1000;
xyzsteps[2] = stepmmx[2] * 1000;
menu_44_t[3] = 0.001 * xyzsteps[0];
menu_44_t[5] = 0.001 * xyzsteps[1];
menu_44_t[7] = 0.001 * xyzsteps[2];
return 8;
}
void menu_44_click(int a)
{
if (a == IRK_H || a == IRK4_H || a == IRK4_BACK2)
LOADMENU(4);
if (a == IRK_OK || a == IRK4_OK) {
// save config and back to menu 4
//EE_estepmm
stepmmx[0] = xyzsteps[0] * 0.001;
stepmmx[1] = xyzsteps[1] * 0.001;
stepmmx[2] = xyzsteps[2] * 0.001;
eepromwrite(EE_xstepmm, xyzsteps[0]);
eepromwrite(EE_ystepmm, xyzsteps[1]);
eepromwrite(EE_zstepmm, xyzsteps[2]);
LOADMENU(4);
}
int v = menu_setvalue(a);
if (v != 0) {
if (v == -1000)
xyzsteps[*menu_pos] = -xyzsteps[*menu_pos];
else
xyzsteps[*menu_pos] += v * 10;
menu_44_t[(*menu_pos) * 2 + 3] = 0.001 * xyzsteps[*menu_pos];
draw_menu();
}
}
void LOADMENU44(void)
{
col2pos = 10;
load_menu(44, menu_44_t,
getSteps(),
2,
&menu_44_pos, &menu_44_page, draw_menu, menu_44_click);
}
int menu_45_pos = 0;
int menu_45_page = 0;
String menu_45_t[] = { "Home Pos", "mm", "X", "0", "Y", "250", "Z", "15" };
int xyzhome[3];
int getHomes(void)
{
xyzhome[0] = ax_home[0];
xyzhome[1] = ax_home[1];
xyzhome[2] = ax_home[2];
menu_45_t[3] = xyzhome[0];
menu_45_t[5] = xyzhome[1];
menu_45_t[7] = xyzhome[2];
return 8;
}
void menu_45_click(int a)
{
if (a == IRK_H || a == IRK4_H || a == IRK4_BACK2) {
LOADMENU(4);
reload_eeprom();
}
if (a == IRK_OK || a == IRK4_OK) {
// save config and back to menu 4
//EE_xhome
ax_home[0] = xyzhome[0];
ax_home[1] = xyzhome[1];
ax_home[2] = xyzhome[2];
eepromwrite(EE_xhome, xyzhome[0] * 1000);
eepromwrite(EE_yhome, xyzhome[1] * 1000);
eepromwrite(EE_zhome, xyzhome[2] * 1000);
LOADMENU(4);
}
int v = menu_setvalue(a);
if (v != 0 && v > -1000) {
xyzhome[*menu_pos] += v;
if (xyzhome[*menu_pos] < 0)
xyzhome[*menu_pos] = 0;
menu_45_t[(*menu_pos) * 2 + 3] = xyzhome[*menu_pos];
draw_menu();
}
}
void LOADMENU45(void)
{
col2pos = 14;
load_menu(45, menu_45_t,
getHomes(),
2,
&menu_45_pos, &menu_45_page, draw_menu, menu_45_click);
}
void UPDATEESP(int a)
{
if (a) {
extern void updateFirmware();
updateFirmware();
}
LOADMENU(0);
}
#ifdef ANALOG_THC
int menu_46_pos=0;
int menu_46_page=0;
String menu_46_t[] = { "THC", "v", "V.Ref", "0", "Ofset", "0"};
int thcVal[2];
int getThc(void){
menu_46_t[3] = thc_up;
menu_46_t[5] = thc_ofs;
thcVal[0]=thc_up;
thcVal[1]=thc_ofs;
return 6;
}
void menu_46_click(int a){
if (a == IRK_H || a == IRK4_H || a == IRK4_BACK2) {
LOADMENU(4);
reload_eeprom();
}
if (a == IRK_OK || a == IRK4_OK) {
// save config and back to menu 4
//EE_xhome
thc_up = thcVal[0];
thc_ofs = thcVal[1];
eepromwrite(EE_thc_up, thc_up);
eepromwrite(EE_thc_ofs, thc_ofs);
LOADMENU(4);
}
int v = menu_setvalue(a);
if (v != 0) {
if (v == -1000)
thcVal[*menu_pos] = -thcVal[*menu_pos];
else
thcVal[*menu_pos] += v;
menu_46_t[(*menu_pos) * 2 + 3] = thcVal[*menu_pos];
draw_menu();
}
}
void LOADMENU46(void)
{
col2pos = 14;
load_menu(46, menu_46_t,
getThc(),
2,
&menu_46_pos, &menu_46_page, draw_menu, menu_46_click);
}
#endif
void menu_4_click(int a)
{
static int menu4L=LEN(menu_4_t)-2;
extern bool RPM_PID_MODE;
if (a == IRK_LF || a == IRK4_LF || a == IRK4_BACK2)
LOADMENU(0);
else if (a == IRK_OK || a == IRK4_OK)
{
switch (*menu_pos) {
case 0:
LOADMENU41();
break;
case 1:
LOADMENU42();
break;
case 2:
LOADMENU43();
break;
case 3:
LOADMENU44();
break;
case 4:
LOADMENU45();
break;
#ifdef ANALOG_THC
case 5:
LOADMENU46();
break;
#endif
}
if (*menu_pos==menu4L-1){
reload_eeprom();
LOADMENU(0);
} else if (*menu_pos==menu4L){
LOADCONFIRM(("UPDATE FIRMWARE ?"), UPDATEESP);
}
}
}
/*
* * ============================================================================================
*/
/*
MENU 2, job list
*/
// Jobs menu, display files
#ifdef __ARM__
#define NUMJOBS 20
#endif
#ifdef ESP8266
#define NUMJOBS 50
#endif
int menu_2_pos = 0;
int menu_2_page = 0;
String menu_2_t[NUMJOBS * 2];
#ifdef ESP8266
#include <FS.h>
String ojobname;
void check_job() {
if (ojobname != jobname) {
dummy_beginuncompress("/" + jobname);
ojobname = jobname;
}
}
int getJobs(void)
{
Dir dir = SPIFFS.openDir("/");
menu_2_t[0] = "File name";
menu_2_t[1] = "Kb";
ojobname = "";
int i = 0;
while (dir.next()) {
String s = dir.fileName();
if (s.endsWith(".gcode")) {
s.remove(0, 1);
s.remove(s.length() - 6);
//s.remove(0,1);
menu_2_t[i * 2 + 2] = s;
menu_2_t[i * 2 + 3] = String(dir.fileSize() / 1000);
i++;
}
}
return i * 2 + 2;
}
#endif
#ifdef __ARM__
#include <SdFat.h>
int getJobs(void)
{
Dir dir = SPIFFS.openDir("/");
menu_2_t[0] = "File name";
menu_2_t[1] = "Kb";
int i = 0;
while (dir.next()) {
String s = dir.fileName();
if (s.endsWith(".gcode")) {
s.remove(0, 1);
s.remove(s.length() - 6);
//s.remove(0,1);
menu_2_t[i * 2 + 2] = s;
menu_2_t[i * 2 + 3] = String(dir.fileSize() / 1000);
i++;
}
}
return i * 2 + 2;
}
#endif
void draw_menu(void)
{
extern bool inwaitbuffer;
//if (inwaitbuffer)return;
d_clear(); // clear the internal memory
d_setcolor(WHITE);
d_text(0, 0, *menu_t); // write something to the internal memory
d_rect(0, LCD_Y - 2, LCD_X * d_w(), 1);
d_frect(0, LCD_Y * (1 + *menu_pos - *menu_page) - 1, LCD_X * d_w() + 2, LCD_Y);
if (menu_col == 2) {
d_text(20 - d_t_width(*(menu_t + 1)) / LCD_X, 0, *(menu_t + 1)); // write something to the internal memory
d_rect(col2pos * LCD_X - 1, 0, 1, LCD_Y);
d_setcolor(BLACK);
d_rect(col2pos * LCD_X - 1, LCD_Y * (1 + *menu_pos - *menu_page), 1, LCD_Y + 2);
}
for (int i = 0; i < LINES - 1; i++) {
int j = i + *menu_page;
if (j > menu_page_le)
break;
d_setcolor(j == *menu_pos ? BLACK : WHITE);
d_text(1, i + 1, *(menu_t + j * menu_col + menu_col)); // write something to the internal memory
if (menu_col == 2) {
String* kb = (menu_t + j * menu_col + menu_col + 1);
d_text(20 - d_t_width(*kb) / LCD_X, i + 1, *kb);
}
}
d_show();
}
int menu_81_pos = 0;
int menu_81_page = 0;
String menu_81_t[] = { "", "Execute", "Preview Area", "Delete", "Back" };
void menu_81_click(int a)
{
if (a == IRK_OK || a == IRK4_OK || a == IRK_LF || a == IRK4_LF || a == IRK4_BACK2) {
confirm_click((a == IRK_OK || a == IRK4_OK) ? *menu_pos : -1);
}
}
#define LOADCONFIRM1(T, clickok) \
menu_81_t[0] = T; \
confirm_click = clickok; \
LOADMENU(81);
int menu_82_pos = 0;
int menu_82_page = 0;
String menu_82_t[] = { "", "", "", "", "", "" };
void menu_82_click(int a)
{
if (a == IRK_OK || a == IRK4_OK || a == IRK_LF || a == IRK4_LF || a == IRK4_BACK2) {
confirm_click((a == IRK_OK || a == IRK4_OK) ? *menu_pos : -1);
}
}
#define LOADCUSTOM(T, L1, L2, L3, L4, L5, clickok) \
menu_82_t[0] = T; \
menu_82_t[1] = L1; \
menu_82_t[2] = L2; \
menu_82_t[3] = L3; \
menu_82_t[4] = L4; \
menu_82_t[5] = L5; \
confirm_click = clickok; \
LOADMENU(82);
extern int uncompress;
void LOADMENU2FAIL(int a)
{
if (a) {
extern void stopmachine();
stopmachine();
}
LOADMENU(0);
}
void LOADMENU2(void)
{
if (!uncompress) {
load_menu(2, menu_2_t,
getJobs(),
2,
&menu_2_pos, &menu_2_page, draw_menu, menu_2_click);
}
else {
LOADCONFIRM(("Stop running job !"), LOADMENU2FAIL); // CONFIRMATION MENU
}
}
void menu_99_click(int a)
{
if (a == IRK_OK || a == IRK4_OK) {
LOADMENU(0);
}
}
extern void wifi_push(char c); // we use WIFI GCODE Command buffer to inject gcode
static const char* gc92 = "G92\n";
extern void connectWifi(int ret = 1);
extern int ISWIFIOK;
void RESTARTESP(int a)
{
if (a) {
#ifdef ESP8266
//eepromwrite(EE_softreset, 111);
//eepromcommit();
//delay(200);
if (ISWIFIOK) {
connectWifi();
LOADINFO();
} else ESP.restart();
#endif
}
else
LOADMENU(0);
}
void menu_0_click(int a)
{
if (a == IRK_LF || a == IRK4_LF || a == IRK4_BACK2)
LOADINFO();
if (a == IRK_OK || a == IRK4_OK) {
switch (*menu_pos) {
case 0:
for (int i = 0; i < strlen(gc92); i++)
wifi_push(gc92[i]);
LOADINFO();
break; // return to info menu
case 1:
LOADMENU2();
break; // load the jobs menu
case 2:
LOADMENU(3);
break; // settings menu
case 3:
LOADMENU(4);
break; // settings menu
case 4:
if (ISWIFIOK)
RESTARTESP(1);
else
{
LOADCONFIRM(("Restart CNC ?"), RESTARTESP);
}
break; // settings menu
}
}
}
void DELETEJOB(int a)
{
if (a) {
deletejob("/" + jobname);
}
LOADMENU2();
}
void DUMMYJOB(int a)
{
LOADMENU2();
}
void runjob(int a);
long lastpreview = 0;
void runpreview()
{
//
if (millis() - lastpreview < 5000) return;
lastpreview = millis();
LOADMENU2();
extern int laserOn, constantlaserVal;
laserOn = 1;
constantlaserVal = 255;
extern float ocz1, cx1, cy1;
float rx = cx1;
float ry = cy1;
float rz = ocz1;
#ifndef PLASMA_MODE
set_pwm(150);
#endif
addmove(100, xMin, yMin, 2, 0, 1, 1); // ke kiri atas
addmove(100, 0, 0, 0.5, 0, 0, 1);
float dx=(xMax-xMin)/4;
float dy=(yMax-yMin)/4;
addmove(100, dx, 0, 0, 0, 1, 1); // ke kanan atas