Library for Modtronix im4OLED board with 128x64 OLED and 4 buttons. For details, see product page http://modtronix.com/im4oled.html. Is a clone of Adafruit_GFX library, with some additional code added.

Fork of Adafruit_GFX by Neal Horman

Files at this revision

API Documentation at this revision

Comitter:
modtronix-com
Date:
Sat Aug 13 11:34:09 2016 +1000
Parent:
23:44309099c532
Child:
25:0a64129dc4e8
Commit message:
Added support for PT01NZ board

Changed in this revision

im4oled.cpp Show annotated file Show diff for this revision Revisions of this file
im4oled.h Show annotated file Show diff for this revision Revisions of this file
--- a/im4oled.cpp	Wed Oct 21 14:49:56 2015 +1100
+++ b/im4oled.cpp	Sat Aug 13 11:34:09 2016 +1000
@@ -26,6 +26,7 @@
 
 static MxTick  mxTick;
 
+#if (IM4OLED_VIA_PT01NZ==0)
 /*
  * Constructor
  */
@@ -46,16 +47,69 @@
     // Read pins every 10ms
     _ticker.attach(this, &Im4OLED::_sample, 0.01);
 }
+#else
+/*
+ * Constructor
+ */
+Im4OLED::Im4OLED(PinName pinOKStar, PinName pinUpDown)
+    : btnOKStar(pinOKStar, PullUp), btnUpDown(pinUpDown, PullUp)
+{
+    delayTillRepeat = 80;   //Repeats start after 800ms
+    repeatPeriod = 20;      //200mS between button repeats
+    repeatBtnId = 0xff;     //No button currently pressed donw
+    repeatCount = 0;
+    tmrRepeat = 0;
+
+    // reset all the flags and counters
+    memset(&arrButtons, 0, sizeof(arrButtons));
+    memset(&arrBtnFallingCnt, 0, sizeof(arrBtnFallingCnt));
+    memset(&arrBtnFlags, 0, sizeof(arrBtnFlags));
+
+    // Read pins every 10ms
+    _ticker.attach(this, &Im4OLED::_sample, 0.01);
+}
+#endif
+
 
 void Im4OLED::_sample() {
     bool anyBtnPressed = false;    //Check if any button pressed
     uint16_t i;
     uint8_t val[IM4OLED_BUTTONS];
 
+#if (IM4OLED_VIA_PT01NZ==0)
     val[0] = btnOK.read();
     val[1] = btnStar.read();
     val[2] = btnUp.read();
     val[3] = btnDown.read();
+#else
+    //All buttons not pressed
+    val[0] = val[1] = val[2] = val[3] = 1;
+
+    //Test if OK or Down is pressed. To test this, enable pullups(default) on both
+    //pins, and test if pins are pulled low.
+    if(btnOKStar.read() == 0) {
+        val[0] = 0; //Star pressed
+    }
+    btnOKStar.mode(PullDown);
+    if(btnUpDown.read() == 0) {
+        val[3] = 0; //Down pressed
+    }
+    btnUpDown.mode(PullDown);
+
+    //Test if Star or Up is pressed. To test this, enable pulldown on both
+    //pins, and test if pins are pulled high.
+    wait_us(5);     //Delay time for pulldown to settle
+    if(btnOKStar.read() == 1) {
+        val[1] = 0; //OK pressed
+    }
+    if(btnUpDown.read() == 1) {
+        val[2] = 0; //Up pressed
+    }
+
+    //Enable default state - pullups on both pins
+    btnOKStar.mode(PullUp);
+    btnUpDown.mode(PullUp);
+#endif
 
     for(i=0; i<IM4OLED_BUTTONS; i++) {
         // Current button PRESSED /////////////////////////////////////////////
--- a/im4oled.h	Wed Oct 21 14:49:56 2015 +1100
+++ b/im4oled.h	Sat Aug 13 11:34:09 2016 +1000
@@ -19,12 +19,17 @@
  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  */
 #include "mbed.h"
+#include "im4oled_default_config.h"
 
 class Im4OLED {
 public:
     /** Constructor
      */
+#if (IM4OLED_VIA_PT01NZ==0)
     Im4OLED(PinName pinOK, PinName pinStar, PinName pinUp, PinName pinDown);
+#else
+    Im4OLED(PinName pinOKStar, PinName pinUpDown);
+#endif
 
     /**
      * Returns true if any button was pressed, and is available via a getXxxBtnFalling() function
@@ -130,10 +135,15 @@
     //Objects
     Ticker      _ticker;
 
+#if (IM4OLED_VIA_PT01NZ==1)
+    DigitalIn   btnOKStar;
+    DigitalIn   btnUpDown;
+#else
     DigitalIn   btnOK;
     DigitalIn   btnStar;
     DigitalIn   btnUp;
     DigitalIn   btnDown;
+#endif
 
 private :
     struct ButtonFlags {