20171006

Dependencies:   INA219 ISL29125 TSL2561 libmDot-mbed5 LoRa_Miun_20171002 SmartApp_Miun

Fork of Smart_Miun by BIN WANG

Files at this revision

API Documentation at this revision

Comitter:
biwa1400
Date:
Fri Oct 06 08:06:05 2017 +0000
Parent:
23:c4dbb237bb76
Commit message:
Light1006;

Changed in this revision

INA219.lib Show annotated file Show diff for this revision Revisions of this file
ISL29125.lib Show annotated file Show diff for this revision Revisions of this file
TSL2561.lib Show annotated file Show diff for this revision Revisions of this file
project/inc/example.h Show diff for this revision Revisions of this file
project/inc/light.h Show annotated file Show diff for this revision Revisions of this file
project/src/example.cpp Show diff for this revision Revisions of this file
project/src/light.cpp Show annotated file Show diff for this revision Revisions of this file
project/src/main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/INA219.lib	Fri Oct 06 08:06:05 2017 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/teams/components/code/INA219/#eee9c8ba72ff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ISL29125.lib	Fri Oct 06 08:06:05 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/frankvnk/code/ISL29125/#ae36914adb6d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSL2561.lib	Fri Oct 06 08:06:05 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/anhnt2407/code/TSL2561/#ab906ac6e90b
--- a/project/inc/example.h	Mon Oct 02 16:13:51 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-#ifndef __EXAMPLE_H__
-#define __EXAMPLE_H__
-
-#include "AppUnit.h"
-#include "SmartAppSingle.h"
-#include "mbed.h"
-#include "mDot.h"
-#include "MTSLog.h"
-#include <string>
-
-class Example: public MIUN::SmartAppSingle
-{
-     
-public:
-    //@override
-    virtual void execute();
-};
-
-
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project/inc/light.h	Fri Oct 06 08:06:05 2017 +0000
@@ -0,0 +1,32 @@
+#ifndef __EXAMPLE_H__
+#define __EXAMPLE_H__
+
+#include "AppUnit.h"
+#include "SmartAppSingle.h"
+#include "mbed.h"
+#include "mDot.h"
+#include "MTSLog.h"
+#include "ISL29125.h"
+#include "TSL2561.h"
+#include "INA219.hpp"
+#include <string>
+
+class Light: public MIUN::SmartAppSingle
+{
+private:
+    DigitalOut rgbPower;
+    DigitalOut luminPower;
+public:
+    Light::Light();
+    //@override
+    virtual void execute();
+    void         test();
+    void         readRGB(uint16_t rgb[]);
+    uint32_t     readLumin();
+    uint16_t     readSolarCurrent();
+    void         send(uint16_t r,uint16_t g,uint16_t b, uint32_t lumin, uint16_t solarCurrent);
+
+};
+
+
+#endif
\ No newline at end of file
--- a/project/src/example.cpp	Mon Oct 02 16:13:51 2017 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-#include "SmartAppSingle.h"
-#include "example.h"
-#include "MIUN.LoRa.h"
-#include "MTSLog.h"
-
-void Example::execute()
-{
-    sendReceive("Hello World",1,NULL);
-}
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/project/src/light.cpp	Fri Oct 06 08:06:05 2017 +0000
@@ -0,0 +1,88 @@
+#include "SmartAppSingle.h"
+#include "light.h"
+#include "MIUN.LoRa.h"
+#include "MTSLog.h"
+#include "mDot.h"
+#include <sstream>
+
+Light::Light():rgbPower(PB_0),luminPower(PA_5)
+{
+}
+
+void Light::execute()
+{
+    uint16_t rgb[3];
+    readRGB(rgb);
+    logInfo("R:%d,G:%d,B:%d",rgb[0],rgb[1],rgb[2]);
+
+    uint32_t lumin =  readLumin();
+    logInfo("Lumin:%d",lumin);
+        
+    uint16_t solarCurrent = readSolarCurrent();
+    logInfo("solar current: %d",solarCurrent);
+    
+    send(rgb[0],rgb[1],rgb[2],lumin, solarCurrent);
+}
+
+void Light::test()
+{
+
+}
+
+void Light::readRGB(uint16_t rgb[])
+{
+    luminPower = 1;
+    rgbPower = 1; 
+    
+    wait(1);
+    ISL29125 RGB_sensor(I2C_SDA,I2C_SCL);
+    wait(1);
+    
+    RGB_sensor.RGBmode(ISL29125_RGB);
+    RGB_sensor.Range(ISL29125_10KLX);
+    RGB_sensor.Resolution(ISL29125_16BIT);
+    while(RGB_sensor.Read(ISL29125_RGB, rgb)!=true){}
+    
+    luminPower = 0; 
+    rgbPower = 0;
+}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
+
+uint32_t Light::readLumin()
+{
+
+    luminPower = 1;
+    
+    wait(1);
+    TSL2561 tsl2561(I2C_SDA,I2C_SCL);
+    tsl2561.setGain(TSL2561_GAIN_16X);      
+    tsl2561.setTiming(TSL2561_INTEGRATIONTIME_101MS);  
+    
+    uint32_t value = tsl2561.getLuminosity (TSL2561_FULLSPECTRUM);
+    
+    luminPower = 0;
+    
+    return value;
+}                                                                              
+
+
+uint16_t Light::readSolarCurrent()
+{
+    luminPower = 1;
+    
+    wait(1);
+    INA219 ina219 (I2C_SDA,I2C_SCL);
+    uint16_t result = ina219.read_current_raw();
+    
+    luminPower = 0;
+    
+    return result;
+}
+
+void Light::send(uint16_t r,uint16_t g,uint16_t b, uint32_t lumin, uint16_t solarCurrent)
+{
+    stringstream sendStream;
+    sendStream<<r<<","<<g<<","<<b<<","<<lumin<<","<<solarCurrent;
+    string sendString =sendStream.str();
+    logInfo("Send String: %s",sendString.c_str());
+    sendReceive(sendString,1,NULL);
+}
\ No newline at end of file
--- a/project/src/main.cpp	Mon Oct 02 16:13:51 2017 +0000
+++ b/project/src/main.cpp	Fri Oct 06 08:06:05 2017 +0000
@@ -1,10 +1,11 @@
-#include "example.h"
+#include "light.h"
 #include "SmartApp.h"
 
 int main()
 {
-    Example example;
-    example.setSleepTime(10);
-    example.startRunning();
+    Light light;
+    light.setSleepTime(20);
+    light.startRunning();
+   // light.test();
     return 0;
 }
\ No newline at end of file