|
Page 1 of 1
|
[ 8 posts ] |
|
Development of Scrolling Menu!
| Author |
Message |
|
Ripley
Rookie
Joined: Sun Sep 25, 2011 3:22 am Posts: 5
|
 Development of Scrolling Menu!
Hi there...I am trying to develop a scrolling menu very similar to the main menu of the NXT...Does anyone know how i can go about doing this?
|
| Sun Sep 25, 2011 3:28 am |
|
 |
|
Dick Swan
Creator
Joined: Fri Feb 09, 2007 9:21 am Posts: 613
|
 Re: Development of Scrolling Menu!
look for some of the examples that read the NXT buttons. You can determined whether the LEFT, RIGHT, ENTER or EXIT button is pushed. You could use LEFT / RIGHT to select an index within a list of text commands. ENTER can be used to select a command or begin a sub-menu. EXIT can popup a menu level or exit a command.
NOTE: hardward constraints allow only a single button to be pushed at a time.
NOTE: Above will work with a list of text commands. It's a lot harder if you wanted to have the "icons" displayed as in the NXT menus.
|
| Sun Sep 25, 2011 8:25 am |
|
 |
|
Ripley
Rookie
Joined: Sun Sep 25, 2011 3:22 am Posts: 5
|
 Re: Development of Scrolling Menu!
hey there, i found an example that kind of is what i'm looking for! the "Program Chooser" sample program has the kind of idea of what im after. I have tried messing around with the code but i could only get it down to 1 error. If somebody could help me figure out the working of that code that would be appreciated. Also if anybody knows anything about the option...that would help me a lot...there are no help files on that! Thanks! Ripley!
|
| Mon Sep 26, 2011 6:10 am |
|
 |
|
Ripley
Rookie
Joined: Sun Sep 25, 2011 3:22 am Posts: 5
|
 Re: Development of Scrolling Menu!
This is the "Program Chooser" Code:  |  |  |  | Code: //*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//
/////////////////////////////////////////////////////////////////////////////////////////////////// // // Select Tele-Operation Executable Program for FTC Tele-operation Contest Phase // // FTC competition programs can be operated in two modes: // 1. A single user program is used for both autonomous and tele-operated phases of a // competition. // 2. Separate programs are used for each of the two phases. // // When dual mode is used, the name of the tele-operated phase is stored in a text file. // The Competition field management system will read this file to obtain the name of the // program to run for the tele-op phase. // // This nifty little utility is used to setup the configuration file. // // It also illustrates the use of easily creating programs using standard menus // with ROBOTC. // ///////////////////////////////////////////////////////////////////////////////////////////////////
#include "MenusAndIcons.c"
const string sTextFileName = "FTCConfig.txt"; // Name of the file containg tele-op name
// // Global variables to hold a list of all executable files // const int kMaxFiles = 25; int nNumbOfFiles; string sFileNames[kMaxFiles];
const string sSelectModePrompt = "Select Mode";
/////////////////////////////////////////////////////////////////////////////////////////////////// // // Build List of Executable Files // ///////////////////////////////////////////////////////////////////////////////////////////////////
void buildFileList() { TFileHandle hFileHandle; TFileIOResult nIoResult; string sFileName; short nFileSize; const string sFileSearch = "*.rxe"; // Wildcard to search for any executable file
FindFirstFile(hFileHandle, nIoResult, sFileSearch, sFileName, nFileSize); nNumbOfFiles = 0; while (nIoResult == ioRsltSuccess) { StringDelete(sFileName, strlen(sFileName) - 4, 4); // Trim File Extension sFileNames[nNumbOfFiles] = sFileName; ++nNumbOfFiles; FindNextFile(hFileHandle, nIoResult, sFileName, nFileSize); } Close(hFileHandle, nIoResult); return; }
/////////////////////////////////////////////////////////////////////////////////////////////////// // // displayCommandProgress // ///////////////////////////////////////////////////////////////////////////////////////////////////
void displayCommandProgress(const string &sProgress) { // Display Message
nxtDisplayTextLine(5, ""); nxtDisplayCenteredTextLine(6, sProgress); nxtDisplayTextLine(7, ""); wait1Msec(1250); }
/////////////////////////////////////////////////////////////////////////////////////////////////// // // displayCommandProgress // ///////////////////////////////////////////////////////////////////////////////////////////////////
void deleteTeleOpConfigFile() { TFileIOResult nIoResult;
do // Make a loop in case, due to error, there are multiple copies { Delete(sTextFileName, nIoResult); } while (nIoResult == ioRsltSuccess); }
/////////////////////////////////////////////////////////////////////////////////////////////////// // // createTeleopConfigFile // ///////////////////////////////////////////////////////////////////////////////////////////////////
void createTeleopConfigFile(string &sExecutableName) { TFileIOResult nIoResult; TFileHandle hFileHandle; short nFileSize;
deleteTeleOpConfigFile(); // Erase existing file
// Create the file
nFileSize = strlen(sExecutableName) + 4; OpenWrite(hFileHandle, nIoResult, sTextFileName, nFileSize); WriteText(hFileHandle, nIoResult, sExecutableName); WriteText(hFileHandle, nIoResult, ".rxe"); Close(hFileHandle, nIoResult);
// Display Message
displayCommandProgress((nIoResult == ioRsltSuccess) ? "Entering Tracking" : "Entering Config"); return; }
/////////////////////////////////////////////////////////////////////////////////////////////////// // // Menu Processing -- Select an Executable File // // Presents a menu of the available executable files on the NXT so that the user can select the // name of the file to run for the tele-op phase of a FTC competition. // ///////////////////////////////////////////////////////////////////////////////////////////////////
bool doDualModeFileSelection() { int nFileIndex; TMenuAnimationType nDrawType;
nDrawType = menuOverwrite; nFileIndex = 0; while (true) { switch (nNxtButtonTransition) { case kRightButton: ++nFileIndex; if (nFileIndex >= nNumbOfFiles) nFileIndex = 0; nDrawType = menuFromLeft; break;
case kLeftButton: --nFileIndex; if (nFileIndex < 0) nFileIndex = nNumbOfFiles - 1; nDrawType = menuFromRight; break;
case kEnterButton: createTeleopConfigFile(sFileNames[nFileIndex]); nDrawType = menuFromBottom; return true;
case kExitButton: return false;
default: break; }
if (nDrawType != menuRefreshComplete) { drawMenu(nDrawType, iconFileTypeExeFiles, iconFileTypeExeFiles, iconFileTypeExeFiles, sFileNames[nFileIndex], "Select File"); nDrawType = menuRefreshComplete; } } }
/////////////////////////////////////////////////////////////////////////////////////////////////// // // Menu Processing -- Single vs Dual Mode Program Execution // ///////////////////////////////////////////////////////////////////////////////////////////////////
void doSingleOrDualModeSelection() { bool bSingle;
bSingle = false; drawMenu(menuFromTop, iconNone, iconMyFiles, iconFileTypeExeFiles, "Config", sSelectModePrompt); while (true) { switch (nNxtButtonTransition) { case kRightButton: case kLeftButton: // Toggle boolean mode selection with 'left' / 'right' keypress
if (!bSingle) drawMenu(menuFromRight, iconMyFiles, iconFileTypeExeFiles, iconNone, "Tracker", sSelectModePrompt); else drawMenu(menuFromLeft, iconNone, iconMyFiles, iconFileTypeExeFiles, "Config", sSelectModePrompt); bSingle = !bSingle; break;
case kEnterButton: if (bSingle) { deleteTeleOpConfigFile(); displayCommandProgress("Tracking"); return; } else if (doDualModeFileSelection()) return; // File was selected. Exit the program.
// "Exit" without file selection. Redraw menu. drawMenu(menuFromBottom, iconNone, iconMyFiles, iconFileTypeExeFiles, "Config", sSelectModePrompt); break;
case kExitButton: return;
default: break; } } }
task main() { nNxtButtonTask = -2; nNxtExitClicks = 4; buildFileList(); doSingleOrDualModeSelection(); } |  |  |  |  |
|
| Mon Sep 26, 2011 6:11 am |
|
 |
|
Dick Swan
Creator
Joined: Fri Feb 09, 2007 9:21 am Posts: 613
|
 Re: Development of Scrolling Menu!
Attached file has documentation on the "drawMenu" command.
|
| Mon Sep 26, 2011 7:25 am |
|
 |
|
Ripley
Rookie
Joined: Sun Sep 25, 2011 3:22 am Posts: 5
|
 Re: Development of Scrolling Menu!
Thanks for that! Can i ask where you got this file from as i struggled a lot to finds any information on this code! Thanks in advance!
|
| Mon Sep 26, 2011 7:58 am |
|
 |
|
Ripley
Rookie
Joined: Sun Sep 25, 2011 3:22 am Posts: 5
|
 Re: Development of Scrolling Menu!
OK here is the code that i have gotten so far...but it only responds to the original state so the scrolling is slightly broken...if anyone has any advice i would appreciate it!  |  |  |  | Code: #include "MenusAndIcons.c"
// // Global variables to hold a list of all executable files //
void one() { drawMenu(menuFromTop, iconDataGraph, iconSettings, iconLightAmbient, "Config", sSelectModePrompt); }
void two() { drawMenu(menuFromRight,iconSettings, iconLightAmbient, iconDataGraph, "Tracker", sSelectModePrompt); }
void three() { drawMenu(menuFromRight,iconLightAmbient, iconDataGraph, iconSettings, "Tracker", sSelectModePrompt); }
//============================================================================================ void displayCommandProgress(const string &sProgress) { // Display Message
nxtDisplayTextLine(5, "HI"); nxtDisplayCenteredTextLine(6, sProgress); nxtDisplayTextLine(7, ""); wait1Msec(1250); } //============================================================================================ void tracking() { eraseDisplay(); wait10Msec(10); nxtDisplayTextLine(5, "TRACKING"); nxtDisplayTextLine(7, " %3.1fV", nAvgBatteryLevel / (float) 1000, nImmediateBatteryLevel / (float) 10000); wait1Msec(1250);
}
//============================================================================================ void ModeSelection() { bool bSingle;
bSingle = false; one(); while (true) { switch (nNxtButtonTransition) { case kRightButton: // Toggle boolean mode selection with 'right' keypress
if (!bSingle) two(); else one(); bSingle = !bSingle; break; //========================================================================================================== case kLeftButton: // Toggle boolean mode selection with 'left' keypress
if (!bSingle) three(); else one(); bSingle = !bSingle; break; //========================================================================================================== case kEnterButton: if (bSingle) { displayCommandProgress("Tracking"); tracking(); return; } else { displayCommandProgress("Entering Config"); }
// "Exit". Redraw menu. drawMenu(menuFromBottom, iconDataGraph, iconSettings, iconLightAmbient, "Config", sSelectModePrompt); break;
case kExitButton: return;
default: break; } } }
task main() { nNxtButtonTask = -2; nNxtExitClicks = 4; ModeSelection(); } |  |  |  |  |
|
| Mon Sep 26, 2011 10:53 am |
|
 |
|
MHTS
Guru
Joined: Sun Nov 15, 2009 5:46 am Posts: 1023
|
 Re: Development of Scrolling Menu!
Our team has a generic menu module that allows you to display a choice menu of up to 6 choices. At the beginning of the competition, it displays the choice menu and allows the user to select the choice by the left and right buttons and the orange button of the NXT. Once the choice is made, the code will go into "waitForStart". You can find the menu module here: http://proj.titanrobotics.net/hg/Ftc/20 ... lib/menu.hThe code that uses the menu module can be found here in the RobotInit() function: http://proj.titanrobotics.net/hg/Ftc/20 ... AutoMain.hThe limitation of this module is the max of 6 choices which worked fine last year. But we anticipate to have more autonomous routines this year. So we will be extending the menu module with scrolling capability so it can virtually accommodate unlimited choices (as far as RobotC allows).
|
| Tue Sep 27, 2011 4:38 pm |
|
|
|
Page 1 of 1
|
[ 8 posts ] |
|
Who is online |
Users browsing this forum: No registered users and 4 guests |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|