Dave Clarke / Mbed OS Hexi_talking_one_main

Fork of Hexi_Click_Relay-v3_Example by Hexiwear

Revision:
0:ac93d26bbdb5
Child:
1:070fc531e5cb
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Sep 20 21:51:57 2016 +0000
@@ -0,0 +1,153 @@
+/*
+* Bitmaps need to be formatted as 16bppRgb565, flipped vertically
+* and a 6 byte header needs to be appended at the start of the array.
+* Use the following tool to create arrays for images. 
+* https://github.com/MikroElektronika/HEXIWEAR/tree/master/SW/ResourceCollectionTool
+* It takes an image and outputs the array. It handles the flipping and the 6 byte header.  
+* Image needs to be converted outside the tool to fit the screen 
+* (Max Dimensions:96px by 96px).
+*/
+
+#include "mbed.h"
+#include "Hexi_OLED_SSD1351.h"
+#include "images.h"
+#include "Hexi_KW40Z.h"
+
+#define LED_ON      0
+#define LED_OFF     1
+   
+void StartHaptic(void);
+void StopHaptic(void const *n);
+
+/* Instantiate the Click Relay pinout */
+DigitalOut relay1(PTA10);
+DigitalOut relay2(PTC4);
+
+/* Instantiate the RGB LED and Haptic motor pinout */
+DigitalOut redLed(LED1);
+DigitalOut greenLed(LED2);
+DigitalOut blueLed(LED3);
+DigitalOut haptic(PTB9);
+
+/* Instantiate the Hexi KW40Z Driver (UART TX, UART RX) */ 
+KW40Z kw40z_device(PTE24, PTE25);
+
+/* Instantiate the SSD1351 OLED Driver */
+SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // (MOSI,SCLK,POWER,CS,RST,DC)
+
+/* Define timer for haptic feedback */
+RtosTimer hapticTimer(StopHaptic, osTimerOnce);
+
+
+
+int flag=0;
+
+void ButtonLeft(void)
+{
+    StartHaptic();
+    
+    redLed      = LED_ON;
+    greenLed    = LED_ON;
+    blueLed     = LED_OFF;
+    
+    relay2 = !relay2;
+    flag = 1;
+}
+
+void ButtonRight(void)
+{
+    StartHaptic();
+    
+    redLed      = LED_ON;
+    greenLed    = LED_OFF;
+    blueLed     = LED_OFF;    
+    
+    relay1 = !relay1;
+    flag = 1;
+}
+
+void StartHaptic(void)
+{
+    hapticTimer.start(75);
+    haptic = 1;
+}
+
+void StopHaptic(void const *n) {
+    haptic = 0;
+    hapticTimer.stop();
+    redLed      = LED_OFF;
+    greenLed    = LED_OFF;
+    blueLed     = LED_OFF;
+}
+
+int main() {
+    
+    redLed      = LED_OFF;
+    greenLed    = LED_OFF;
+    blueLed     = LED_OFF;
+    
+    /* Pointer for the image to be displayed  */  
+    const uint8_t *image1;
+    const uint8_t *image2;
+    const uint8_t *image3;
+    const uint8_t *image4;
+
+    /* Setting pointer location of the 96 by 96 pixel bitmap */
+    image1  = Relay_FF;
+    image2  = Relay_NN;
+    image3  = Relay_FN;
+    image4  = Relay_NF;
+    
+    /* Turn on the backlight of the OLED Display */
+    oled.DimScreenON();
+    
+    /* Register callbacks to application functions */
+    kw40z_device.attach_buttonLeft(&ButtonLeft);
+    kw40z_device.attach_buttonRight(&ButtonRight);
+    
+    /* Fill the screen with white to overwrite previous image */
+    oled.FillScreen(COLOR_BLACK);
+        
+    /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */
+    oled.DrawImage(image1,0,0);
+
+    while (true) {
+        
+        if (flag == 1) {
+        if (relay2==0)  {
+        if (relay1==0) {
+            /* Fill the screen with white to overwrite previous image */
+            oled.FillScreen(COLOR_BLACK);
+        
+            /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */
+            oled.DrawImage(image1,0,0);
+            }
+        else {
+            /* Fill the screen with white to overwrite previous image */
+            oled.FillScreen(COLOR_BLACK);
+        
+            /* Draw 96px by 96px NXP Banner at the bottom by setting x =0,y=64(96-32)*/
+            oled.DrawImage(image3,0,0);
+            }
+            }
+    else {
+        if (relay1==0) { 
+            /* Fill the screen with white to overwrite previous image */
+            oled.FillScreen(COLOR_BLACK);
+        
+            /* Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0 */
+            oled.DrawImage(image4,0,0);
+       }
+        else {  
+            /* Fill the screen with white to overwrite previous image */
+            oled.FillScreen(COLOR_BLACK);
+        
+            /* Draw 96px by 96px NXP Banner at the bottom by setting x =0,y=64(96-32)*/
+            oled.DrawImage(image2,0,0);
+            }
+            }
+         flag = 0;
+            }
+            Thread::wait(50);
+    }
+}
\ No newline at end of file