Rune L / Multichannel_Gas_Sensor
Committer:
runesla
Date:
Wed Feb 03 18:57:23 2021 +0100
Revision:
2:c836ed5bafce
Parent:
1:f0e19383efb9
Child:
6:52d9088d70cd
removed templating, reorganized constructors and GMXXXRead32

Who changed what in which revision?

UserRevisionLine numberNew contents of line
runesla 0:2fec9850cc9b 1 /*
runesla 0:2fec9850cc9b 2 Multichannel_Gas_GMXXX.h
runesla 0:2fec9850cc9b 3 Description: A drive for Seeed Grove Multichannel gas sensor V2.0.
runesla 0:2fec9850cc9b 4 2019 Copyright (c) Seeed Technology Inc. All right reserved.
runesla 0:2fec9850cc9b 5 Author: Hongtai Liu(lht856@foxmail.com)
runesla 0:2fec9850cc9b 6 2019-6-18
runesla 0:2fec9850cc9b 7
runesla 0:2fec9850cc9b 8 The MIT License (MIT)
runesla 0:2fec9850cc9b 9 Permission is hereby granted, free of charge, to any person obtaining a copy
runesla 0:2fec9850cc9b 10 of this software and associated documentation files (the "Software"), to deal
runesla 0:2fec9850cc9b 11 in the Software without restriction, including without limitation the rights
runesla 0:2fec9850cc9b 12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
runesla 0:2fec9850cc9b 13 copies of the Software, and to permit persons to whom the Software is
runesla 0:2fec9850cc9b 14 furnished to do so, subject to the following conditions:
runesla 0:2fec9850cc9b 15 The above copyright notice and this permission notice shall be included in
runesla 0:2fec9850cc9b 16 all copies or substantial portions of the Software.
runesla 0:2fec9850cc9b 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
runesla 0:2fec9850cc9b 18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
runesla 0:2fec9850cc9b 19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
runesla 0:2fec9850cc9b 20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
runesla 0:2fec9850cc9b 21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
runesla 0:2fec9850cc9b 22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
runesla 0:2fec9850cc9b 23 THE SOFTWARE.1 USA
runesla 0:2fec9850cc9b 24 */
runesla 0:2fec9850cc9b 25 #ifndef __GAS_GMXXX__
runesla 0:2fec9850cc9b 26 #define __GAS_GMXXX__
runesla 0:2fec9850cc9b 27
runesla 1:f0e19383efb9 28 #include <inttypes.h>
runesla 2:c836ed5bafce 29 #include "mbed.h"
runesla 0:2fec9850cc9b 30
runesla 0:2fec9850cc9b 31 #define GM_RESOLUTION 1023
runesla 0:2fec9850cc9b 32
runesla 0:2fec9850cc9b 33 //command
runesla 0:2fec9850cc9b 34 #define GM_102B 0x01
runesla 0:2fec9850cc9b 35 #define GM_302B 0x03
runesla 0:2fec9850cc9b 36 //#define GM_402B 0x04
runesla 0:2fec9850cc9b 37 #define GM_502B 0x05
runesla 0:2fec9850cc9b 38 #define GM_702B 0x07
runesla 0:2fec9850cc9b 39 //#define GM_802B 0x08
runesla 0:2fec9850cc9b 40 #define CHANGE_I2C_ADDR 0x55
runesla 0:2fec9850cc9b 41 #define WARMING_UP 0xFE
runesla 0:2fec9850cc9b 42 #define WARMING_DOWN 0xFF
runesla 0:2fec9850cc9b 43
runesla 0:2fec9850cc9b 44 class GAS_GMXXX {
runesla 0:2fec9850cc9b 45 public:
runesla 2:c836ed5bafce 46 GAS_GMXXX(PinName sda, PinName scl, uint8_t addr = 0x08);
runesla 2:c836ed5bafce 47 //void begin();
runesla 2:c836ed5bafce 48 void init();
runesla 0:2fec9850cc9b 49 void setAddress(uint8_t address = 0x08);
runesla 0:2fec9850cc9b 50 void preheated();
runesla 0:2fec9850cc9b 51 void unPreheated();
runesla 0:2fec9850cc9b 52 void changeGMXXXAddr(uint8_t address = 0x08);
runesla 0:2fec9850cc9b 53 uint32_t measure_NO2(){
runesla 0:2fec9850cc9b 54 return getGM102B();
runesla 0:2fec9850cc9b 55 };
runesla 0:2fec9850cc9b 56 uint32_t getGM102B();
runesla 0:2fec9850cc9b 57 uint32_t measure_C2H5OH(){
runesla 0:2fec9850cc9b 58 return getGM302B();
runesla 0:2fec9850cc9b 59 };
runesla 0:2fec9850cc9b 60 uint32_t getGM302B();
runesla 0:2fec9850cc9b 61 #ifdef GM_402B
runesla 0:2fec9850cc9b 62 uint32_t getGM402B();
runesla 0:2fec9850cc9b 63 #endif
runesla 0:2fec9850cc9b 64 uint32_t measure_VOC(){
runesla 0:2fec9850cc9b 65 return getGM502B();
runesla 0:2fec9850cc9b 66 };
runesla 0:2fec9850cc9b 67 uint32_t getGM502B();
runesla 0:2fec9850cc9b 68 uint32_t measure_CO(){
runesla 0:2fec9850cc9b 69 return getGM702B();
runesla 0:2fec9850cc9b 70 };
runesla 0:2fec9850cc9b 71 uint32_t getGM702B();
runesla 0:2fec9850cc9b 72 #ifdef GM_802B
runesla 0:2fec9850cc9b 73 uint32_t getGM802B();
runesla 0:2fec9850cc9b 74 #endif
runesla 0:2fec9850cc9b 75 inline float calcVol(uint32_t adc) {
runesla 0:2fec9850cc9b 76 return (adc * 3.3) / GM_RESOLUTION;
runesla 0:2fec9850cc9b 77 };
runesla 0:2fec9850cc9b 78 private:
runesla 2:c836ed5bafce 79 I2C* _i2c_p;
runesla 2:c836ed5bafce 80 I2C& _i2c;
runesla 0:2fec9850cc9b 81 bool isPreheated;
runesla 0:2fec9850cc9b 82 uint8_t GMXXX_ADDRESS;
runesla 0:2fec9850cc9b 83 void GMXXXWriteByte(uint8_t cmd);
runesla 0:2fec9850cc9b 84 uint32_t GMXXXRead32();
runesla 0:2fec9850cc9b 85 };
runesla 0:2fec9850cc9b 86 #endif