513 lines
12 KiB
C
513 lines
12 KiB
C
/*
|
|
* testMenu.c
|
|
*
|
|
* Created on: Mar 27, 2024
|
|
* Author: Brian.Bailey
|
|
*/
|
|
|
|
|
|
#include <assert.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <math.h>
|
|
#include <stdint.h>
|
|
|
|
//Drivers
|
|
#include "fsl_common.h"
|
|
#include "fsl_gpio.h"
|
|
|
|
|
|
#include "Fonts\fontLibrary.h"
|
|
#include "Graphics\graphicsLibrary.h"
|
|
#include "lcd.h"
|
|
#include "keys.h"
|
|
#include "timer.h"
|
|
#include "frq.h"
|
|
#include "Graphics\icons.h"
|
|
#include "System\system.h"
|
|
#include "menu.h"
|
|
#include "hwFixes.h"
|
|
#include "eeprom.h"
|
|
|
|
#include "testMenu.h"
|
|
|
|
|
|
/*******************************************************************************
|
|
* Definitions
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
* Variables
|
|
******************************************************************************/
|
|
|
|
MenuItem_t testMenu[TEST_MENU_NUM];
|
|
MenuItem_t hwFixMenu[HWFIX_MENU_NUM];
|
|
|
|
uint8_t * fixStrings[] = {"NOT YET...", "DONE"}; //1 = fix done
|
|
uint8_t * onOffStrings[] = {"OFF", "ON"}; //1 = on
|
|
|
|
extern HARDWARE_FIX_t hwf;
|
|
extern char tempString[40];
|
|
extern uint8_t Diag_Flag;
|
|
/*******************************************************************************
|
|
* Static Function Declarations
|
|
******************************************************************************/
|
|
|
|
static void ClearTestMenuItems(MenuItem_t items[], uint32_t num);
|
|
static uint8_t * GetFixStatusString(uint32_t index);
|
|
static void HwFixMenu(void);
|
|
static void DisplayHwFixMenu(uint32_t selected);
|
|
static void DrawTestMenuScrollBar(uint32_t displayIndex, uint32_t numItems);
|
|
|
|
|
|
/*******************************************************************************
|
|
* Static Functions
|
|
******************************************************************************/
|
|
|
|
//Clear an array of MENU_ITEM_t
|
|
static void ClearTestMenuItems(MenuItem_t items[], uint32_t num)
|
|
{
|
|
for(uint32_t i = 0; i < num; i++)
|
|
{
|
|
items[i].pMonoIcon = 0; //Init mono icon pointer to null
|
|
|
|
items[i].text[0] = 0; //Init first char to null
|
|
}
|
|
}
|
|
|
|
static uint8_t * GetFixStatusString(uint32_t index)
|
|
{
|
|
return fixStrings[index];
|
|
}
|
|
|
|
static uint8_t * GetOnOffString(uint32_t index)
|
|
{
|
|
return onOffStrings[index];
|
|
}
|
|
|
|
static void HwFixMenu(void)
|
|
{
|
|
uint32_t selected = 0;
|
|
uint32_t menuNum = HWFIX_MENU_NUM;
|
|
uint32_t menuExit = 0;
|
|
|
|
//Draw screen first time
|
|
DisplayHwFixMenu(selected);
|
|
|
|
|
|
while(1)
|
|
{
|
|
//use keys to changes selected
|
|
uint32_t pressed = KEY_WaitForKeyPress(KEY_ALL);
|
|
|
|
switch(pressed) //This won't work if multiple keys pressed, but it'll clear them
|
|
{
|
|
case KEY_BACK:
|
|
menuExit = true;
|
|
break;
|
|
case ON_OFF_KEY:
|
|
//Do nothing
|
|
break;
|
|
case KEY_UP:
|
|
if(--selected > menuNum)
|
|
{
|
|
selected = 0;
|
|
}
|
|
DisplayHwFixMenu(selected);
|
|
break;
|
|
case (KEY_UP << KEY_LONG_PRESS):
|
|
do
|
|
{
|
|
if(--selected > menuNum)
|
|
{
|
|
selected = 0;
|
|
}
|
|
DisplayHwFixMenu(selected);
|
|
|
|
Delay_Ticks(MENU_KEY_HOLD_SCROLL_DELAY);
|
|
}
|
|
while(KEY_GetUpKeyHeld());
|
|
break;
|
|
case KEY_DOWN:
|
|
if(++selected >= menuNum)
|
|
{
|
|
selected = menuNum - 1;
|
|
}
|
|
DisplayHwFixMenu(selected);
|
|
break;
|
|
case (KEY_DOWN << KEY_LONG_PRESS):
|
|
do
|
|
{
|
|
if(++selected >= menuNum)
|
|
{
|
|
selected = menuNum - 1;
|
|
}
|
|
DisplayHwFixMenu(selected);
|
|
Delay_Ticks(MENU_KEY_HOLD_SCROLL_DELAY);
|
|
}
|
|
while(KEY_GetDownKeyHeld());
|
|
break;
|
|
case KEY_ENTER: //SHORT Press to SET Hardware Fix
|
|
switch(selected)
|
|
{
|
|
case(0): //vBattCap_021
|
|
EE_WriteUINT32(EE_HWFIX_VBATT_CAP_021, true);
|
|
hwf.vBattCap_021 = true;
|
|
break;
|
|
case(1): //Increase mainPcbaPN
|
|
hwf.mainPcbaPN += 2;
|
|
if(hwf.mainPcbaPN > HWF_MAX_MAIN_PCBA_PN)
|
|
{
|
|
hwf.mainPcbaPN = HWF_MAX_MAIN_PCBA_PN;
|
|
}
|
|
EE_WriteUINT32(EE_HWFIX_MAIN_PCBA_PN, hwf.mainPcbaPN);
|
|
break;
|
|
case(2): //Not used
|
|
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
DisplayHwFixMenu(selected); //Redraw menu after any changes
|
|
break;
|
|
case (KEY_ENTER << KEY_LONG_PRESS): //LONG Press to CLEAR Hardware Fix
|
|
switch(selected)
|
|
{
|
|
case(0): //vBattCap_021
|
|
EE_WriteUINT32(EE_HWFIX_VBATT_CAP_021, false);
|
|
hwf.vBattCap_021 = false;
|
|
break;
|
|
case(1): //Decrease mainPcbaPN
|
|
hwf.mainPcbaPN -= 2;
|
|
if(hwf.mainPcbaPN < HWF_MIN_MAIN_PCBA_PN)
|
|
{
|
|
hwf.mainPcbaPN = HWF_MIN_MAIN_PCBA_PN;
|
|
}
|
|
EE_WriteUINT32(EE_HWFIX_MAIN_PCBA_PN, hwf.mainPcbaPN);
|
|
break;
|
|
case(2): //Not used
|
|
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
DisplayHwFixMenu(selected); //Redraw menu after any changes
|
|
break;
|
|
}
|
|
|
|
if(menuExit)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void DisplayHwFixMenu(uint32_t selected)
|
|
{
|
|
char displayIndex = 0; //index of first menu line to draw
|
|
uint32_t menuNum = HWFIX_MENU_NUM;
|
|
|
|
LCD_Clear();
|
|
//Title
|
|
FL_DrawString("HARDWARE FIXES", LCD_X_MID, 0, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_CENTER);
|
|
|
|
//Update displayIndex
|
|
if(selected >= (displayIndex + MENU_TEST_MAX_LINES_DISPLAYED))
|
|
{
|
|
displayIndex++;
|
|
}
|
|
else if(selected < displayIndex)
|
|
{
|
|
displayIndex--;
|
|
}
|
|
|
|
//Draw menu items
|
|
uint32_t lastIndex = displayIndex + MENU_TEST_MAX_LINES_DISPLAYED; //last line to draw. Limit lastIndex to max lines
|
|
if(lastIndex > menuNum) //Limit lastIndex to number of items
|
|
{
|
|
lastIndex = menuNum;
|
|
}
|
|
for(uint32_t i = displayIndex; i < lastIndex; i++)
|
|
{
|
|
//Menu strings
|
|
FL_DrawString(hwFixMenu[i].text, MENU_MAIN_TEXT_X, MENU_TEST_TEXT_Y_START + (i-displayIndex)*MENU_LINE_HEIGHT, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
|
|
|
|
|
|
//Draw item status
|
|
switch(i)
|
|
{
|
|
case(0): //vBattCap_021
|
|
FL_DrawString(GetFixStatusString(hwf.vBattCap_021), MENU_MAIN_STATUS_X, MENU_TEST_TEXT_Y_START + (i - displayIndex)*MENU_LINE_HEIGHT, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
|
|
break;
|
|
case(1): //mainPcbaPN
|
|
sprintf(tempString, "%d", hwf.mainPcbaPN);
|
|
FL_DrawString(tempString, MENU_MAIN_STATUS_X, MENU_TEST_TEXT_Y_START + (i - displayIndex)*MENU_LINE_HEIGHT, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
|
|
break;
|
|
case(2): //
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
//Draw selection bar
|
|
uint32_t selRectY0 = MENU_TEST_TEXT_Y_START + (selected - displayIndex)*MENU_LINE_HEIGHT;
|
|
GL_DrawFilledRectangle(MENU_SEL_RECT_X0, selRectY0, MENU_SEL_RECT_X1, selRectY0 + MENU_LINE_HEIGHT, LCD_DRAW_XOR);
|
|
|
|
|
|
DrawTestMenuScrollBar(displayIndex, menuNum);
|
|
|
|
|
|
LCD_Update();
|
|
}
|
|
|
|
|
|
/* Draw TEST menu scroll bar on right side
|
|
* DIFFERENT for testMenu since number of lines per screen is different
|
|
*/
|
|
static void DrawTestMenuScrollBar(uint32_t displayIndex, uint32_t numItems)
|
|
{
|
|
//Exit if scroll bar not needed
|
|
if(numItems <= MENU_MAX_LINES_DISPLAYED)
|
|
{
|
|
return;
|
|
}
|
|
//numItems = 30; // 18
|
|
//vertical line
|
|
const uint32_t lineWidth = 5;
|
|
const uint32_t lineX = LCD_X_MAX - 10;
|
|
const uint32_t lineYStart = 20;
|
|
const uint32_t lineYStop = LCD_Y_MAX - 20;
|
|
const uint32_t lineHeight = lineYStop - lineYStart;
|
|
|
|
//rectangle
|
|
const uint32_t rectWidth = 20;
|
|
const uint32_t rectX = lineX;
|
|
|
|
uint32_t rectHeight = lineHeight * ((double)MENU_TEST_MAX_LINES_DISPLAYED / numItems);
|
|
uint32_t rectYStart = lineYStart + (lineHeight - rectHeight) * ((double)displayIndex / (numItems - MENU_MAX_LINES_DISPLAYED));
|
|
uint32_t rectYStop = rectYStart + rectHeight;
|
|
|
|
//Draw line
|
|
GL_DrawLine(lineX, lineYStart, lineX, lineYStop, lineWidth, LCD_DRAW_SET);
|
|
|
|
//Draw Rectangle
|
|
GL_DrawLine(rectX, rectYStart, rectX, rectYStop, rectWidth, LCD_DRAW_SET);
|
|
}
|
|
|
|
/*******************************************************************************
|
|
* Public Functions
|
|
******************************************************************************/
|
|
|
|
void TM_Init(void)
|
|
{
|
|
//Clear menu items
|
|
ClearTestMenuItems(testMenu, TEST_MENU_NUM);
|
|
ClearTestMenuItems(hwFixMenu, HWFIX_MENU_NUM);
|
|
|
|
|
|
uint32_t i = 0;
|
|
|
|
//test menu
|
|
testMenu[i].pMonoIcon = 0;
|
|
strcpy(testMenu[i++].text, "Test Mode");
|
|
|
|
testMenu[i].pMonoIcon = 0;
|
|
strcpy(testMenu[i++].text, "Show Details");
|
|
|
|
testMenu[i].pMonoIcon = 0;
|
|
strcpy(testMenu[i++].text, "Hardware Fixes");
|
|
|
|
testMenu[i].pMonoIcon = 0;
|
|
strcpy(testMenu[i++].text, "Frog");
|
|
|
|
testMenu[i].pMonoIcon = 0;
|
|
strcpy(testMenu[i++].text, "Tuna");
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
//hwFix menu
|
|
hwFixMenu[i].pMonoIcon = 0;
|
|
strcpy(hwFixMenu[i++].text, "VBatt Cap (021)");
|
|
|
|
hwFixMenu[i].pMonoIcon = 0;
|
|
strcpy(hwFixMenu[i++].text, "Main PCBA PN");
|
|
|
|
hwFixMenu[i].pMonoIcon = 0;
|
|
strcpy(hwFixMenu[i++].text, "TBD");
|
|
}
|
|
|
|
|
|
/*
|
|
* Test menu accesses through konami code
|
|
*/
|
|
void TM_TestMenu(void)
|
|
{
|
|
uint32_t selected = 0;
|
|
uint32_t menuNum = TEST_MENU_NUM;
|
|
uint32_t menuExit = 0;
|
|
|
|
//Draw screen first time
|
|
TM_DisplayTestMenu(selected);
|
|
|
|
|
|
while(1)
|
|
{
|
|
//use keys to changes selected
|
|
uint32_t pressed = KEY_WaitForKeyPress(KEY_ALL);
|
|
|
|
switch(pressed) //This won't work if multiple keys pressed, but it'll clear them
|
|
{
|
|
case KEY_BACK:
|
|
menuExit = true;
|
|
break;
|
|
case ON_OFF_KEY:
|
|
//Do nothing
|
|
break;
|
|
case KEY_UP:
|
|
if(--selected > menuNum)
|
|
{
|
|
selected = 0;
|
|
}
|
|
TM_DisplayTestMenu(selected);
|
|
break;
|
|
case (KEY_UP << KEY_LONG_PRESS):
|
|
do
|
|
{
|
|
if(--selected > menuNum)
|
|
{
|
|
selected = 0;
|
|
}
|
|
TM_DisplayTestMenu(selected);
|
|
|
|
Delay_Ticks(MENU_KEY_HOLD_SCROLL_DELAY);
|
|
}
|
|
while(KEY_GetUpKeyHeld());
|
|
break;
|
|
case KEY_DOWN:
|
|
if(++selected >= menuNum)
|
|
{
|
|
selected = menuNum - 1;
|
|
}
|
|
TM_DisplayTestMenu(selected);
|
|
break;
|
|
case (KEY_DOWN << KEY_LONG_PRESS):
|
|
do
|
|
{
|
|
if(++selected >= menuNum)
|
|
{
|
|
selected = menuNum - 1;
|
|
}
|
|
TM_DisplayTestMenu(selected);
|
|
Delay_Ticks(MENU_KEY_HOLD_SCROLL_DELAY);
|
|
}
|
|
while(KEY_GetDownKeyHeld());
|
|
break;
|
|
case KEY_ENTER:
|
|
switch(selected)
|
|
{
|
|
case(0): //Test Mode
|
|
//Toggle test mode flag
|
|
break;
|
|
case(1): //Show Details
|
|
Diag_Flag ^=1; //Toggle showDetails flag
|
|
break;
|
|
case(2): //Hardware Fixes
|
|
HwFixMenu();
|
|
break;
|
|
case(3): //Not used
|
|
|
|
break;
|
|
case(4): //Not used
|
|
|
|
break;
|
|
case(5): //Not used
|
|
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
TM_DisplayTestMenu(selected); //Redraw menu after any changes
|
|
|
|
break;
|
|
}
|
|
|
|
if(menuExit)
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
void TM_DisplayTestMenu(uint32_t selected)
|
|
{
|
|
char displayIndex = 0; //index of first menu line to draw
|
|
uint32_t menuNum = TEST_MENU_NUM;
|
|
|
|
LCD_Clear();
|
|
//Title
|
|
FL_DrawString("SNEAKRET MENU", LCD_X_MID, 0, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_CENTER);
|
|
|
|
//Update displayIndex
|
|
if(selected >= (displayIndex + MENU_TEST_MAX_LINES_DISPLAYED))
|
|
{
|
|
displayIndex++;
|
|
}
|
|
else if(selected < displayIndex)
|
|
{
|
|
displayIndex--;
|
|
}
|
|
|
|
//Draw menu items
|
|
uint32_t lastIndex = displayIndex + MENU_TEST_MAX_LINES_DISPLAYED; //last line to draw. Limit lastIndex to max lines
|
|
if(lastIndex > menuNum) //Limit lastIndex to number of items
|
|
{
|
|
lastIndex = menuNum;
|
|
}
|
|
for(uint32_t i = displayIndex; i < lastIndex; i++)
|
|
{
|
|
//Menu strings
|
|
FL_DrawString(testMenu[i].text, MENU_MAIN_TEXT_X, MENU_TEST_TEXT_Y_START + (i-displayIndex)*MENU_LINE_HEIGHT, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
|
|
|
|
|
|
//Draw item status
|
|
switch(i)
|
|
{
|
|
case(0): //Test Mode
|
|
FL_DrawString(GetOnOffString(0), MENU_MAIN_STATUS_X, MENU_TEST_TEXT_Y_START + (i - displayIndex)*MENU_LINE_HEIGHT, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
|
|
break;
|
|
case(1): //Show Details
|
|
FL_DrawString(GetOnOffString(Diag_Flag), MENU_MAIN_STATUS_X, MENU_TEST_TEXT_Y_START + (i - displayIndex)*MENU_LINE_HEIGHT, MENU_FONT, LCD_DRAW_SET, FL_ALIGN_LEFT);
|
|
break;
|
|
case(2): //Hardware Fix Menu
|
|
GL_DrawMonoBitmap(menuMore, MENU_MAIN_STATUS_X, MENU_TEST_TEXT_Y_START + (i-displayIndex)*MENU_LINE_HEIGHT + MENU_MAIN_STATUS_Y_OFF, LCD_DRAW_SET);
|
|
break;
|
|
case(3): //Frog
|
|
GL_DrawMonoBitmap(menuMore, MENU_MAIN_STATUS_X, MENU_TEST_TEXT_Y_START + (i-displayIndex)*MENU_LINE_HEIGHT + MENU_MAIN_STATUS_Y_OFF, LCD_DRAW_SET);
|
|
break;
|
|
case(4): //Tuna
|
|
GL_DrawMonoBitmap(menuMore, MENU_MAIN_STATUS_X, MENU_TEST_TEXT_Y_START + (i-displayIndex)*MENU_LINE_HEIGHT + MENU_MAIN_STATUS_Y_OFF, LCD_DRAW_SET);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
//Draw selection bar
|
|
uint32_t selRectY0 = MENU_TEST_TEXT_Y_START + (selected - displayIndex)*MENU_LINE_HEIGHT;
|
|
GL_DrawFilledRectangle(MENU_SEL_RECT_X0, selRectY0, MENU_SEL_RECT_X1, selRectY0 + MENU_LINE_HEIGHT, LCD_DRAW_XOR);
|
|
|
|
|
|
DrawTestMenuScrollBar(displayIndex, menuNum);
|
|
|
|
|
|
LCD_Update();
|
|
}
|
|
|