correct errors in database SQL
authortobias <tm@tm3d.de>
Wed, 1 Mar 2017 06:28:29 +0000 (07:28 +0100)
committertobias <tm@tm3d.de>
Wed, 1 Mar 2017 06:28:29 +0000 (07:28 +0100)
src/main.cpp
src/mySensorDB.cpp

index 1987435..b629617 100755 (executable)
@@ -210,8 +210,11 @@ void continuous(std::vector<owDevice*> *devices,int intervall,int headline,int s
                                        for (owDevice* dev :*devices) {
                                                if (dev->configstate!=OWDCS_NONE) {
                                                        for (size_t i=0;i<4;i++) {
-                                                               if (dev->config->getPropertyID(i)!=0)
-                                                                       printf("\033[3;34m[%s]  \033[0m\t",dev->config->getUnit(i).c_str());
+                                                               if (dev->config->getPropertyID(i)!=0) {
+                                                                       size_t l=utf8_length(dev->config->getUnit(i));
+                                                                       std::string ls="           ";
+                                                                       printf("\033[3;34m[%s]%s\033[0m\t",dev->config->getUnit(i).c_str(),ls.substr(0,5-l).c_str());
+                                                               }
                                                        }
                                                }
                                        }
@@ -242,7 +245,11 @@ void continuous(std::vector<owDevice*> *devices,int intervall,int headline,int s
                                if (dev->configstate!=OWDCS_NONE) {
                                        for (size_t i=0;i<4;i++) {                                      
                                                if (dev->config->getPropertyID(i)!=0) {
-                                                       if (dev->values[i]<10) 
+                                                       if (dev->values[i]<=-10) 
+                                                               printf("%0.2f \t",dev->values[i]);
+                                                       else if (dev->values[i]<0) 
+                                                               printf("%0.3f \t",dev->values[i]);
+                                                       else if (dev->values[i]<10) 
                                                                printf("%0.4f \t",dev->values[i]);
                                                        else if (dev->values[i]<100)    
                                                                printf("%0.3f \t",dev->values[i]);
@@ -290,7 +297,7 @@ void device_menu(owDevice* d) {
        printf("\n");
        d->convertAll();
        for (size_t i=0;i<d->values.size();i++) {
-               printf("\033[1;33m%0.4f %s\033[0m   ",d->values[i],d->config->getUnit(i).c_str());
+               printf("\033[1;33m%0.4f %s\033[0m  ",d->values[i],d->config->getUnit(i).c_str());
        }
        printf("\n");
        for(int i=0;i<70;i++) printf(HL);printf("\n");
@@ -491,6 +498,18 @@ int main(int argc, char *argv[]) {
                printf("%i Devices found\n",(int)owi->devices.size());  
                                
        } else 
+       if ((s=getArg("v"))!="") {
+               printf("Reset VOC\n");
+               int sel=selectDevice();
+               if (sel==0) exit(0);
+               owDevice* dev=owi->devices[sel-1];
+               std::vector<uint8_t> cl;
+               cl.push_back(0x4E);
+               cl.push_back(0x1F);
+               cl.push_back(0x1F);
+               cl.push_back(0x1F);
+               dev->Communicate(&cl,4,0);
+       } else 
        
        if ((s=getArg("n"))!="") {
                printf("Change id of selected Device\n");
index 76631e3..891282e 100755 (executable)
@@ -193,7 +193,7 @@ int mySensorDB::insertValues(owDevice *dev) {
                sprintf(hs,"%016llX",(unsigned long long)dev->getNum().num);
                std::string query;
                query="INSERT INTO `"+mypre+"OW"+std::string(hs)+"` (";
-               for (size_t i=0;i<4;i++) if (dev->config->getPropertyID(i)!=0) query+=std::string(hs)+"_"+std::to_string(i+1)+", ";
+               for (size_t i=0;i<4;i++) if (dev->config->getPropertyID(i)!=0) query+="`"+std::string(hs)+"_"+std::to_string(i+1)+"`, ";
                query.pop_back();query.pop_back();
                query+=") VALUES (";
                for (size_t i=0;i<4;i++) if (dev->config->getPropertyID(i)!=0) query+=std::to_string(dev->values[i])+", ";