// *************************************************************************
//
// Setting up a lilOS handheld device. STEP 3 touch screen.
//
// Third step is to make sure we have the touch screen working. We need..
// • The touch screen that can run inder lilOS.
// • The SD card adapter. Typcially mounted on the screen. We need one.
//
// This is where we shift from the Muggle world into Magic land. Notice we
// No longer call draw() on the icon? Also, we have added idle() to loop().
//
// Instead of calling draw() manually, we've passed the icon off to the
// viewList to be managed behind the scenes by the viewMgr. This controls
// redrawing and touch events. With the help of the global event manager.
// Also, anything handed to the viewMgr will be recycled if it needs to
// be. We no longer need to concern ourselves with these objects.
//
// At this point you have pretty much full control over what's running on
// the screen. lilOS is not yet involved in anything. Many applications
// just go this far, use all the UI drawing stuff, and are completely
// happy. If this is all you need?
//
// You've arrived!
//
// If not? Let's move on to step 4. Setting up our OS and adding
// applications.
//
// As before, all these examples we'll be using our little handheld with an
// Adafruit PN 1947 for display and SD card slot.
//
// Documentation, it's all in the book :
// https://github.com/leftCoast/LC_libraryDocs/blob/main/LC_libraries.pdf
// *************************************************************************
#include <SD.h>
#include <adafruit_1947.h>
#include <LC_SPI.h>
#include <iconButton.h>
#define DISPLAY_CS 10 // These are the pins my hand held is using.
#define SD_CS 4 // You will need to replace these with the
#define BEEP_PIN 23 // Ones you are using on your device.
// A quick function to show an error in a uniform way. (optional)
void error(const char* inMsg) {
delay(2000); // If the first thing we do fails, we'll need this.
Serial.print("ERROR : "); // Label.
Serial.println(inMsg); // Message.
}
// A quick function to halt the processor because the hardware is not
// going to work. In a uniform way as well. (Also optional)
void halt(const char* function) {
delay(2000); // If the first thing we do fails, we'll need this.
Serial.print("HALTING PROCESS IN : "); // Tell 'em so they don't wonder.
Serial.print(function); // And tell 'em where we stopped.
Serial.println("()"); // Make it look right as well.
while(1); // Lock down!
}
// See if we can get everything running..
void setup() {
iconButton* aBtn;
Serial.begin(9600); // Serial port for debugging.
screen = new adafruit_1947(DISPLAY_CS,-1); // We create our screen object.
if (!screen) { // Didn't get a screen?
error("No screen."); // Tell the user.
halt(__func__); // Halt the program and tell the user where.
} //
if (!screen->begin()) { // Have a go at initialising the screen.
error("screen begin() failed."); // Failed? Tell the user.
halt(__func__); // Halt the program and tell the user where.
} //
screen->fillScreen(&black); // Have a go at making the sreen.. black.
if (!SD.begin(SD_CS)) { // Have a go at initializing the SD drive.
error("SD.begin() failed."); // Failed? Tell the user.
halt(__func__); // Halt the program and tell the user where.
} // //
ourEventMgr.begin(); // Kickstart our event manager.
//
aBtn = new iconButton(50,50,"/system/icons/standard/check32.bmp"); // Creat the button.
aBtn->setCallback(gotAClick); // Add a callback to the icon button.
viewList.addObj(aBtn); // Hand the icon button off to viewList.
Serial.println();
Serial.println("You should see the green check icon again.");
Serial.println("Click it to see if it works.");
Serial.println("If it's not showing, did you forget to call");
Serial.println("idle() in your loop() function?");
}
void gotAClick(void) {
Serial.print("GOT A CLICK!! ");
Serial.println("User interface stuff is up and running!");
}
// To actually get clicks and run screen updates, you
// MUST now call idle() in your loop() function.
void loop() { idle(); }