Browse Source

Pretty printed the Arduino code with astyle

Baozhu Zuo 6 years ago
parent
commit
98bf137375
3 changed files with 121 additions and 129 deletions
  1. 36 40
      Air_Quality_Sensor.cpp
  2. 31 31
      Air_Quality_Sensor.h
  3. 54 58
      examples/Grove_Air_Quality_Sensor/Grove_Air_Quality_Sensor.ino

+ 36 - 40
Air_Quality_Sensor.cpp

@@ -1,32 +1,32 @@
 /*
- * Air_Quality_Sensor.cpp
- * Source file for Grove - Air Quality Sensor.
- *
- * Copyright (c) 2019 seeed technology inc.
- * Author		: Lets Blu
- * Created Time	: Jan 2019
- * Modified Time:
- *
- * The MIT License (MIT)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
+    Air_Quality_Sensor.cpp
+    Source file for Grove - Air Quality Sensor.
+
+    Copyright (c) 2019 seeed technology inc.
+    Author		: Lets Blu
+    Created Time	: Jan 2019
+    Modified Time:
+
+    The MIT License (MIT)
+
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+*/
 #include "Air_Quality_Sensor.h"
 
 const int AirQualitySensor::FORCE_SIGNAL   = 0;
@@ -34,8 +34,8 @@ const int AirQualitySensor::HIGH_POLLUTION = 1;
 const int AirQualitySensor::LOW_POLLUTION  = 2;
 const int AirQualitySensor::FRESH_AIR      = 3;
 
-AirQualitySensor::AirQualitySensor(int pin) 
-: _pin(pin), _voltageSum(0), _volSumCount(0) {
+AirQualitySensor::AirQualitySensor(int pin)
+    : _pin(pin), _voltageSum(0), _volSumCount(0) {
     // do nothing
 }
 
@@ -50,8 +50,7 @@ bool AirQualitySensor::init(void) {
         _lastStdVolUpdated = millis();
 
         return true;
-    }
-    else {
+    } else {
         return false;
     }
 }
@@ -66,16 +65,13 @@ int AirQualitySensor::slope(void) {
     updateStandardVoltage();
     if (_currentVoltage - _lastVoltage > 400 || _currentVoltage > 700) {
         return AirQualitySensor::FORCE_SIGNAL;
-    }
-    else if ((_currentVoltage - _lastVoltage > 400 && _currentVoltage < 700)
-             || _currentVoltage - _standardVoltage > 150) {
+    } else if ((_currentVoltage - _lastVoltage > 400 && _currentVoltage < 700)
+               || _currentVoltage - _standardVoltage > 150) {
         return AirQualitySensor::HIGH_POLLUTION;
-    }
-    else if ((_currentVoltage - _lastVoltage > 200 && _currentVoltage < 700)
-             || _currentVoltage - _standardVoltage > 50) {
+    } else if ((_currentVoltage - _lastVoltage > 200 && _currentVoltage < 700)
+               || _currentVoltage - _standardVoltage > 50) {
         return AirQualitySensor::LOW_POLLUTION;
-    }
-    else {
+    } else {
         return AirQualitySensor::FRESH_AIR;
     }
 

+ 31 - 31
Air_Quality_Sensor.h

@@ -1,39 +1,39 @@
 /*
- * Air_Quality_Sensor.h
- * Header file for Grove - Air Quality Sensor.
- *
- * Copyright (c) 2019 seeed technology inc.
- * Author		: Lets Blu
- * Created Time	: Jan 2019
- * Modified Time:
- *
- * The MIT License (MIT)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
+    Air_Quality_Sensor.h
+    Header file for Grove - Air Quality Sensor.
+
+    Copyright (c) 2019 seeed technology inc.
+    Author		: Lets Blu
+    Created Time	: Jan 2019
+    Modified Time:
+
+    The MIT License (MIT)
+
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+*/
 #ifndef __AIR_QUALITY_SENSOR_H__
 #define __AIR_QUALITY_SENSOR_H__
 
 #include "Arduino.h"
 
 class AirQualitySensor {
-public:
+  public:
     AirQualitySensor(int pin);
 
     bool init(void);
@@ -45,13 +45,13 @@ public:
     static const int LOW_POLLUTION;
     static const int FRESH_AIR;
 
-protected:
+  protected:
     int  _pin;
 
     int  _lastVoltage;
     int  _currentVoltage;
     int  _standardVoltage;
-    
+
     long _voltageSum;
     int  _volSumCount;
     long _lastStdVolUpdated;

+ 54 - 58
examples/Grove_Air_Quality_Sensor/Grove_Air_Quality_Sensor.ino

@@ -1,69 +1,65 @@
 /*
- * Grove_Air_Quality_Sensor.ino
- * Demo for Grove - Air Quality Sensor.
- *
- * Copyright (c) 2019 seeed technology inc.
- * Author    : Lets Blu
- * Created Time : Jan 2019
- * Modified Time:
- *
- * The MIT License (MIT)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
- #include "Air_Quality_Sensor.h"
+    Grove_Air_Quality_Sensor.ino
+    Demo for Grove - Air Quality Sensor.
+
+    Copyright (c) 2019 seeed technology inc.
+    Author    : Lets Blu
+    Created Time : Jan 2019
+    Modified Time:
+
+    The MIT License (MIT)
+
+    Permission is hereby granted, free of charge, to any person obtaining a copy
+    of this software and associated documentation files (the "Software"), to deal
+    in the Software without restriction, including without limitation the rights
+    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+    copies of the Software, and to permit persons to whom the Software is
+    furnished to do so, subject to the following conditions:
+
+    The above copyright notice and this permission notice shall be included in
+    all copies or substantial portions of the Software.
+
+    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+    THE SOFTWARE.
+*/
+#include "Air_Quality_Sensor.h"
 
 AirQualitySensor sensor(A0);
 
 void setup(void) {
-  Serial.begin(9600);
-  while (!Serial);
+    Serial.begin(9600);
+    while (!Serial);
+
+    Serial.println("Waiting sensor to init...");
+    delay(20000);
 
-  Serial.println("Waiting sensor to init...");
-  delay(20000);
-  
-  if (sensor.init()) {
-    Serial.println("Sensor ready.");
-  }
-  else {
-    Serial.println("Sensor ERROR!");
-  }
+    if (sensor.init()) {
+        Serial.println("Sensor ready.");
+    } else {
+        Serial.println("Sensor ERROR!");
+    }
 }
 
 void loop(void) {
-  int quality = sensor.slope();
+    int quality = sensor.slope();
+
+    Serial.print("Sensor value: ");
+    Serial.println(sensor.getValue());
+
+    if (quality == AirQualitySensor::FORCE_SIGNAL) {
+        Serial.println("High pollution! Force signal active.");
+    } else if (quality == AirQualitySensor::HIGH_POLLUTION) {
+        Serial.println("High pollution!");
+    } else if (quality == AirQualitySensor::LOW_POLLUTION) {
+        Serial.println("Low pollution!");
+    } else if (quality == AirQualitySensor::FRESH_AIR) {
+        Serial.println("Fresh air.");
+    }
 
-  Serial.print("Sensor value: ");
-  Serial.println(sensor.getValue());
-  
-  if (quality == AirQualitySensor::FORCE_SIGNAL) {
-    Serial.println("High pollution! Force signal active.");
-  }
-  else if (quality == AirQualitySensor::HIGH_POLLUTION) {
-    Serial.println("High pollution!");
-  }
-  else if (quality == AirQualitySensor::LOW_POLLUTION) {
-    Serial.println("Low pollution!");
-  }
-  else if (quality == AirQualitySensor::FRESH_AIR) {
-    Serial.println("Fresh air.");
-  }
-  
-  delay(1000);
+    delay(1000);
 }