📄 menus.c
字号:
#include "Main.h"
unsigned char digits[10];
unsigned int digit_index = 0;
extern struct stCanObj
{
ubyte ubData[8]; // Message Data 0..7
ulong ulCANAR; // Arbitration Register
ulong ulCANAMR; // Acceptance Mask Register
uword uwMSGCTR; // Message Control Register
uword uwCounter; // Frame Counter
uword uwMSGCFG; // Message Configuration Register
uword uwINP; // Interrupt Node Pointer
uword uwCANFCR; // FIFO / Gateway Control Register
uword uwCANPTR; // FIFO Pointer
ulong ulReserved; // Reserved
};
void PrintMainMenu(void)
{
unsigned int i;
printf("\033[2J"); // Clear Screen
printf("MO: Node: DIR: ID: Data: MO: Node: DIR: ID: Data:\n");
for (i = 0; i< 31; i+=2)
{
printf("%02d",i); // MO
printf(" -"); // Node
printf(" --"); // DIR
printf(" ----"); // ID
printf(" --------"); // Data
printf(" %02d",i+1); // MO
printf(" -"); // Node
printf(" --"); // DIR
printf(" ----"); // ID
printf(" --------\n"); // Data
}
PrintPrompt(0,0);
}
void PrintPrompt(unsigned int p, unsigned int mo)
{
unsigned int i;
TCAN_SWObj SW_MO;
for(i = 18; i<25; i++)
{
MoveCursor(CursorPosY=i, CursorPosX=1);
printf("\033[2K"); // Clear Line
}
if(p==0) // Main Propmpt
{
MoveCursor(CursorPosY=22,CursorPosX=1);
printf("Enter 'E' to Edit MO, Enter 'T' to Transmit MO, Enter 'R' to Refresh:\n");
CursorPosX = 1;
CursorPosY = 23;
}
else if (p==1) // Transmit Prompt
{
MoveCursor(CursorPosY=22, CursorPosX=1);
printf("Enter MO# to Transmit (ESC to go back):\n");
CursorPosX = 1;
CursorPosY = 23;
}
else if (p == 2)
{
MoveCursor(CursorPosY=22, CursorPosX=1);
printf("Enter MO# to Edit (ESC to go back):\n");
CursorPosY++;
}
else if (p == 3)
{
MoveCursor(CursorPosY=19, CursorPosX=1);
printf("Current Settings for MO: %d", mo);
printf("\n"); // New line
CAN_vGetMsgObj(mo, &SW_MO);
if(SW_MO.uwMsgCfg&0x2)
printf("Node=B ");
else
printf("Node=A ");
if(SW_MO.uwMsgCfg & 0x08)
printf("DIR=TX "); // DIR
else
printf("DIR=RX "); // DIR
printf("ID=0x%03x", SW_MO.ulID); // ID
printf(" ");
printf("Mask=0x%03x",SW_MO.ulMask & 0x7FF);
printf(" Data=");
for(i = 0; i < 8; i++)
{
if (i >= ((SW_MO.uwMsgCfg&0x00F0)>>4) )
putchar('-');
else
{
if( (SW_MO.ubData[i] > 31) && (SW_MO.ubData[i] < 127) )
putchar(SW_MO.ubData[i]); // Data
else
putchar('-');
}
}
printf("\n\n"); // New lines
printf("Enter Field to Edit: N=Node, R=RX, T=TX, I=ID, M=Mask, D=Data, V=Enable\\Disable\n");
CursorPosX = 1;
CursorPosY = 23;
}
else if (p == 4)
{
MoveCursor(CursorPosY=19, CursorPosX=1);
printf("Current Settings for MO: %d", mo);
printf("\n"); // New line
CAN_vGetMsgObj(mo, &SW_MO);
if(SW_MO.uwMsgCfg&0x2)
printf("Node=B ");
else
printf("Node=A ");
if(SW_MO.uwMsgCfg & 0x08)
printf("DIR=TX "); // DIR
else
printf("DIR=RX "); // DIR
printf("ID=0x%03x", SW_MO.ulID); // ID
printf(" ");
printf("Mask=0x%03x",SW_MO.ulMask & 0x7FF);
printf(" Data=");
for(i = 0; i < 8; i++)
{
if (i >= ((SW_MO.uwMsgCfg&0x00F0)>>4) )
putchar('-');
else
{
if( (SW_MO.ubData[i] > 31) && (SW_MO.ubData[i] < 127) )
putchar(SW_MO.ubData[i]); // Data
else
putchar('-');
}
}
printf("\n\n"); // New lines
printf("Enter 'A' or 'B' to Assign the MO to Node A or B:\n");
CursorPosX = 1;
CursorPosY = 23;
}
else if (p == 5)
{
MoveCursor(CursorPosY=19, CursorPosX=1);
printf("Current Settings for MO: %d", mo);
printf("\n"); // New line
CAN_vGetMsgObj(mo, &SW_MO);
if(SW_MO.uwMsgCfg&0x2)
printf("Node=B ");
else
printf("Node=A ");
if(SW_MO.uwMsgCfg & 0x08)
printf("DIR=TX "); // DIR
else
printf("DIR=RX "); // DIR
printf("ID=0x%03x", SW_MO.ulID); // ID
printf(" ");
printf("Mask=0x%03x",SW_MO.ulMask & 0x7FF);
printf(" Data=");
for(i = 0; i < 8; i++)
{
if (i >= ((SW_MO.uwMsgCfg&0x00F0)>>4) )
putchar('-');
else
{
if( (SW_MO.ubData[i] > 31) && (SW_MO.ubData[i] < 127) )
putchar(SW_MO.ubData[i]); // Data
else
putchar('-');
}
}
printf("\n\n"); // New lines
printf("Enter the ID in Hex (upto 11 bits):\n");
printf("0x");
CursorPosX = 3;
CursorPosY = 23;
}
else if (p == 6)
{
MoveCursor(CursorPosY=19, CursorPosX=1);
printf("Current Settings for MO: %d", mo);
printf("\n"); // New line
CAN_vGetMsgObj(mo, &SW_MO);
if(SW_MO.uwMsgCfg&0x2)
printf("Node=B ");
else
printf("Node=A ");
if(SW_MO.uwMsgCfg & 0x08)
printf("DIR=TX "); // DIR
else
printf("DIR=RX "); // DIR
printf("ID=0x%03x", SW_MO.ulID); // ID
printf(" ");
printf("Mask=0x%03x",SW_MO.ulMask & 0x7FF);
printf(" Data=");
for(i = 0; i < 8; i++)
{
if (i >= ((SW_MO.uwMsgCfg&0x00F0)>>4) )
putchar('-');
else
{
if( (SW_MO.ubData[i] > 31) && (SW_MO.ubData[i] < 127) )
putchar(SW_MO.ubData[i]); // Data
else
putchar('-');
}
}
printf("\n\n"); // New lines
printf("Enter the 11-bit Mask in Hex (0=don't care, 1=care about ID bit):\n");
printf("0x");
CursorPosX = 3;
CursorPosY = 23;
}
else if (p == 7)
{
MoveCursor(CursorPosY=19, CursorPosX=1);
printf("Current Settings for MO: %d", mo);
printf("\n"); // New line
CAN_vGetMsgObj(mo, &SW_MO);
if(SW_MO.uwMsgCfg&0x2)
printf("Node=B ");
else
printf("Node=A ");
if(SW_MO.uwMsgCfg & 0x08)
printf("DIR=TX "); // DIR
else
printf("DIR=RX "); // DIR
printf("ID=0x%03x", SW_MO.ulID); // ID
printf(" ");
printf("Mask=0x%03x",SW_MO.ulMask & 0x7FF);
printf(" Data=");
for(i = 0; i < 8; i++)
{
if (i >= ((SW_MO.uwMsgCfg&0x00F0)>>4) )
putchar('-');
else
{
if( (SW_MO.ubData[i] > 31) && (SW_MO.ubData[i] < 127) )
putchar(SW_MO.ubData[i]); // Data
else
putchar('-');
}
}
printf("\n\n"); // New lines
printf("Enter upto 8 characters for the frame data (data sent will be characters):\n");
CursorPosX = 1;
CursorPosY = 23;
}
else if (p == 8)
{
MoveCursor(CursorPosY=19, CursorPosX=1);
printf("Current Settings for MO: %d", mo);
printf("\n"); // New line
CAN_vGetMsgObj(mo, &SW_MO);
if(SW_MO.uwMsgCfg&0x2)
printf("Node=B ");
else
printf("Node=A ");
if(SW_MO.uwMsgCfg & 0x08)
printf("DIR=TX "); // DIR
else
printf("DIR=RX "); // DIR
printf("ID=0x%03x", SW_MO.ulID); // ID
printf(" ");
printf("Mask=0x%03x",SW_MO.ulMask & 0x7FF);
printf(" Data=");
for(i = 0; i < 8; i++)
{
if (i >= ((SW_MO.uwMsgCfg&0x00F0)>>4) )
putchar('-');
else
{
if( (SW_MO.ubData[i] > 31) && (SW_MO.ubData[i] < 127) )
putchar(SW_MO.ubData[i]); // Data
else
putchar('-');
}
}
printf("\n\n"); // New lines
printf("Enter 'E' to Enable the Message Objec or 'D' to Disable the Message Object:\n");
CursorPosX = 1;
CursorPosY = 23;
}
for (i = 0; i< 10 ; i++)
digits[i] = 0;
digit_index = 0;
}
void MoveCursor(unsigned int y, unsigned int x)
{
unsigned int i;
printf("\033[f"); // Move cursor to upper left corner
for (i = 1; i< y; i++)
printf("\033[1B"); // Move cursor down one line
for (i = 1; i< x; i++)
printf("\033[1C"); // Move cursor Right one space
}
void UpdateStatus(void)
{
unsigned int i;
//unsigned int j;
unsigned int k;
for (i = 0; i<32; i++)
{
if (MO_Status[i])
{
MO_Status[i] = 0;
if(i & 0x01)
{
MoveCursor((i>>1)+2, 42);
}
else
{
MoveCursor((i>>1)+2, 1);
}
printf(" "); // Clear field
printf("\033[31D"); // Move Cursor back
if (CAN_HWOBJ[i].uwMSGCTR & 0x0080) // if MO valid
{
CAN_vGetMsgObj(i, &SW_MOs[i]);
printf("%02d",i); // MO
if(SW_MOs[i].uwMsgCfg & 0x2)
printf(" B");
else
printf(" A");
if(SW_MOs[i].uwMsgCfg & 0x08)
printf(" TX"); // DIR
else
printf(" RX"); // DIR
printf(" 0x%03x", SW_MOs[i].ulID); // ID
printf(" ");
printf("0x%03x", SW_MOs[i].ulMask & 0x7FF);
printf(" ");
for(k = 0; k < 8; k++)
{
if (k >= ((SW_MOs[i].uwMsgCfg&0x00F0)>>4) )
putchar('-');
else
{
if( (SW_MOs[i].ubData[k] > 31) && (SW_MOs[i].ubData[k] < 127) )
putchar(SW_MOs[i].ubData[k]); // Data
else
putchar('-');
}
}
}
else
{
printf("%02d",i); // MO
printf(" -"); // Node
printf(" --"); // DIR
printf(" -----"); // ID
printf(" -----"); // Mask
printf(" --------"); // Data
}
MoveCursor(CursorPosY, CursorPosX);
}
}
}
void MenuHandler(void)
{
unsigned int key;
volatile unsigned int i;
static unsigned int mo;
// TCAN_SWObj SW_MO;
_atomic_(0);
i = WriteIndex;
_endatomic_();
if(i != ReadIndex)
{
key = KeyBuf[ReadIndex++];
if (ReadIndex == 12)
ReadIndex = 0;
switch (MenuID)
{
case 0:
if(key== 'T' || key == 't')
{
putchar(key);
PrintPrompt(1,mo);
MenuID = 1;
}
else if(key == 'E' || key == 'e')
{
PrintPrompt(2,0);
MenuID = 2;
}
else if (key == 'R' || key == 'r')
{
printf("\033[2J"); // Clear Screen
printf("MO: Node: DIR: ID: Mask: Data: MO: Node: DIR: ID: Mask: Data:\n");
for (i = 0; i<32; i++)
{
MO_Status[i] = 1;
}
PrintPrompt(0,mo);
}
break;
case 1:
if (key == 27) // Escape
{
PrintPrompt(0,mo);
MenuID = 0;
}
if (digit_index)
{
if (key == 8) // Backspace
{
MoveCursor(CursorPosY, --CursorPosX);
putchar(' ');
MoveCursor(CursorPosY, CursorPosX);
digits[--digit_index] = 0;
}
}
if(digit_index < 3)
{
if (digit_index)
{
if (key == 13) //Enter
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -