blah

Files at this revision

API Documentation at this revision

Comitter:
hisyamfs
Date:
Sun Dec 16 01:52:53 2018 +0000
Commit message:
test board v1

Changed in this revision

TPA81new.cpp Show annotated file Show diff for this revision Revisions of this file
TPA81new.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 90ed652031fd TPA81new.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TPA81new.cpp	Sun Dec 16 01:52:53 2018 +0000
@@ -0,0 +1,102 @@
+#include "TPA81new.h"
+
+TPA81::TPA81(PinName mysda, PinName myscl, char TPA_addr): _TPA(mysda,myscl) {
+    _delay = 51;
+    _addr = TPA_addr;
+}
+
+void TPA81::setAddress(char inAddr) {
+_addr = inAddr;
+}
+
+void TPA81::changeaddress(char oldAddr, char newAddr) {
+    _addr = oldAddr;
+    char data[2];
+    data[0] = 0;
+    data[1] = 0xA0;
+    _TPA.write(_addr,data,2,false);
+    wait_us(100);
+    data[1] = 0xAA;
+    _TPA.write(_addr,data,2,false);
+    wait_us(100);
+    data[1] = 0xA5;
+    _TPA.write(_addr,data,2,false);
+    wait_us(100);
+    data[1] = newAddr;
+    _TPA.write(_addr,data,2,false);
+    wait_us(100);
+}
+    
+int TPA81::getTempAt() {
+    _cmd[0] = 1;
+    _cmd[1] = 1;
+
+    _TPA.write(_addr, _cmd, 2);
+    _TPA.read(_addr, _cmd, 1);
+
+    return _cmd[0];
+}
+
+int TPA81::getTemp(short i) {
+    _cmd[0] = i;
+    _cmd[1] = i;
+
+    _TPA.write(_addr, _cmd, 2);
+    _TPA.read(_addr, _cmd, 1);
+
+    return _cmd[0];
+}
+
+unsigned int TPA81::Ambient(){
+        return getTemp(1);
+}
+
+void TPA81::Read()
+{
+    for (short i = 2; i < 10; i++)
+    {
+        Data[i-2]=getTemp(i)-getTemp(1);
+                if(Data[i-2]<0){
+                        Data[i-2] = 0;
+                }
+    }    
+        
+}
+
+unsigned char TPA81::IsAdaApi()
+{
+    int i;
+    
+    Read();
+    i=Data[0]+Data[1]+Data[2]+Data[3]+Data[4]+Data[5]+Data[6]+Data[7];
+    if (i>400)
+        return(1);
+    else
+        return(0);;
+}
+
+unsigned int TPA81::TingkatPanas()
+{
+    int i;
+    
+    Read();
+    i=Data[0]+Data[1]+Data[2]+Data[3]+Data[4]+Data[5]+Data[6]+Data[7];
+    return i;
+}
+
+/*unsigned int TPA81::TingkatPanas()
+{
+    int i;
+        unsigned int x;
+    
+    Read();
+    for(i=1;i<9;i++){
+                if(Data[i-1]<Data[i]){
+                        x = Data[i];
+                }
+                else{
+                        x = Data[i-1];
+                }
+        }
+    return x;
+}*/
\ No newline at end of file
diff -r 000000000000 -r 90ed652031fd TPA81new.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TPA81new.h	Sun Dec 16 01:52:53 2018 +0000
@@ -0,0 +1,31 @@
+#ifndef MY_TPA_H
+#define MY_TPA_H
+#define TPA_addr_x 0xD2
+#define TPA_addr_y 0xD0
+#include "mbed.h"
+
+class TPA81{
+public:
+    TPA81(PinName mysda, PinName myscl, char TPA_addr);
+    void setAddress(char inAddr);
+    int getTempAt();
+    int getTemp(short i);
+    void changeaddress(char x, char y);
+    // Untuk Lomba
+    int Data[8];
+    void Read();
+    unsigned char IsAdaApi();
+    unsigned int TingkatPanas();
+        unsigned int Ambient();
+        
+protected:
+    int _aTemp;
+    int _temp[8];
+    I2C _TPA;
+    char _addr;
+    char _cmd[2];
+    float _delay;
+};
+
+#endif
+