Skip to content

Creating a Custom Page

Colin edited this page Oct 30, 2013 · 6 revisions

Minimal code example

Create a class for the page, probably in pages.h (or pagePlane.h if it's a plane page...). We're going to use PageStatus for this example (which does exist in the code already, so pick a different name!!). You can copy and paste the following for the basic class structure, just change PageStatus to PageExample for example!

class PageStatus :
public Pages {
public:
	PageStatus() {};

protected:
  /// One off function, executes on page enter
  virtual uint8_t _enter();

  /// Force update the page
  virtual uint8_t _forceUpdate(uint8_t reason);

  /// One off function, executes on uav type change
  virtual uint8_t _redefine(){};

  /// refresh page - medium items (10Hz)
  virtual uint8_t _refresh_med();

  /// refresh page - slow items (0.5 Hz)
  virtual uint8_t _refresh_slow();

  /// Interact with the page
  virtual uint8_t _interact(uint8_t buttonid);
};

Then create the code for the page, probably in pages.ino (or pagePlane.ino if it's a plane page...) Again, you can copy and paste the following to get started, but rename PageStatus

uint8_t PageStatus::_enter() {
	// This function gets called when the user switches to this page
	GLCD.CursorTo(0, 0);
	GLCD.print("Display something on first loading the page");
	return 0;
}

uint8_t PageStatus::_refresh_med() {
	// This function gets called ten times a second
	GLCD.CursorTo(0, 1);
	GLCD.print("Display something on screen update");
	return 0;
}

uint8_t PageStatus::_refresh_slow() {
	// This function gets called every two seconds
	return 0;
}

// Note B_RIGHT and B_LEFT code always required for moving between pages:
uint8_t PageStatus::_interact(uint8_t buttonid) {
	switch (buttonid) {
	case B_OK:
		break;
	case B_RIGHT:
		Pages::move(1);
		break;
	case B_LEFT:
		Pages::move(-1);
		break;
	case B_CANCEL:
		Pages::move(0);
		break;
	}
	return 0;
}

uint8_t PageStatus::_forceUpdate(uint8_t reason) {
	return 0;
}

Now add a page enumeration to the page class (located in pages.h), so for example here we've added P_STATUS:

class Pages {
public:
	  // ----- Declare pages here ----- //
	  enum PAGEIDS {
	    P_MAIN = 0,
	    P_STATUS,
            P_SETTINGS,
	    P_COMMANDS,
	    P_PARAMETERS,
	    P_PARAMETERS_CTUN,
	    P_PARAMETERS_NTUN,
	    P_PARAMETERS_TECS,
	    P_ROVER_PARAMETERS,
	    P_COPTER_PARAMETERS,
	    P_TRACKER,
	    P_HARDWARE,
	    P_UAVTEST,
	    P_GLCD,
	    P_SD,
	    P_PID,
	    P_COUNT
	  };

Note that we must put this somewhere before P_COUNT.

Now we have to declare an instance of our newly defined page, so at the top of pages.ino add a line similar to this:

PageStatus statusPage;

In order for the page to be displayed on demand, we must add a pointer to the above instance "statusPage" using the enumeration "P_STATUS" we made. Scroll down in pages.ino to the following code and add the case for the new page, here it's P_STATUS

Pages*
Pages::_currPage(uint8_t pageid) {
	// ----- Assign each page declared above to the page ordering enumerated in pages.h ----- //
	switch (_pageids[pageid]) {
	case P_MAIN:
		return (&mainPage);
		break;
	case P_STATUS:
		return (&statusPage);
		break;

Finally, we must decide where the page is amongst all the other ones, and for what vehicles it should be displayed. Let's take the rover for example, within the uint8_t Pages::definePages() function (also pages.ino) add our statusPage (making sure to update the indices and pagecount variable):

else if (uav.type == MAV_TYPE_GROUND_ROVER) {
		_pageids[0] = P_MAIN;
		_pageids[1] = P_STATUS;
		_pageids[2] = P_COMMANDS;
		_pageids[3] = P_ROVER_PARAMETERS; // Rover parameters
		_pageids[4] = P_TRACKER;
		_pageids[5] = P_HARDWARE;
		_pageids[6] = P_UAVTEST;
		_pageids[7] = P_GLCD;
		_pageids[8] = P_SD;
		_pageids[9] = P_SETTINGS;
		_pagecount = 10;
	}
Clone this wiki locally