CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

LCD+keyboard user interface with RTOS

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








LCD+keyboard user interface with RTOS
PostPosted: Sat Jan 27, 2007 1:33 pm     Reply with quote

Hi there.

I am planning to use the CCS RTOS for a device that has signal aquisition, data processing, a user interface with LCD and buttons and a serial communication port, a perfect job for RTOS at the first look. I have never worked with RTOS before, but I learned and understood the basics quickly. I am working with the 18F452.

My great difficulty is implementing the user interface, so that the data aquisition and processing executes in the background while the user browses the menus and reads/modifies parameters. Until now I implemented menu structures with functions for every menu option available. Of course, the menu had several levels. Periodic processing of signals was done with timer interrupts. Very easy to do in normal programming. But with CCS' RTOS I just have no idea about implementing this menu-based user interface. Can anybody give me an idea to start with? Thank you.
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Sun Jan 28, 2007 6:23 am     Reply with quote

Can you tell us more about your menu handling algorithm?

You could create a button handling task that calls the current menu function.
VanHauser



Joined: 03 Oct 2005
Posts: 88
Location: Ploiesti, Romania

View user's profile Send private message

PostPosted: Sun Jan 28, 2007 7:19 am     Reply with quote

Seems I forgot to log in when I started this thread Embarassed

Anyway, my old menu structure is something like:
Code:

void menuMain() {
  int8 item = 0;
  while(1) {
    /* Display current menu item */
    switch(getKey()) {
      case K_UP: item--; break;
      case K_DOWN: item++; break;
      case K_OK: switch(item) {
        case 0: menuOption0(); break;
        case 1: menuOption1(); break;
        case 2: subMenu2(); break;
        /* ...... */
      } break;
      case K_BACK: return;
    }
  }
}

void menuOption0() {
  /* User views or modifies parameters */
}

void menuOption1() {
  /* ... */
}

void subMenu2() {
  /* something like menuMain() */
}

The menuMain() function is called when the user presses the menu button in normal operation mode.

So, I want to do something similar while using RTOS. The obvious problem is that the RTOS locks when I keep waiting for a keypress, and I need processing tasks running permanently in the background.

I already have tested a button handling task, but I don't see how to efficiently implement the tree-like menu structure.
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Sun Jan 28, 2007 7:50 am     Reply with quote

You can setup a 10mS menuMain() task to call getKey() and rtos_yield() in case of K_BACK.

Also you can enable/disable this task by using the rtos calls, so you can enable it when the user presses the menu button and disable itself in case of
K_BACK.

You must remove the infinite loop.

I am very interested in your code. I have tried two or three ways to implement a complex (50 screens) menu tree.
VanHauser



Joined: 03 Oct 2005
Posts: 88
Location: Ploiesti, Romania

View user's profile Send private message

PostPosted: Mon Jan 29, 2007 8:48 am     Reply with quote

future wrote:
I have tried two or three ways to implement a complex (50 screens) menu tree.

And did you get any results? Please give me an idea about how you did. I feel like the menu task is going to be a huge function with many switches Shocked
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Mon Jan 29, 2007 2:42 pm     Reply with quote

I did a menu renderer routine that would accept a pointer to a linked list of 'widgets'. These widgets have their behavior dictated by their own routines.
Any text, label, editbox or button action on the lcd has to be added to the list and sent to the renderer routine.
The code is for C30 and relies on pointers heavily.

The other way was to build a BIG array with all your strings, where-to-go, variables to edit... And just 'navigate' this array throught the buttons.

The results were satisfatory but I did not like them.

Any new screen takes some effort to implement.

Now I think that the best way is to navigate the system throught functions.
Each function can do anything, be completely different from the others and have total control over the system.

I am just starting on user interfaces, but I am doing my homework.
VanHauser



Joined: 03 Oct 2005
Posts: 88
Location: Ploiesti, Romania

View user's profile Send private message

PostPosted: Tue Jan 30, 2007 2:45 am     Reply with quote

Well I am not using graphics, just a 2x16 LCD so it should be easier.

I thought about nested struct's containing the menu tree with all details, but I think it would be too much for my PIC. In my menu I have to enter just floats and integers. I am now working at two general tasks that ask the user for a float and a int respectively and another task that shows menu options.

Another idea that popped into my head is to use a second PIC just for the user interface, without RTOS.
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Fri Feb 16, 2007 3:36 pm     Reply with quote

I am doing a user interface at the moment and using the switch method with success.

The final code is big, but it is easy to modify if you structure it correctly.

Have your interface running on a separate task, another one for button debouncing. You will never lock inside a function.

A single switch(menu) and a switch(submenu) can do a lot.

Also don't use menu--; or submenu--;. Use menu = MENU_MAIN or something else.

I hope you understand.
VanHauser



Joined: 03 Oct 2005
Posts: 88
Location: Ploiesti, Romania

View user's profile Send private message

PostPosted: Fri Feb 16, 2007 5:42 pm     Reply with quote

I have been working on that interface for a while now and it works much better than expected. Multilayered menus and everything, with recursion. It's very easy to add a new option or a parameter value once you have figured out the interface engine. Menus and parameters are identified by their IDs in a switch.

I have 5 tasks for this interface: menu/selection display, float input, int16 input, int8 input, button debouncing. Menu task is stopped when a value input is demanded and the corresponding task is started, and after that finishes it resumes. Button debouncing runs permanently.

ROM and RAM consumption is HUGE indeed, but the results are good.
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Sat Feb 17, 2007 12:15 pm     Reply with quote

I've been thinking about a stack based menu system.

This would ease the management of deep menus and allow any sequence of screens.

There is no code yet, just a thought.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group