#include <adafruit_1947.h> // Screen lib.
#include <eventMgr.h> // Interaction manager.
#include <scrollingList.h> // The scrolling list class we're showing off today.
#include <serialStr.h> // A amanager for the serial port.
#include "listParts.h"
#define DSP_CS 10 // Display chip select
colorObj backColor; // We setup a colorObj for the background color of the display.
dragList* ourList; // Our scrolling list NOTE : See listParts.h tab.
serialStr ourSerialMgr; // Easy way to get c strings from the user.
// The way setup() works here is mostly for hardware setup. If that all works?
// Then we go on to setup the srceen object and controls.
void setup() {
Serial.begin(115200); // Fire up Serial port.
Serial.print("Scrolling list. " ); // Give the user a hint as to what to do.
Serial.println("Select an item and type in new text."); //
ourSerialMgr.setCallback(gotString); // Set the callback for the Serial manager.
screen = (displayObj*) new adafruit_1947(DSP_CS,-1); // Create our screen object.
if (screen) { // We got one? Cool!
if (screen->begin()) { // Can we successfully call begin on the screen?
screen->setRotation(PORTRAIT); // Ok, set portrait. Good for handhelds.
ourEventMgr.begin(); // We are looking for touch sceen action! Fire up the even manager.
setupScreen(); // Populate the screen.
return; // Everything fired up successfuly. Lets go!
} //
} //
Serial.println("NO SCREEN!"); // Send an error out the serial port.
while(true)delay(10); // Lock processor here forever.
}
// Extension to setup() that puts all the scren bits and things together.
void setupScreen(void) {
listItem* itemPtr;
backColor.setColor(&blue); // Setup background display color.
backColor.blend(&white,70); // Lets lighten it, mixin some white.
screen->fillScreen(&backColor); // A command to "screen" happens (NOW). Objects update later.
// Create the goodies.
ourList = new dragList(); // Create a vertical scrolling list.
if (ourList) { // If we got one..
viewList.addObj(ourList); // Add it to the viewList to manage.
itemPtr = new listItem(ourList,"First item");
ourList->addObj(itemPtr); // And the label (It's also a pointer) to the view list to be managed.
itemPtr = new listItem(ourList,"Another item");
ourList->addObj(itemPtr);
itemPtr = new listItem(ourList,"Do it all day.");
ourList->addObj(itemPtr);
itemPtr = new listItem(ourList,"Look a rat!");
ourList->addObj(itemPtr);
itemPtr = new listItem(ourList,"There's glory for 'ya,");
ourList->addObj(itemPtr);
itemPtr = new listItem(ourList,"A couple more.");
ourList->addObj(itemPtr);
itemPtr = new listItem(ourList,"Last item");
ourList->addObj(itemPtr);
ourList->setPositions();
} else { // Didn't get a dragList?
Serial.println("No dragList!"); // Tell Miss user.
while(true)delay(10); // Lock processor here forever.
} //
}
// Callback for ourSerialMgr.
void gotString(char* inStr) { ourList->changeStr(inStr); }
// In loop, make a call to idle.
void loop() { idle(); } // Runs all the mnagic.