[NXC UserInteraction Library]

Project date: Mar 2012
Tags: Mindstorms :: robotics

Current version: 1.2 :: Follow me on Twitter for updates

The User Interaction (UIn) Library helps you create standard user interfaces (multi-line aligned texts, buttons, menus, etc.) and capture user actions on the NXT Mindstorms brick. The library works with the intelligent brick buttons and keeps all your sensor ports free for your program to use.

The UIn Library is a single .h file that can be included with your NXC project. It has been tested with NBC version 1.2.1 r4 and requires the NXC extended firmware. Please read the development setup tutorial if you are not sure how to get extended firmware.

Main features

How it works

Download a demo (XCode) project to try out the whole UserInteraction library.

This is an example of using a sliding menu in order to decide which task to exectute. UIn function createSlidingMenu() is called with appropriate arguments and the program waits until user selects an option from the menu. The user choice is then resolved by the calling task. Note that ExitTo(Task newTask) is used in order to close the current task and start a new one. This prevents unpredictable behaviour of the new task when calling UIn and other functions.

#include "UserInteraction.h"

task main() {

    //-- create menu with 2-line option items
    string menuItems[3] = {"First#Option","Second#Option", "Third#Option"};
    int userResponse = createSlidingMenu("Select#an option",menuItems, 0);

    //-- resolve answer from the sliding menu
    switch (userResponse) {
        case 0:
            // Selected 'First Option'
            ExitTo(onFirstOption);
            break;
        case 1:
            // Selected 'Second Option'
            ExitTo(onSecondOption);
            break;
        default:
            // Selected 'Third Option'
            ExitTo(onThirdOption);
            break;
    }
}

task onFirstOption() {}
task onSecondOption() {}
task onThirdOption() {}

}

Other features

Text drawing functions

Shape-drawing functions

Helper functions

  • int getTextPixelLength (string text_)
  • int getAlignedTextPosition (string text_, UIN_ALIGNMENT alignment_)
  • int normaliseTextXPosition (string text_, int xPosition_)
  • int lastPos(string substr_, string string_)

Math functions

  • int round (float number_)
  • float abs (float number_)

Other


Please comment or email me if you have questions or ideas about new functionality.


{Please enable JavaScript in order to post comments}

[Blog]

Ultrastable Neuroendocrine Robot is born

I have finally put a beginning of an artificial brain to my Ultrastable Neuroendocrine Robot - UNER... my lego robot can now measure inputs from its 3 front proximity sensors and individual cells in its brain get activated when it sees something

[Read full]

Busy working on Alien Farm

For the last couple of weeks, I have been working on a strategy game with working name 'Alien Farm'. I have done a lot of improvements and bug fixes and almost ready to move to creating a few campaign missions...

[Read full]