📄 c_ui.c
字号:
//
// Programmer
//
// Date init 14.12.2004
//
// Reviser $Author:: Dktochpe $
//
// Revision date $Date:: 2-03-06 13:03 $
//
// Filename $Workfile:: c_ui.c $
//
// Version $Revision:: 135 $
//
// Archive $Archive:: /LMS2006/Sys01/Main/Firmware/Source/c_ui.c $
//
// Platform C
//
#include "stdio.h"
#include "string.h"
#include "ctype.h"
#include "stdconst.h"
#include "modules.h"
#include "c_ui.iom"
#include "c_ui.h"
#include "m_sched.h"
#include "c_display.iom"
#include "c_loader.iom"
#include "c_button.iom"
#include "c_sound.iom"
#include "c_input.iom"
#include "c_output.iom"
#include "c_ioctrl.iom"
#include "c_cmd.iom"
#include "c_comm.iom"
#include "c_lowspeed.iom"
static IOMAPUI IOMapUi;
static VARSUI VarsUi;
static HEADER **pHeaders;
const HEADER cUi =
{
0x000C0001L,
"Ui",
cUiInit,
cUiCtrl,
cUiExit,
(void *)&IOMapUi,
(void *)&VarsUi,
(UWORD)sizeof(IOMapUi),
(UWORD)sizeof(VarsUi),
0x0000 // Code size - not used so far
};
// ****** GENERAL GRAPHIC RESOURCES ******************************************
#include "Display.txt" // Bitmap for frame used in view and datalog
#include "LowBattery.txt" // Bitmap showed when low battery occures
#include "Font.txt" // Font used for all text
#include "Step.txt" // Bitmap used in On Brick Programming
#include "Cursor.txt" // Bitmap for cursor
#include "Running.txt" // Icon collection used for "running" symbol
#include "Port.txt" // Font used for naming sensor ports in datalog/bluetooth
#include "Ok.txt" // Bitmap for OK buttom in get user string
#include "Wait.txt" // Bitmap for feedback
#include "Fail.txt" // Bitmap for feedback
#include "Info.txt" // Bitmap for feedback
#include "Icons.txt" // Icon collection used for menues
// ****** INTRO ANIMATION RESOURCES ******************************************
#include "RCXintro_1.txt" // Bitmap for picture 1 in the intro animation
#include "RCXintro_2.txt" // Bitmap for picture 2 in the intro animation
#include "RCXintro_3.txt" // Bitmap for picture 3 in the intro animation
#include "RCXintro_4.txt" // Bitmap for picture 4 in the intro animation
#include "RCXintro_5.txt" // Bitmap for picture 5 in the intro animation
#include "RCXintro_6.txt" // Bitmap for picture 6 in the intro animation
#include "RCXintro_7.txt" // Bitmap for picture 7 in the intro animation
#include "RCXintro_8.txt" // Bitmap for picture 8 in the intro animation
#include "RCXintro_9.txt" // Bitmap for picture 9 in the intro animation
#include "RCXintro_10.txt" // Bitmap for picture 10 in the intro animation
#include "RCXintro_11.txt" // Bitmap for picture 11 in the intro animation
#include "RCXintro_12.txt" // Bitmap for picture 12 in the intro animation
#include "RCXintro_13.txt" // Bitmap for picture 13 in the intro animation
#include "RCXintro_14.txt" // Bitmap for picture 14 in the intro animation
#include "RCXintro_15.txt" // Bitmap for picture 15 in the intro animation
#include "RCXintro_16.txt" // Bitmap for picture 16 in the intro animation
const BMPMAP *Intro[NO_OF_INTROBITMAPS] = // Picture sequence for the intro animation
{
(BMPMAP*)RCXintro_1,
(BMPMAP*)RCXintro_2,
(BMPMAP*)RCXintro_3,
(BMPMAP*)RCXintro_4,
(BMPMAP*)RCXintro_5,
(BMPMAP*)RCXintro_6,
(BMPMAP*)RCXintro_7,
(BMPMAP*)RCXintro_8,
(BMPMAP*)RCXintro_9,
(BMPMAP*)RCXintro_10,
(BMPMAP*)RCXintro_11,
(BMPMAP*)RCXintro_12,
(BMPMAP*)RCXintro_13,
(BMPMAP*)RCXintro_14,
(BMPMAP*)RCXintro_15,
(BMPMAP*)RCXintro_16
};
// ****** STATUS LINE GRAPHIC RESOURCES **************************************
#include "Status.txt" // Status icon collection file
enum STATUS_NO // Index in status icon collection file
{
STATUS_NO_NOT_USED,
STATUS_NO_RUNNING_0,
STATUS_NO_RUNNING_1,
STATUS_NO_RUNNING_2,
STATUS_NO_RUNNING_3,
STATUS_NO_RUNNING_4,
STATUS_NO_RUNNING_5,
STATUS_NO_RUNNING_6,
STATUS_NO_RUNNING_7,
STATUS_NO_RUNNING_8,
STATUS_NO_RUNNING_9,
STATUS_NO_RUNNING_10,
STATUS_NO_RUNNING_11,
STATUS_NO_BATTERY_0,
STATUS_NO_BATTERY_1,
STATUS_NO_BATTERY_2,
STATUS_NO_BATTERY_3,
STATUS_NO_BATTERY_4,
STATUS_NO_BATTERY_5,
STATUS_NO_RECHARGEABLE_0,
STATUS_NO_RECHARGEABLE_1,
STATUS_NO_RECHARGEABLE_2,
STATUS_NO_RECHARGEABLE_3,
STATUS_NO_RECHARGEABLE_4,
STATUS_NO_RECHARGEABLE_5,
STATUS_NO_BLUETOOTH_0,
STATUS_NO_BLUETOOTH_1,
STATUS_NO_BLUETOOTH_2,
STATUS_NO_BLUETOOTH_3,
STATUS_NO_BLUETOOTH_4,
STATUS_NO_BLUETOOTH_5,
STATUS_NO_USB_0,
STATUS_NO_USB_1,
STATUS_NO_USB_2,
STATUS_NO_USB_3,
STATUS_NO_USB_4,
STATUS_NO_USB_5
};
// ****** BT DEVICE GRAPHIC RESOURCES ****************************************
#include "Devices.txt" // Icon collection used for Blue tooth devices
enum
{
DEVICETYPE_UNKNOWN,
DEVICETYPE_NXT,
DEVICETYPE_PHONE,
DEVICETYPE_PC
};
// ****** BT CONNECTIONS GRAPHIC RESOURCES ***********************************
#include "Connections.txt" // Icon collection used for Blue tooth connections
// ****** FREE TEXT GRAPHIC RESOURCES ****************************************
#include "Ui.txt" // Text strings that is'nt defined in menu files
enum // String index in text string file
{
TXT_GENERAL_EMPTY,
// BlueTooth connect
TXT_FB_BT_CONNECTING_WAIT, // "Connecting"
TXT_FB_BT_CONNECT_BUSY_FAIL, // "Line is busy"
TXT_FB_BT_CONNECTING_FAIL, // "Failed!"
// BlueTooth send file
TXT_FB_BT_SENDING_NO_CONN_FAIL, // "Connection?"
TXT_FB_BT_SENDING_WAIT, // "Sending file"
TXT_FB_BT_SENDING_FAIL, // "Failed!"
// BlueTooth on/off
TXT_FB_BT_TURNING_ON_WAIT, // "Turning on"
TXT_FB_BT_TURNING_ON_FAIL, // "Failed!"
TXT_FB_BT_TURNING_OFF_WAIT, // "Turning off"
TXT_FB_BT_TURNING_OFF_FAIL, // "Failed!"
// BlueTooth seach
TXT_FB_BT_SEARCHING_WAIT, // "Searching"
TXT_FB_BT_SEARCH_ABORTED_INFO, // "Aborted!"
TXT_FB_BT_SEARCHING_FAIL, // "Failed!"
// BlueTooth device list
TXT_FB_BT_REMOVE_FAIL, // "Failed!"
// BlueTooth connection list
TXT_FB_BT_DISCONNECT_FAIL, // "Failed!"
// On Brick Programming
TXT_FB_OBP_MEMORY_FULL_FAIL, // "Memory full!"
TXT_FB_OBP_FILE_SAVED_INFO, // "File saved"
TXT_FB_OBP_FILE_EXIST_FAIL, // "File exist"
TXT_FB_OBP_OVERWRITE_FAIL, // "overwrite!"
// File delete
TXT_FB_FD_FILE_DELETED_INFO, // "File deleted"
// Files delete
TXT_FB_FD_FILES_INFO, // "Files"
TXT_FB_FD_DELETED_INFO, // "deleted"
// File run
TXT_FILERUN_RUNNING, // "Running"
TXT_FILERUN_ABORTED, // "Aborted!"
TXT_FILERUN_ENDED, // "Ended"
TXT_FILERUN_FILE_ERROR, // "File error!"
// Files delete
TXT_FILESDELETE_DELETING_ALL, // "Deleting all"
TXT_FILESDELETE_S_FILES, // "%s files!"
// File types
TXT_FILETYPE_SOUND, // "Sound"
TXT_FILETYPE_LMS, // "Software"
TXT_FILETYPE_NXT, // "NXT"
TXT_FILETYPE_TRY_ME, // "Try me"
TXT_FILETYPE_DATA, // "Datalog"
// Get user string
TXT_GETUSERSTRING_PIN, // "Pin:"
TXT_GETUSERSTRING_FILENAME, // "Filename:"
// On Brick Programming
TXT_ONBRICKPROGRAMMING_PLEASE_USE_PORT, // "Please use port:"
TXT_ONBRICKPROGRAMMING_1_TOUCH_SENSOR, // "1 - Touch sensor"
TXT_ONBRICKPROGRAMMING_2_SOUND_SENSOR, // "2 - Sound sensor"
TXT_ONBRICKPROGRAMMING_3_LIGHT_SENSOR, // "3 - Light sensor"
TXT_ONBRICKPROGRAMMING_4_ULTRA_SONIC, // "4 - Ultra sonic"
TXT_ONBRICKPROGRAMMING_BC_LR_MOTORS, // "B/C - L/R motors"
// View
TXT_VIEW_SELECT, // "Select"
// BlueTooth device list
TXT_BTDEVICELIST_SELECT, // "Select"
// BlueTooth connection list
TXT_BTCONNECTLIST_SELECT, // "Select"
// Bluetooth list errors
TXT_FB_BT_ERROR_LR_COULD_NOT_SAVE_1, // BT save data error!
TXT_FB_BT_ERROR_LR_COULD_NOT_SAVE_2, //
TXT_FB_BT_ERROR_LR_STORE_IS_FULL_1, // BT store is full error!
TXT_FB_BT_ERROR_LR_STORE_IS_FULL_2, //
TXT_FB_BT_ERROR_LR_UNKOWN_ADDR_1, // BT unknown addr. error!
TXT_FB_BT_ERROR_LR_UNKOWN_ADDR_2, //
// Power of time
TXT_POWEROFFTIME_NEVER // "Never"
};
// ****** FILE TYPE GRAPHIC RESOURCES ****************************************
#define ALLFILES 0x1A // Icon collection offset
enum // File type id's
{
FILETYPE_ALL, // 0 = All
FILETYPE_SOUND, // 1 = Sound
FILETYPE_LMS, // 2 = LMS
FILETYPE_NXT, // 3 = NXT
FILETYPE_TRYME, // 4 = Try me
FILETYPE_DATALOG, // 5 = Datalog
FILETYPES
};
const UBYTE TXT_FILE_EXT[FILETYPES][4] =
{
"*", // 0 = All
TXT_SOUND_EXT, // 1 = Sound
TXT_LMS_EXT, // 2 = LMS
TXT_NXT_EXT, // 3 = NXT
TXT_TRYME_EXT, // 4 = Try me
TXT_DATA_EXT // 5 = Datalog
};
const UBYTE TXT_FILETYPE[FILETYPES] =
{
0, // NA
TXT_FILETYPE_SOUND, // 1 = Sound
TXT_FILETYPE_LMS, // 2 = LM
TXT_FILETYPE_NXT, // 3 = NXT
TXT_FILETYPE_TRY_ME,// 4 = Try me
TXT_FILETYPE_DATA // 5 = Datalog
};
// ****** POWER OFF DEFINITIONS **********************************************
#define POWER_OFF_TIME_STEPS 6
#define POWER_OFF_TIME_DEFAULT 3
const UBYTE PowerOffTimeSteps[POWER_OFF_TIME_STEPS] = { 0,2,5,10,30,60 }; // [min]
// ****** BATTERY DEFINITIONS ************************************************
#define BATTERYLIMITS 4 // [Cnt]
#define BATTERYLIMITHYST 100 // [mV]
#define RECHARGEABLELIMITHYST 50 // [mV]
const UWORD BatteryLimits[BATTERYLIMITS] =
{
6100,6500,7000,7500 // [mV]
};
const UWORD RechargeableLimits[BATTERYLIMITS] =
{
7100,7200,7300,7500 // [mV]
};
//******* UI MENU FILE HANDLER *************************************************************************
#include "Mainmenu.rms"
#include "Submenu01.rms"
#include "Submenu02.rms"
#include "Submenu04.rms"
#include "Submenu05.rms"
#include "Submenu06.rms"
#include "Submenu07.rms"
SWORD cUiMenuFile(UBYTE Cmd,UBYTE *pFile,UBYTE *pData,ULONG *pLng)
{
SWORD Result;
UBYTE *pFilePointer;
Result = -1;
switch (Cmd)
{
case OPENREADLINEAR :
{
if (strcmp((char*)pFile,"Mainmenu.rms") == 0)
{
pFilePointer = (UBYTE*)MAINMENU;
Result = 0;
}
if (strcmp((char*)pFile,"Submenu01.rms") == 0)
{
pFilePointer = (UBYTE*)SUBMENU01;
Result = 0;
}
if (strcmp((char*)pFile,"Submenu02.rms") == 0)
{
pFilePointer = (UBYTE*)SUBMENU02;
Result = 0;
}
if (strcmp((char*)pFile,"Submenu04.rms") == 0)
{
pFilePointer = (UBYTE*)SUBMENU04;
Result = 0;
}
if (strcmp((char*)pFile,"Submenu05.rms") == 0)
{
pFilePointer = (UBYTE*)SUBMENU05;
Result = 0;
}
if (strcmp((char*)pFile,"Submenu06.rms") == 0)
{
pFilePointer = (UBYTE*)SUBMENU06;
Result = 0;
}
if (strcmp((char*)pFile,"Submenu07.rms") == 0)
{
pFilePointer = (UBYTE*)SUBMENU07;
Result = 0;
}
if (Result == 0)
{
*pLng = ((UWORD)pFilePointer[2] << 8) + (UWORD)pFilePointer[3] + FILEHEADER_LENGTH;
*((ULONG*)pData) = (ULONG)pFilePointer;
}
}
break;
}
return (Result);
}
//******************************************************************************************************
UBYTE* cUiGetString(UBYTE No) // Get string in text string file
{
UBYTE *Result = NULL;
TXT *pUi;
UWORD Tmp;
pUi = (TXT*)Ui;
if (No)
{
if (No <= pUi->ItemsY)
{
Tmp = No - 1;
Tmp *= pUi->ItemCharsX;
Result = &(pUi->Data[Tmp]);
}
}
return (Result);
}
UBYTE cUiReadButtons(void) // Read buttons
{
UBYTE Result = BUTTON_NONE;
if (!(IOMapUi.Flags & UI_DISABLE_LEFT_RIGHT_ENTER))
{
if ((pMapButton->State[BTN3] & PRESSED_STATE))
{
Result = BUTTON_LEFT;
}
if ((pMapButton->State[BTN2] & PRESSED_STATE))
{
Result = BUTTON_RIGHT;
}
if ((pMapButton->State[BTN4] & PRESSED_STATE))
{
Result = BUTTON_ENTER;
}
}
if (!(IOMapUi.Flags & UI_DISABLE_EXIT))
{
if ((pMapButton->State[BTN1] & PRESSED_STATE))
{
Result = BUTTON_EXIT;
}
}
if (Result == BUTTON_NONE)
{
// All buttons released
VarsUi.ButtonOld = BUTTON_NONE;
VarsUi.ButtonTime = BUTTON_DELAY_TIME;
}
else
{
// Some button pressed
if (VarsUi.ButtonOld == BUTTON_NONE)
{
// Just pressed
VarsUi.ButtonOld = Result;
VarsUi.ButtonTimer = 0;
}
else
{
// Still pressed
Result = BUTTON_NONE;
if (VarsUi.ButtonTimer >= VarsUi.ButtonTime)
{
VarsUi.ButtonTimer = 0;
VarsUi.ButtonTime = BUTTON_REPEAT_TIME;
if ((VarsUi.ButtonOld == BUTTON_LEFT) || (VarsUi.ButtonOld == BUTTON_RIGHT))
{
// If arrow repeat
Result = VarsUi.ButtonOld;
}
}
}
}
if (VarsUi.ButtonOld == BUTTON_NONE)
{
// If no key - check interface
Result = IOMapUi.Button;
IOMapUi.Button = BUTTON_NONE;
}
if (Result != BUTTON_NONE)
{
// If key - play key sound file
sprintf((char*)pMapSound->SoundFilename,"%s.%s",(char*)UI_KEYCLICK_SOUND,(char*)TXT_SOUND_EXT);
pMapSound->Volume = IOMapUi.Volume;
pMapSound->Mode = SOUND_ONCE;
pMapSound->Flags |= SOUND_UPDATE;
// Reset power down timer
IOMapUi.Flags |= UI_RESET_SLEEP_TIMER;
}
return (Result);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -