standalone sx1276 demo program

Dependencies:   SX1276Lib mbed

Fork of SX1276_GPS by CaryCoders

Revision:
9:1501fb01ded6
Parent:
7:d087e901b74b
Child:
10:3fcab08717fc
diff -r d182b98b975f -r 1501fb01ded6 main.cpp
--- a/main.cpp	Sun Aug 03 15:17:16 2014 +0000
+++ b/main.cpp	Mon Aug 04 11:38:13 2014 +0000
@@ -1,5 +1,4 @@
 #include "mbed.h"
-
 #include "Adafruit_RGBLCDShield.h"
 //#include "MCP23017.h"
 
@@ -7,29 +6,61 @@
 
 MCP23017 mcp23017 = MCP23017(I2C_SDA, I2C_SCL, 0x40);
 Adafruit_RGBLCDShield lcd(mcp23017);
+
+enum EExtraChars
+{
+    eUp = 0,
+    eDown,
+    eDegree
+};
+
+void CreateChars()
+{
+    uint8_t k_aUp[] = { 0x4,0xe,0x1f,0x15,0x4,0x4,0x4,0x4 };
+    uint8_t k_aDown[] = { 0x4,0x4,0x4,0x4,0x15,0x1f,0xe,0x4 };
+    uint8_t k_aDegree[] = { 0xc,0x12,0x12,0xc,0x0,0x0,0x0,0x0 };
+
+    lcd.createChar(eUp,k_aUp);
+    lcd.createChar(eDown,k_aDown);
+    lcd.createChar(eDegree,k_aDegree);    
+}
+
+void Initialise()
+{
+    lcd.begin(16,2);
+    CreateChars();
+
+    lcd.setCursor(0,0);
+    lcd._putc(eUp);
+
+    lcd.setCursor(0,1);
+    lcd._putc(eDown);    
+}
     
 // Allows to set the backlight, if the LCD backpack is used
 void SetBacklight(unsigned char status)
 {
-    pc.printf("Backlight: %i\n\r", status);
+    pc.printf("Backlight: %i\r\n", status);
     
     mcp23017.digitalWrite(8, (~(status >> 2) & 0x1));
     mcp23017.digitalWrite(7, (~(status >> 1) & 0x1));
     mcp23017.digitalWrite(6, (~status & 0x1));
 }
 
-void loop()
+uint8_t CheckKeys()
 {
-    static int count = 0;
+    static uint8_t lastButtons = lcd.readButtons();
     
     uint8_t buttons = lcd.readButtons();
 
     if (buttons)
     {
-        count = 0;
-        
-        lcd.clear();
-        lcd.setCursor(0,0);
+        if (buttons != lastButtons)
+        {
+            lastButtons = buttons;
+        }
+            
+        lcd.setCursor(2,1);
         
         if (buttons & BUTTON_UP)
         {
@@ -65,24 +96,78 @@
             
             lcd.printf("SELECT ");            
         }
+        
+        lcd.printf("              ");
     }
-    else
-    {
-        lcd.setCursor(0,1);
-        lcd.printf("Waiting... %i",count++);
-    }
+    
+    return buttons;
+}
+
+void ShowTemp(int in_nTemp)
+{
+    lcd.setCursor(2,0);
+    lcd.printf("Room: %i%cC     ",in_nTemp,eDegree);    
+}
+
+void SetTime
+(
+    uint8_t     in_nHour,
+    uint8_t     in_nMin,
+    uint8_t     in_nDay,
+    uint8_t     in_nMonth,
+    uint16_t    in_nYear
+)
+{
+    tm sCurrentTime = { 0 };
+    sCurrentTime.tm_year = in_nYear - 1900;
+    sCurrentTime.tm_mon = in_nMonth - 1;
+    sCurrentTime.tm_mday = in_nDay;
+    
+    sCurrentTime.tm_hour = in_nHour;
+    sCurrentTime.tm_min = in_nMin;
+    
+    time_t nCurrentTime = mktime(&sCurrentTime);
+    set_time(nCurrentTime);    
+}
+
+void ShowTime()
+{
+    lcd.setCursor(2,1);
+
+    time_t rawtime = time(0);
+    tm * timeinfo = localtime(&rawtime);        
+    lcd.printf ("%02i:%02i:%02i      ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);    
 }
 
 int main()
-{    
-    pc.printf("\n\rInitialise LCD\n\r");    
-    lcd.begin(16,2);
+{        
+    pc.printf("\r\nInitialise LCD\r\n");    
+    
+    Initialise();
 
-    lcd.printf("AdaFruit RGB LCD Shield");            
-    pc.printf("\n\rEntering key tracking loop\n\r");
+    SetTime(11,48,4,8,2014);
+    
+    int nTemp = 28;
+    ShowTemp(nTemp);
+
+    time_t nLast = 0;
     while (true)
     {
-        loop();
+        if (time(0) - nLast > 3)
+        {
+            ShowTime();
+        }
+
+        uint8_t nKeys = CheckKeys();        
+        if (nKeys)
+        {
+            if (nKeys & BUTTON_UP) nTemp++;
+            if (nKeys & BUTTON_DOWN) nTemp--;
+                        
+            ShowTemp(nTemp);            
+            nLast = time(0);
+        }
+            
         wait(0.2);
     }    
 }