aboutsummaryrefslogtreecommitdiffhomepage
path: root/workspace/TS100/src/gui.cpp
blob: 2371774fc3062ad6116c6195d7538efee865e80a (plain)
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
/*
 * gui.cpp
 *
 *  Created on: 3Sep.,2017
 *      Author: Ben V. Brown
 */

#include "gui.hpp"
#include "main.hpp"
#include "cmsis_os.h"
#include "Translation.h"

#include "string.h"
extern uint32_t lastButtonTime;
void gui_Menu(const menuitem* menu);
static void settings_setInputVRange(void);
static void settings_displayInputVRange(void);
static void settings_setSleepTemp(void);
static void settings_displaySleepTemp(void);
static void settings_setSleepTime(void);
static void settings_displaySleepTime(void);
static void settings_setShutdownTime(void);
static void settings_displayShutdownTime(void);
static void settings_setSensitivity(void);
static void settings_displaySensitivity(void);
static void settings_setTempF(void);
static void settings_displayTempF(void);
static void settings_setAdvancedSolderingScreens(void);
static void settings_displayAdvancedSolderingScreens(void);
static void settings_setAdvancedIDLEScreens(void);
static void settings_displayAdvancedIDLEScreens(void);
static void settings_setScrollSpeed(void);
static void settings_displayScrollSpeed(void);

static void settings_setDisplayRotation(void);
static void settings_displayDisplayRotation(void);
static void settings_setBoostModeEnabled(void);
static void settings_displayBoostModeEnabled(void);
static void settings_setBoostTemp(void);
static void settings_displayBoostTemp(void);
static void settings_setAutomaticStartMode(void);
static void settings_displayAutomaticStartMode(void);
static void settings_setCoolingBlinkEnabled(void);
static void settings_displayCoolingBlinkEnabled(void);
static void settings_setResetSettings(void);
static void settings_displayResetSettings(void);
static void settings_setCalibrate(void);
static void settings_displayCalibrate(void);
static void settings_setCalibrateVIN(void);
static void settings_displayCalibrateVIN(void);

//Menu functions
static void settings_displaySolderingMenu(void);
static void settings_enterSolderingMenu(void);
static void settings_displayPowerMenu(void);
static void settings_enterPowerMenu(void);
static void settings_displayUIMenu(void);
static void settings_enterUIMenu(void);
static void settings_displayAdvancedMenu(void);
static void settings_enterAdvancedMenu(void);
/*
 * Root Settings Menu
 *
 * Power Source
 * Soldering
 * 	Boost Mode Enabled
 * 	Boost Mode Temp
 * 	Auto Start
 *
 * Power Saving
 * 	Sleep Temp
 * 	Sleep Time
 * 	Shutdown Time
 * 	Motion Sensitivity
 *
 * UI
 *  // Language
 *  Scrolling Speed
 *  Temperature Unit
 *  Display orientation
 *  Cooldown blink
 *
 * Advanced
 *  Detailed IDLE
 *  Detailed Soldering
 *  Logo Time
 *  Calibrate Temperature
 *  Calibrate Input V
 *  Reset Settings
 *
 */
const menuitem rootSettingsMenu[] {
/*
 * Power Source
 * Soldering Menu
 * Power Saving Menu
 * UI Menu
 * Advanced Menu
 * Exit
 */
{ (const char*) SettingsDescriptions[0], { settings_setInputVRange }, {
		settings_displayInputVRange } }, /*Voltage input*/
{ (const char*) SettingsMenuEntriesDescriptions[0], {
		settings_enterSolderingMenu }, { settings_displaySolderingMenu } }, /*Soldering*/
{ (const char*) SettingsMenuEntriesDescriptions[1], { settings_enterPowerMenu },
		{ settings_displayPowerMenu } }, /*Sleep Options Menu*/
{ (const char*) SettingsMenuEntriesDescriptions[2], { settings_enterUIMenu }, {
		settings_displayUIMenu } }, /*UI Menu*/
{ (const char*) SettingsMenuEntriesDescriptions[3],
		{ settings_enterAdvancedMenu }, { settings_displayAdvancedMenu } }, /*Advanced Menu*/
{ NULL, { NULL }, { NULL } }            // end of menu marker. DO NOT REMOVE
};

const menuitem solderingMenu[] = {
/*
 * Boost Mode Enabled
 * 	Boost Mode Temp
 * 	Auto Start
 */
{ (const char*) SettingsDescriptions[8], { settings_setBoostModeEnabled }, {
		settings_displayBoostModeEnabled } }, /*Enable Boost*/
{ (const char*) SettingsDescriptions[9], { settings_setBoostTemp }, {
		settings_displayBoostTemp } }, /*Boost Temp*/
{ (const char*) SettingsDescriptions[10], { settings_setAutomaticStartMode }, {
		settings_displayAutomaticStartMode } }, /*Auto start*/
{ NULL, { NULL }, { NULL } }            // end of menu marker. DO NOT REMOVE
};
const menuitem UIMenu[] = {
/*
 // Language
 *  Scrolling Speed
 *  Temperature Unit
 *  Display orientation
 *  Cooldown blink
 */
{ (const char*) SettingsDescriptions[5], { settings_setTempF }, {
		settings_displayTempF } }, /* Temperature units*/
{ (const char*) SettingsDescriptions[7], { settings_setDisplayRotation }, {
		settings_displayDisplayRotation } }, /*Display Rotation*/
{ (const char*) SettingsDescriptions[11], { settings_setCoolingBlinkEnabled }, {
		settings_displayCoolingBlinkEnabled } }, /*Cooling blink warning*/
{ (const char*) SettingsDescriptions[16], { settings_setScrollSpeed }, {
		settings_displayScrollSpeed } }, /*Scroll Speed for descriptions*/
{ NULL, { NULL }, { NULL } }            // end of menu marker. DO NOT REMOVE
};
const menuitem PowerMenu[] = {
/*
 * Sleep Temp
 * 	Sleep Time
 * 	Shutdown Time
 * 	Motion Sensitivity
 */
{ (const char*) SettingsDescriptions[1], { settings_setSleepTemp }, {
		settings_displaySleepTemp } }, /*Sleep Temp*/
{ (const char*) SettingsDescriptions[2], { settings_setSleepTime }, {
		settings_displaySleepTime } }, /*Sleep Time*/
{ (const char*) SettingsDescriptions[3], { settings_setShutdownTime }, {
		settings_displayShutdownTime } }, /*Shutdown Time*/
{ (const char*) SettingsDescriptions[4], { settings_setSensitivity }, {
		settings_displaySensitivity } }, /* Motion Sensitivity*/
{ NULL, { NULL }, { NULL } }            // end of menu marker. DO NOT REMOVE
};
const menuitem advancedMenu[] = {

/*
 * Detailed IDLE
 *  Detailed Soldering
 *  Logo Time
 *  Calibrate Temperature
 *  Calibrate Input V
 *  Reset Settings
 */
{ (const char*) SettingsDescriptions[6], { settings_setAdvancedIDLEScreens }, {
		settings_displayAdvancedIDLEScreens } }, /* Advanced idle screen*/
{ (const char*) SettingsDescriptions[15],
		{ settings_setAdvancedSolderingScreens }, {
				settings_displayAdvancedSolderingScreens } }, /* Advanced soldering screen*/
{ (const char*) SettingsDescriptions[13], { settings_setResetSettings }, {
		settings_displayResetSettings } }, /*Resets settings*/
{ (const char*) SettingsDescriptions[12], { settings_setCalibrate }, {
		settings_displayCalibrate } }, /*Calibrate tip*/
{ (const char*) SettingsDescriptions[14], { settings_setCalibrateVIN }, {
		settings_displayCalibrateVIN } }, /*Voltage input cal*/
{ NULL, { NULL }, { NULL } }            // end of menu marker. DO NOT REMOVE
};

static void printShortDescriptionSingleLine(uint32_t shortDescIndex) {
	lcd.setFont(0);
	lcd.setCharCursor(0, 0);
	lcd.print(SettingsShortNames[shortDescIndex][0]);
}

static void printShortDescriptionDoubleLine(uint32_t shortDescIndex) {
	lcd.setFont(1);
	lcd.setCharCursor(0, 0);
	lcd.print(SettingsShortNames[shortDescIndex][0]);
	lcd.setCharCursor(0, 1);
	lcd.print(SettingsShortNames[shortDescIndex][1]);
}

/**
 * Prints two small lines of short description
 * and prepares cursor in big font after it.
 * @param shortDescIndex Index to of short description.
 * @param cursorCharPosition Custom cursor char position to set after printing
 * description.
 */
static void printShortDescription(uint32_t shortDescIndex,
		uint16_t cursorCharPosition) {
	// print short description (default single line, explicit double line)
	if (SettingsShortNameType == SHORT_NAME_DOUBLE_LINE) {
		printShortDescriptionDoubleLine(shortDescIndex);
	} else {
		printShortDescriptionSingleLine(shortDescIndex);
	}

	// prepare cursor for value
	lcd.setFont(0);
	lcd.setCharCursor(cursorCharPosition, 0);
}

static int userConfirmation(const char* message) {
	uint16_t messageWidth = FONT_12_WIDTH * (strlen(message) + 7);
	uint32_t messageStart = xTaskGetTickCount();

	lcd.setFont(0);
	lcd.setCursor(0, 0);
	int16_t lastOffset = -1;
	bool lcdRefresh = true;


	for (;;) {

					int16_t messageOffset =
							((xTaskGetTickCount() - messageStart)
									/ (systemSettings.descriptionScrollSpeed == 1 ?
											1 : 2));
					messageOffset %= messageWidth;		//Roll around at the end


		if (lastOffset != messageOffset) {
			lcd.clearScreen();

			//^ Rolling offset based on time
			lcd.setCursor((OLED_WIDTH - messageOffset), 0);
			lcd.print(message);
			lastOffset = messageOffset;
			lcdRefresh = true;
		}

		ButtonState buttons = getButtonState();
		switch (buttons) {
		case BUTTON_F_SHORT:
			//User confirmed
			return 1;

		case BUTTON_NONE:
			break;
		default:
		case BUTTON_BOTH:
		case BUTTON_B_SHORT:
		case BUTTON_F_LONG:
		case BUTTON_B_LONG:
			return 0;
		}

		if (lcdRefresh) {
			lcd.refresh();
			osDelay(20);
			lcdRefresh = false;
		}
	}
	return 0;
}

static void settings_setInputVRange(void) {
	systemSettings.cutoutSetting = (systemSettings.cutoutSetting + 1) % 5;
}

static void settings_displayInputVRange(void) {
	printShortDescription(0, 6);

	if (systemSettings.cutoutSetting) {
		lcd.drawChar('0' + 2 + systemSettings.cutoutSetting);
		lcd.drawChar('S');
	} else {
		lcd.print("DC");
	}
}

static void settings_setSleepTemp(void) {
	systemSettings.SleepTemp += 10;
	if (systemSettings.SleepTemp > 300)
		systemSettings.SleepTemp = 50;
}

static void settings_displaySleepTemp(void) {
	printShortDescription(1, 5);
	lcd.printNumber(systemSettings.SleepTemp, 3);
}

static void settings_setSleepTime(void) {
	systemSettings.SleepTime++;  // Go up 1 minute at a time
	if (systemSettings.SleepTime >= 16) {
		systemSettings.SleepTime = 1;  // can't set time over 10 mins
	}
	// Remember that ^ is the time of no movement
}

static void settings_displaySleepTime(void) {
	printShortDescription(2, 5);

	if (systemSettings.SleepTime < 6) {
		lcd.printNumber(systemSettings.SleepTime * 10, 2);
		lcd.drawChar('S');
	} else {
		lcd.printNumber(systemSettings.SleepTime - 5, 2);
		lcd.drawChar('M');
	}
}

static void settings_setShutdownTime(void) {
	systemSettings.ShutdownTime++;
	if (systemSettings.ShutdownTime > 60) {
		systemSettings.ShutdownTime = 0;  // wrap to off
	}
}

static void settings_displayShutdownTime(void) {
	printShortDescription(3, 6);
	lcd.printNumber(systemSettings.ShutdownTime, 2);
}

static void settings_setTempF(void) {
	systemSettings.temperatureInF = !systemSettings.temperatureInF;
}

static void settings_displayTempF(void) {
	printShortDescription(5, 7);

	lcd.drawChar((systemSettings.temperatureInF) ? 'F' : 'C');
}

static void settings_setSensitivity(void) {
	systemSettings.sensitivity++;
	systemSettings.sensitivity = systemSettings.sensitivity % 10;
}

static void settings_displaySensitivity(void) {
	printShortDescription(4, 7);
	lcd.printNumber(systemSettings.sensitivity, 1);
}

static void settings_setAdvancedSolderingScreens(void) {
	systemSettings.detailedSoldering = !systemSettings.detailedSoldering;
}

static void settings_displayAdvancedSolderingScreens(void) {
	printShortDescription(15, 7);

	lcd.drawCheckbox(systemSettings.detailedSoldering);
}

static void settings_setAdvancedIDLEScreens(void) {
	systemSettings.detailedIDLE = !systemSettings.detailedIDLE;
}

static void settings_displayAdvancedIDLEScreens(void) {
	printShortDescription(6, 7);

	lcd.drawCheckbox(systemSettings.detailedIDLE);
}
static void settings_setScrollSpeed(void) {

	if (systemSettings.descriptionScrollSpeed == 0)
		systemSettings.descriptionScrollSpeed = 1;
	else
		systemSettings.descriptionScrollSpeed = 0;
}
static void settings_displayScrollSpeed(void) {
	printShortDescription(16, 7);
	lcd.drawChar(
			(systemSettings.descriptionScrollSpeed) ?
					SettingFastChar : SettingSlowChar);
}

static void settings_setDisplayRotation(void) {
	systemSettings.OrientationMode++;
	systemSettings.OrientationMode = systemSettings.OrientationMode % 3;
}

static void settings_displayDisplayRotation(void) {
	printShortDescription(7, 7);

	switch (systemSettings.OrientationMode) {
	case 0:
		lcd.drawChar(SettingRightChar);
		break;
	case 1:
		lcd.drawChar(SettingLeftChar);
		break;
	case 2:
		lcd.drawChar(SettingAutoChar);
		break;
	default:
		lcd.drawChar(SettingRightChar);
		break;
	}
}

static void settings_setBoostModeEnabled(void) {
	systemSettings.boostModeEnabled = !systemSettings.boostModeEnabled;
}

static void settings_displayBoostModeEnabled(void) {
	printShortDescription(8, 7);

	lcd.drawCheckbox(systemSettings.boostModeEnabled);
}

static void settings_setBoostTemp(void) {
	systemSettings.BoostTemp += 10;  // Go up 10 at a time
	if (systemSettings.temperatureInF) {
		if (systemSettings.BoostTemp > 850) {
			systemSettings.BoostTemp = 480;  // loop back at 250
		}
	} else {
		if (systemSettings.BoostTemp > 450) {
			systemSettings.BoostTemp = 250;  // loop back at 250
		}
	}
}

static void settings_displayBoostTemp(void) {
	printShortDescription(9, 5);
	lcd.printNumber(systemSettings.BoostTemp, 3);
}

static void settings_setAutomaticStartMode(void) {
	systemSettings.autoStartMode++;
	systemSettings.autoStartMode %= 2;
}

static void settings_displayAutomaticStartMode(void) {
	printShortDescription(10, 7);

	lcd.drawCheckbox(systemSettings.autoStartMode);
}

static void settings_setCoolingBlinkEnabled(void) {
	systemSettings.coolingTempBlink = !systemSettings.coolingTempBlink;
}

static void settings_displayCoolingBlinkEnabled(void) {
	printShortDescription(11, 7);

	lcd.drawCheckbox(systemSettings.coolingTempBlink);
}

static void settings_setResetSettings(void) {
	if (userConfirmation(SettingsResetWarning)) {
		resetSettings();

		lcd.setFont(0);
		lcd.setCursor(0, 0);
		lcd.print("RESET OK");
		lcd.refresh();

		waitForButtonPressOrTimeout(200);
	}
}

static void settings_displayResetSettings(void) {
	printShortDescription(13, 7);
}

static void settings_setCalibrate(void) {
	if (userConfirmation(SettingsCalibrationWarning)) {
		//User confirmed
		//So we now perform the actual calculation
		lcd.clearScreen();
		lcd.setCursor(0, 0);
		lcd.print(".....");
		lcd.refresh();

		setCalibrationOffset(0);            //turn off the current offset
		for (uint8_t i = 0; i < 20; i++) {
			getTipRawTemp(1); //cycle through the filter a fair bit to ensure we're stable.
			osDelay(20);
		}
		osDelay(100);

		uint16_t rawTempC = tipMeasurementToC(getTipRawTemp(0));
		//We now measure the current reported tip temperature
		uint16_t handleTempC = getHandleTemperature() / 10;
		//We now have an error between these that we want to store as the offset
		rawTempC = rawTempC - handleTempC;
		systemSettings.CalibrationOffset = rawTempC;
		setCalibrationOffset(rawTempC);       //store the error
		osDelay(100);
	}
}

static void settings_displayCalibrate(void) {
	printShortDescription(12, 5);
}

static void settings_setCalibrateVIN(void) {
	// Jump to the voltage calibration subscreen
	lcd.setFont(0);
	lcd.clearScreen();
	lcd.setCursor(0, 0);

	for (;;) {
		lcd.setCursor(0, 0);
		lcd.printNumber(getInputVoltageX10(systemSettings.voltageDiv) / 10, 2);
		lcd.print(".");
		lcd.printNumber(getInputVoltageX10(systemSettings.voltageDiv) % 10, 1);
		lcd.print("V");

		ButtonState buttons = getButtonState();
		switch (buttons) {
		case BUTTON_F_SHORT:
			systemSettings.voltageDiv++;
			break;

		case BUTTON_B_SHORT:
			systemSettings.voltageDiv--;
			break;

		case BUTTON_BOTH:
		case BUTTON_F_LONG:
		case BUTTON_B_LONG:
			saveSettings();
			return;

		case BUTTON_NONE:
		default:
			break;
		}

		lcd.refresh();
		osDelay(50);

		// Cap to sensible values
		if (systemSettings.voltageDiv < 90) {
			systemSettings.voltageDiv = 90;
		} else if (systemSettings.voltageDiv > 130) {
			systemSettings.voltageDiv = 130;
		}
	}
}

static void settings_displayCalibrateVIN(void) {
	printShortDescription(14, 5);
}
static void settings_displaySolderingMenu(void) {
	//Call into the menu
	lcd.setFont(1);
	lcd.setCursor(0, 0);
	//Draw title
	lcd.print(SettingsMenuEntries[0]);
	//Draw symbol
	//16 pixel wide image
	lcd.drawArea(96 - 16, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * 0]));
}
static void settings_enterSolderingMenu(void) {
	gui_Menu(solderingMenu);
}
static void settings_displayPowerMenu(void) {
	lcd.setFont(1);
	lcd.setCursor(0, 0);
	//Draw title
	lcd.print(SettingsMenuEntries[1]);
	//Draw symbol
	//16 pixel wide image
	lcd.drawArea(96 - 16, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * 1]));
}
static void settings_enterPowerMenu(void) {
	gui_Menu(PowerMenu);
}
static void settings_displayUIMenu(void) {
	lcd.setFont(1);
	lcd.setCursor(0, 0);
	//Draw title
	lcd.print(SettingsMenuEntries[2]);
	//Draw symbol
	//16 pixel wide image
	lcd.drawArea(96 - 16, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * 2]));
}
static void settings_enterUIMenu(void) {
	gui_Menu(UIMenu);
}
static void settings_displayAdvancedMenu(void) {
	lcd.setFont(1);
	lcd.setCursor(0, 0);
	//Draw title
	lcd.print(SettingsMenuEntries[3]);
	//Draw symbol
	//16 pixel wide image
	lcd.drawArea(96 - 16, 0, 16, 16, (&SettingsMenuIcons[(16 * 2) * 3]));

}
static void settings_enterAdvancedMenu(void) {
	gui_Menu(advancedMenu);
}

void gui_Menu(const menuitem* menu) {
	// Draw the settings menu and provide iteration support etc
	uint8_t currentScreen = 0;
	uint32_t autoRepeatTimer = 0;
	uint8_t autoRepeatAcceleration = 0;
	bool earlyExit = false;
	uint32_t descriptionStart = 0;
	int16_t lastOffset = -1;
	bool lcdRefresh = true;
	ButtonState lastButtonState = BUTTON_NONE;

	while ((menu[currentScreen].draw.func != NULL) && earlyExit == false) {
		lcd.setFont(0);
		lcd.setCursor(0, 0);
		//If the user has hesitated for >=3 seconds, show the long text
		//Otherwise "draw" the option
		if (xTaskGetTickCount() - lastButtonTime < 300) {
			lcd.clearScreen();
			menu[currentScreen].draw.func();
			lastOffset = -1;
			lcdRefresh = true;
		} else {
			// Draw description
			if (descriptionStart == 0)
				descriptionStart = xTaskGetTickCount();
			// lower the value - higher the speed
			int16_t descriptionWidth = FONT_12_WIDTH
					* (strlen(menu[currentScreen].description) + 7);
			int16_t descriptionOffset =
					((xTaskGetTickCount() - descriptionStart)
							/ (systemSettings.descriptionScrollSpeed == 1 ?
									1 : 2));
			descriptionOffset %= descriptionWidth;		//Roll around at the end

			if (lastOffset != descriptionOffset) {
				lcd.clearScreen();

				//^ Rolling offset based on time
				lcd.setCursor((OLED_WIDTH - descriptionOffset), 0);
				lcd.print(menu[currentScreen].description);
				lastOffset = descriptionOffset;
				lcdRefresh = true;
			}

		}

		ButtonState buttons = getButtonState();

		if (buttons != lastButtonState) {
			autoRepeatAcceleration = 0;
			lastButtonState = buttons;
		}

		switch (buttons) {
		case BUTTON_BOTH:
			earlyExit = true;  // will make us exit next loop
			descriptionStart = 0;
			break;
		case BUTTON_F_SHORT:
			// increment
			if (descriptionStart == 0) {
				if (menu[currentScreen].incrementHandler.func != NULL)
					menu[currentScreen].incrementHandler.func();
				else
					earlyExit = true;
			} else
				descriptionStart = 0;
			break;
		case BUTTON_B_SHORT:
			if (descriptionStart == 0)
				currentScreen++;
			else
				descriptionStart = 0;
			break;
		case BUTTON_F_LONG:
			if (xTaskGetTickCount() - autoRepeatTimer
					+ autoRepeatAcceleration> PRESS_ACCEL_INTERVAL_MAX) {
				menu[currentScreen].incrementHandler.func();
				autoRepeatTimer = xTaskGetTickCount();
				descriptionStart = 0;

				autoRepeatAcceleration += PRESS_ACCEL_STEP;
			}
			break;
		case BUTTON_B_LONG:
			if (xTaskGetTickCount() - autoRepeatTimer
					+ autoRepeatAcceleration> PRESS_ACCEL_INTERVAL_MAX) {
				currentScreen++;
				autoRepeatTimer = xTaskGetTickCount();
				descriptionStart = 0;

				autoRepeatAcceleration += PRESS_ACCEL_STEP;
			}
			break;
		case BUTTON_NONE:
		default:
			break;
		}

		if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration)
				< PRESS_ACCEL_INTERVAL_MIN) {
			autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN;
		}

		if (lcdRefresh) {
			lcd.refresh();  // update the LCD
			osDelay(20);
			lcdRefresh = false;
		}
	}

}

void enterSettingsMenu() {
	gui_Menu(rootSettingsMenu);  //Call the root menu
	saveSettings();
}