From b5cedb804a8a212b27dcc63f859e2871ff4efc37 Mon Sep 17 00:00:00 2001 From: Kevin Goveas Date: Thu, 9 Mar 2023 08:01:21 +0100 Subject: [PATCH 1/5] Added missing config files --- src/config/generic_18v_300s_28d/bsec_iaq.txt | 1 + src/config/generic_18v_300s_4d/bsec_iaq.txt | 1 + src/config/generic_18v_3s_28d/bsec_iaq.txt | 1 + src/config/generic_18v_3s_4d/bsec_iaq.txt | 1 + src/config/generic_33v_300s_28d/bsec_iaq.txt | 1 + src/config/generic_33v_300s_4d/bsec_iaq.txt | 1 + src/config/generic_33v_3s_28d/bsec_iaq.txt | 1 + src/config/generic_33v_3s_4d/bsec_iaq.txt | 1 + 8 files changed, 8 insertions(+) create mode 100644 src/config/generic_18v_300s_28d/bsec_iaq.txt create mode 100644 src/config/generic_18v_300s_4d/bsec_iaq.txt create mode 100644 src/config/generic_18v_3s_28d/bsec_iaq.txt create mode 100644 src/config/generic_18v_3s_4d/bsec_iaq.txt create mode 100644 src/config/generic_33v_300s_28d/bsec_iaq.txt create mode 100644 src/config/generic_33v_300s_4d/bsec_iaq.txt create mode 100644 src/config/generic_33v_3s_28d/bsec_iaq.txt create mode 100644 src/config/generic_33v_3s_4d/bsec_iaq.txt diff --git a/src/config/generic_18v_300s_28d/bsec_iaq.txt b/src/config/generic_18v_300s_28d/bsec_iaq.txt new file mode 100644 index 0000000..30603e7 --- /dev/null +++ b/src/config/generic_18v_300s_28d/bsec_iaq.txt @@ -0,0 +1 @@ +2,9,4,1,61,0,0,0,0,0,0,0,182,1,0,0,52,0,1,0,0,168,19,73,64,49,119,76,0,0,97,69,0,0,97,69,137,65,0,191,205,204,204,190,0,0,64,191,225,122,148,190,10,0,3,0,216,85,0,100,0,0,96,64,23,183,209,56,28,0,2,0,0,244,1,150,0,50,0,0,128,64,0,0,32,65,144,1,0,0,112,65,0,0,0,63,16,0,3,0,10,215,163,60,10,215,35,59,10,215,35,59,13,0,5,0,0,0,0,0,1,254,131,137,87,88,0,9,0,7,240,150,61,0,0,0,0,0,0,0,0,28,124,225,61,52,128,215,63,0,0,160,64,0,0,0,0,0,0,0,0,205,204,12,62,103,213,39,62,230,63,76,192,0,0,0,0,0,0,0,0,145,237,60,191,251,58,64,63,177,80,131,64,0,0,0,0,0,0,0,0,93,254,227,62,54,60,133,191,0,0,64,64,12,0,10,0,0,0,0,0,0,0,0,0,229,0,254,0,2,1,5,48,117,100,0,44,1,112,23,151,7,132,3,197,0,92,4,144,1,64,1,64,1,144,1,48,117,48,117,48,117,48,117,100,0,100,0,100,0,48,117,48,117,48,117,100,0,100,0,48,117,48,117,100,0,100,0,100,0,100,0,48,117,48,117,48,117,100,0,100,0,100,0,48,117,48,117,100,0,100,0,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,255,255,255,255,255,255,255,255,220,5,220,5,220,5,255,255,255,255,255,255,220,5,220,5,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,48,117,0,0,0,0,98,60,0,0 \ No newline at end of file diff --git a/src/config/generic_18v_300s_4d/bsec_iaq.txt b/src/config/generic_18v_300s_4d/bsec_iaq.txt new file mode 100644 index 0000000..6bfcd97 --- /dev/null +++ b/src/config/generic_18v_300s_4d/bsec_iaq.txt @@ -0,0 +1 @@ +2,9,4,1,61,0,0,0,0,0,0,0,182,1,0,0,52,0,1,0,0,192,168,71,64,49,119,76,0,0,97,69,0,0,97,69,137,65,0,191,205,204,204,190,0,0,64,191,225,122,148,190,10,0,3,0,216,85,0,100,0,0,96,64,23,183,209,56,28,0,2,0,0,244,1,150,0,50,0,0,128,64,0,0,32,65,144,1,0,0,112,65,0,0,0,63,16,0,3,0,10,215,163,60,10,215,35,59,10,215,35,59,13,0,5,0,0,0,0,0,1,35,41,29,86,88,0,9,0,7,240,150,61,0,0,0,0,0,0,0,0,28,124,225,61,52,128,215,63,0,0,160,64,0,0,0,0,0,0,0,0,205,204,12,62,103,213,39,62,230,63,76,192,0,0,0,0,0,0,0,0,145,237,60,191,251,58,64,63,177,80,131,64,0,0,0,0,0,0,0,0,93,254,227,62,54,60,133,191,0,0,64,64,12,0,10,0,0,0,0,0,0,0,0,0,229,0,254,0,2,1,5,48,117,100,0,44,1,112,23,151,7,132,3,197,0,92,4,144,1,64,1,64,1,144,1,48,117,48,117,48,117,48,117,100,0,100,0,100,0,48,117,48,117,48,117,100,0,100,0,48,117,48,117,100,0,100,0,100,0,100,0,48,117,48,117,48,117,100,0,100,0,100,0,48,117,48,117,100,0,100,0,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,255,255,255,255,255,255,255,255,220,5,220,5,220,5,255,255,255,255,255,255,220,5,220,5,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,48,117,0,0,0,0,179,77,0,0 \ No newline at end of file diff --git a/src/config/generic_18v_3s_28d/bsec_iaq.txt b/src/config/generic_18v_3s_28d/bsec_iaq.txt new file mode 100644 index 0000000..7e2819d --- /dev/null +++ b/src/config/generic_18v_3s_28d/bsec_iaq.txt @@ -0,0 +1 @@ +2,9,4,1,61,0,0,0,0,0,0,0,182,1,0,0,52,0,1,0,0,168,19,73,64,49,119,76,0,192,40,72,0,192,40,72,137,65,0,191,205,204,204,190,0,0,64,191,225,122,148,190,10,0,3,0,216,85,0,100,0,0,96,64,23,183,209,56,28,0,2,0,0,244,1,150,0,50,0,0,128,64,0,0,32,65,144,1,0,0,112,65,0,0,0,63,16,0,3,0,10,215,163,60,10,215,35,59,10,215,35,59,13,0,5,0,0,0,0,0,1,254,131,137,87,88,0,9,0,7,240,150,61,0,0,0,0,0,0,0,0,28,124,225,61,52,128,215,63,0,0,160,64,0,0,0,0,0,0,0,0,205,204,12,62,103,213,39,62,230,63,76,192,0,0,0,0,0,0,0,0,145,237,60,191,251,58,64,63,177,80,131,64,0,0,0,0,0,0,0,0,93,254,227,62,54,60,133,191,0,0,64,64,12,0,10,0,0,0,0,0,0,0,0,0,229,0,254,0,2,1,5,48,117,100,0,44,1,112,23,151,7,132,3,197,0,92,4,144,1,64,1,64,1,144,1,48,117,48,117,48,117,48,117,100,0,100,0,100,0,48,117,48,117,48,117,100,0,100,0,48,117,48,117,100,0,100,0,100,0,100,0,48,117,48,117,48,117,100,0,100,0,100,0,48,117,48,117,100,0,100,0,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,255,255,255,255,255,255,255,255,220,5,220,5,220,5,255,255,255,255,255,255,220,5,220,5,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,44,1,0,0,0,0,226,221,0,0 \ No newline at end of file diff --git a/src/config/generic_18v_3s_4d/bsec_iaq.txt b/src/config/generic_18v_3s_4d/bsec_iaq.txt new file mode 100644 index 0000000..cd231d5 --- /dev/null +++ b/src/config/generic_18v_3s_4d/bsec_iaq.txt @@ -0,0 +1 @@ +2,9,4,1,61,0,0,0,0,0,0,0,182,1,0,0,52,0,1,0,0,192,168,71,64,49,119,76,0,0,97,69,0,0,97,69,137,65,0,191,205,204,204,190,0,0,64,191,225,122,148,190,10,0,3,0,216,85,0,100,0,0,96,64,23,183,209,56,28,0,2,0,0,244,1,150,0,50,0,0,128,64,0,0,32,65,144,1,0,0,112,65,0,0,0,63,16,0,3,0,10,215,163,60,10,215,35,59,10,215,35,59,13,0,5,0,0,0,0,0,1,35,41,29,86,88,0,9,0,7,240,150,61,0,0,0,0,0,0,0,0,28,124,225,61,52,128,215,63,0,0,160,64,0,0,0,0,0,0,0,0,205,204,12,62,103,213,39,62,230,63,76,192,0,0,0,0,0,0,0,0,145,237,60,191,251,58,64,63,177,80,131,64,0,0,0,0,0,0,0,0,93,254,227,62,54,60,133,191,0,0,64,64,12,0,10,0,0,0,0,0,0,0,0,0,229,0,254,0,2,1,5,48,117,100,0,44,1,112,23,151,7,132,3,197,0,92,4,144,1,64,1,64,1,144,1,48,117,48,117,48,117,48,117,100,0,100,0,100,0,48,117,48,117,48,117,100,0,100,0,48,117,48,117,100,0,100,0,100,0,100,0,48,117,48,117,48,117,100,0,100,0,100,0,48,117,48,117,100,0,100,0,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,255,255,255,255,255,255,255,255,220,5,220,5,220,5,255,255,255,255,255,255,220,5,220,5,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,44,1,0,0,0,0,33,68,0,0 \ No newline at end of file diff --git a/src/config/generic_33v_300s_28d/bsec_iaq.txt b/src/config/generic_33v_300s_28d/bsec_iaq.txt new file mode 100644 index 0000000..2024999 --- /dev/null +++ b/src/config/generic_33v_300s_28d/bsec_iaq.txt @@ -0,0 +1 @@ +2,9,4,1,61,0,0,0,0,0,0,0,182,1,0,0,52,0,1,0,0,168,19,73,64,49,119,76,0,0,97,69,0,0,97,69,137,65,0,191,205,204,204,190,0,0,64,191,225,122,148,190,10,0,3,0,216,85,0,100,0,0,96,64,23,183,209,56,28,0,2,0,0,244,1,150,0,50,0,0,128,64,0,0,32,65,144,1,0,0,112,65,0,0,0,63,16,0,3,0,10,215,163,60,10,215,35,59,10,215,35,59,13,0,5,0,0,0,0,0,1,254,131,137,87,88,0,9,0,229,208,34,62,0,0,0,0,0,0,0,0,218,27,156,62,225,11,67,64,0,0,160,64,0,0,0,0,0,0,0,0,94,75,72,189,93,254,159,64,66,62,160,191,0,0,0,0,0,0,0,0,33,31,180,190,138,176,97,64,65,241,99,190,0,0,0,0,0,0,0,0,167,121,71,61,165,189,41,192,184,30,189,64,12,0,10,0,0,0,0,0,0,0,0,0,229,0,254,0,2,1,5,48,117,100,0,44,1,112,23,151,7,132,3,197,0,92,4,144,1,64,1,64,1,144,1,48,117,48,117,48,117,48,117,100,0,100,0,100,0,48,117,48,117,48,117,100,0,100,0,48,117,48,117,100,0,100,0,100,0,100,0,48,117,48,117,48,117,100,0,100,0,100,0,48,117,48,117,100,0,100,0,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,255,255,255,255,255,255,255,255,220,5,220,5,220,5,255,255,255,255,255,255,220,5,220,5,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,48,117,0,0,0,0,220,133,0,0 \ No newline at end of file diff --git a/src/config/generic_33v_300s_4d/bsec_iaq.txt b/src/config/generic_33v_300s_4d/bsec_iaq.txt new file mode 100644 index 0000000..c182ce7 --- /dev/null +++ b/src/config/generic_33v_300s_4d/bsec_iaq.txt @@ -0,0 +1 @@ +2,9,4,1,61,0,0,0,0,0,0,0,182,1,0,0,52,0,1,0,0,192,168,71,64,49,119,76,0,0,97,69,0,0,97,69,137,65,0,191,205,204,204,190,0,0,64,191,225,122,148,190,10,0,3,0,216,85,0,100,0,0,96,64,23,183,209,56,28,0,2,0,0,244,1,150,0,50,0,0,128,64,0,0,32,65,144,1,0,0,112,65,0,0,0,63,16,0,3,0,10,215,163,60,10,215,35,59,10,215,35,59,13,0,5,0,0,0,0,0,1,35,41,29,86,88,0,9,0,229,208,34,62,0,0,0,0,0,0,0,0,218,27,156,62,225,11,67,64,0,0,160,64,0,0,0,0,0,0,0,0,94,75,72,189,93,254,159,64,66,62,160,191,0,0,0,0,0,0,0,0,33,31,180,190,138,176,97,64,65,241,99,190,0,0,0,0,0,0,0,0,167,121,71,61,165,189,41,192,184,30,189,64,12,0,10,0,0,0,0,0,0,0,0,0,229,0,254,0,2,1,5,48,117,100,0,44,1,112,23,151,7,132,3,197,0,92,4,144,1,64,1,64,1,144,1,48,117,48,117,48,117,48,117,100,0,100,0,100,0,48,117,48,117,48,117,100,0,100,0,48,117,48,117,100,0,100,0,100,0,100,0,48,117,48,117,48,117,100,0,100,0,100,0,48,117,48,117,100,0,100,0,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,255,255,255,255,255,255,255,255,220,5,220,5,220,5,255,255,255,255,255,255,220,5,220,5,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,48,117,0,0,0,0,13,244,0,0 \ No newline at end of file diff --git a/src/config/generic_33v_3s_28d/bsec_iaq.txt b/src/config/generic_33v_3s_28d/bsec_iaq.txt new file mode 100644 index 0000000..b077fd1 --- /dev/null +++ b/src/config/generic_33v_3s_28d/bsec_iaq.txt @@ -0,0 +1 @@ +2,9,4,1,61,0,0,0,0,0,0,0,182,1,0,0,52,0,1,0,0,168,19,73,64,49,119,76,0,192,40,72,0,192,40,72,137,65,0,191,205,204,204,190,0,0,64,191,225,122,148,190,10,0,3,0,216,85,0,100,0,0,96,64,23,183,209,56,28,0,2,0,0,244,1,150,0,50,0,0,128,64,0,0,32,65,144,1,0,0,112,65,0,0,0,63,16,0,3,0,10,215,163,60,10,215,35,59,10,215,35,59,13,0,5,0,0,0,0,0,1,254,131,137,87,88,0,9,0,229,208,34,62,0,0,0,0,0,0,0,0,218,27,156,62,225,11,67,64,0,0,160,64,0,0,0,0,0,0,0,0,94,75,72,189,93,254,159,64,66,62,160,191,0,0,0,0,0,0,0,0,33,31,180,190,138,176,97,64,65,241,99,190,0,0,0,0,0,0,0,0,167,121,71,61,165,189,41,192,184,30,189,64,12,0,10,0,0,0,0,0,0,0,0,0,229,0,254,0,2,1,5,48,117,100,0,44,1,112,23,151,7,132,3,197,0,92,4,144,1,64,1,64,1,144,1,48,117,48,117,48,117,48,117,100,0,100,0,100,0,48,117,48,117,48,117,100,0,100,0,48,117,48,117,100,0,100,0,100,0,100,0,48,117,48,117,48,117,100,0,100,0,100,0,48,117,48,117,100,0,100,0,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,255,255,255,255,255,255,255,255,220,5,220,5,220,5,255,255,255,255,255,255,220,5,220,5,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,44,1,0,0,0,0,92,100,0,0 \ No newline at end of file diff --git a/src/config/generic_33v_3s_4d/bsec_iaq.txt b/src/config/generic_33v_3s_4d/bsec_iaq.txt new file mode 100644 index 0000000..7aae2d8 --- /dev/null +++ b/src/config/generic_33v_3s_4d/bsec_iaq.txt @@ -0,0 +1 @@ +2,9,4,1,61,0,0,0,0,0,0,0,182,1,0,0,52,0,1,0,0,192,168,71,64,49,119,76,0,0,97,69,0,0,97,69,137,65,0,191,205,204,204,190,0,0,64,191,225,122,148,190,10,0,3,0,216,85,0,100,0,0,96,64,23,183,209,56,28,0,2,0,0,244,1,150,0,50,0,0,128,64,0,0,32,65,144,1,0,0,112,65,0,0,0,63,16,0,3,0,10,215,163,60,10,215,35,59,10,215,35,59,13,0,5,0,0,0,0,0,1,35,41,29,86,88,0,9,0,229,208,34,62,0,0,0,0,0,0,0,0,218,27,156,62,225,11,67,64,0,0,160,64,0,0,0,0,0,0,0,0,94,75,72,189,93,254,159,64,66,62,160,191,0,0,0,0,0,0,0,0,33,31,180,190,138,176,97,64,65,241,99,190,0,0,0,0,0,0,0,0,167,121,71,61,165,189,41,192,184,30,189,64,12,0,10,0,0,0,0,0,0,0,0,0,229,0,254,0,2,1,5,48,117,100,0,44,1,112,23,151,7,132,3,197,0,92,4,144,1,64,1,64,1,144,1,48,117,48,117,48,117,48,117,100,0,100,0,100,0,48,117,48,117,48,117,100,0,100,0,48,117,48,117,100,0,100,0,100,0,100,0,48,117,48,117,48,117,100,0,100,0,100,0,48,117,48,117,100,0,100,0,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,44,1,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,8,7,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,112,23,255,255,255,255,255,255,255,255,220,5,220,5,220,5,255,255,255,255,255,255,220,5,220,5,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,44,1,0,0,0,0,159,253,0,0 \ No newline at end of file From 5c5c6d1ea22b9de083b709b68dc27277768d79fa Mon Sep 17 00:00:00 2001 From: Kevin Goveas Date: Thu, 9 Mar 2023 08:01:57 +0100 Subject: [PATCH 2/5] Added octopus_demo example. Updated esp32DeepSleep example. --- examples/esp32DeepSleep/README.md | 5 + examples/esp32DeepSleep/esp32DeepSleep.ino | 26 +- .../octopus_demo/OLED_featherwing_display.cpp | 95 +++ .../octopus_demo/OLED_featherwing_display.h | 69 ++ examples/octopus_demo/README.md | 6 + examples/octopus_demo/logos.cpp | 23 + examples/octopus_demo/logos.h | 61 ++ examples/octopus_demo/octopus_demo.ino | 642 ++++++++++++++++++ 8 files changed, 911 insertions(+), 16 deletions(-) create mode 100644 examples/esp32DeepSleep/README.md create mode 100644 examples/octopus_demo/OLED_featherwing_display.cpp create mode 100644 examples/octopus_demo/OLED_featherwing_display.h create mode 100644 examples/octopus_demo/README.md create mode 100644 examples/octopus_demo/logos.cpp create mode 100644 examples/octopus_demo/logos.h create mode 100644 examples/octopus_demo/octopus_demo.ino diff --git a/examples/esp32DeepSleep/README.md b/examples/esp32DeepSleep/README.md new file mode 100644 index 0000000..fb5712e --- /dev/null +++ b/examples/esp32DeepSleep/README.md @@ -0,0 +1,5 @@ +The compensated temperature, compensated humidity, IAQ & Static IAQ are not supported in this example code +because bsec expects the time to be ticking but during deepsleep the time resets to 0. + +To overcome this the sleep duration can be added to the millis and passed to bsec from the example code. +Changes in bsec.c is also needed for this to work. \ No newline at end of file diff --git a/examples/esp32DeepSleep/esp32DeepSleep.ino b/examples/esp32DeepSleep/esp32DeepSleep.ino index 8a4a6d4..6904165 100644 --- a/examples/esp32DeepSleep/esp32DeepSleep.ino +++ b/examples/esp32DeepSleep/esp32DeepSleep.ino @@ -31,12 +31,8 @@ bsec_virtual_sensor_t sensor_list[] = { BSEC_OUTPUT_RAW_PRESSURE, BSEC_OUTPUT_RAW_HUMIDITY, BSEC_OUTPUT_RAW_GAS, - BSEC_OUTPUT_IAQ, - BSEC_OUTPUT_STATIC_IAQ, BSEC_OUTPUT_CO2_EQUIVALENT, BSEC_OUTPUT_BREATH_VOC_EQUIVALENT, - BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE, - BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY, }; int64_t GetTimestamp() { @@ -46,18 +42,18 @@ int64_t GetTimestamp() { } bool CheckSensor() { - if (sensor.status < BSEC_OK) { - LOG("BSEC error, status %d!", sensor.status); + if (sensor.bsecStatus < BSEC_OK) { + LOG("BSEC error, status %d!", sensor.bsecStatus); return false;; - } else if (sensor.status > BSEC_OK) { - LOG("BSEC warning, status %d!", sensor.status); + } else if (sensor.bsecStatus > BSEC_OK) { + LOG("BSEC warning, status %d!", sensor.bsecStatus); } - if (sensor.bme680Status < BME680_OK) { - LOG("Sensor error, bme680_status %d!", sensor.bme680Status); + if (sensor.bme68xStatus < BME68X_OK) { + LOG("Sensor error, bme680_status %d!", sensor.bme68xStatus); return false; - } else if (sensor.bme680Status > BME680_OK) { - LOG("Sensor warning, status %d!", sensor.bme680Status); + } else if (sensor.bme68xStatus > BME68X_OK) { + LOG("Sensor warning, status %d!", sensor.bme68xStatus); } return true; @@ -114,12 +110,10 @@ void setup() { } void loop() { - if (sensor.run(GetTimestamp())) { + if (sensor.run()) { LOG("Temperature raw %.2f compensated %.2f", sensor.rawTemperature, sensor.temperature); LOG("Humidity raw %.2f compensated %.2f", sensor.rawHumidity, sensor.humidity); LOG("Pressure %.2f kPa", sensor.pressure / 1000); - LOG("IAQ %.0f accuracy %d", sensor.iaq, sensor.iaqAccuracy); - LOG("Static IAQ %.0f accuracy %d", sensor.staticIaq, sensor.staticIaqAccuracy); LOG("Gas resistance %.2f kOhm", sensor.gasResistance / 1000); sensor_state_time = GetTimestamp(); @@ -128,7 +122,7 @@ void loop() { LOG("Saved state to RTC memory at %lld", sensor_state_time); CheckSensor(); - uint64_t time_us = ((sensor.nextCall - GetTimestamp()) * 1000) - esp_timer_get_time(); + uint64_t time_us = (sensor.nextCall * 1000) - esp_timer_get_time(); LOG("Deep sleep for %llu ms. BSEC next call at %llu ms.", time_us / 1000, sensor.nextCall); esp_sleep_enable_timer_wakeup(time_us); esp_deep_sleep_start(); diff --git a/examples/octopus_demo/OLED_featherwing_display.cpp b/examples/octopus_demo/OLED_featherwing_display.cpp new file mode 100644 index 0000000..9860d28 --- /dev/null +++ b/examples/octopus_demo/OLED_featherwing_display.cpp @@ -0,0 +1,95 @@ +/** Global Library includes */ + +/** Local Library includes */ + +#include "OLED_featherwing_display.h" + +/** Global variables */ +ImageList image_list[NUMBER_OF_IMAGES]; + +// Create an SSD1306 display object +Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire); + +/** Function definitions */ + +/********************************************************************************/ +void initialize_display() +{ + // Decode logos from uint32_t x 32 (32x32) to uint8_t x 128 + decodeLogo(image_list[0].image, logo_bosch); + decodeLogo(image_list[1].image, logo_temp); + decodeLogo(image_list[2].image, logo_pres); + decodeLogo(image_list[3].image, logo_hum); + decodeLogo(image_list[4].image, logo_gas); + // Initialize the OLED display + display.begin(SSD1306_SWITCHCAPVCC, DISPLAY_I2C_ADDR); // initialize with the I2C addr 0x3C (for the 128x32) + display.clearDisplay(); + display.display(); +} + +/********************************************************************************/ +void display_print_string(String text, uint8_t x_axis, uint8_t y_axis, uint8_t text_size) +{ + display.clearDisplay(); + display.setTextSize(text_size); + display.setTextColor(WHITE); + display.setCursor(x_axis, y_axis); + display.println(text); + display.display(); +} +/********************************************************************************/ + +void display_print_multi_string(String line1, uint8_t x_axis1, uint8_t y_axis1, uint8_t text_size1, String line2_0, + String line2, + uint8_t x_axis2, uint8_t y_axis2, uint8_t text_size2) +{ + display.clearDisplay(); + display.setTextSize(text_size1); + display.setTextColor(WHITE); + display.setCursor(x_axis1, y_axis1); + display.println(line1); + + display.setTextSize(text_size2); + display.setTextColor(WHITE); + display.setCursor(x_axis2, y_axis2); + display.println(line2); + + display.setTextSize(1); + display.setTextColor(WHITE); + display.setCursor(110, 16); + display.println(" A"); + display.setCursor(110, 24); + display.println(line2_0); + + display.display(); +} + +/********************************************************************************/ +void display_bosch_logo(String fwVersion) +{ + display.clearDisplay(); + display.drawBitmap(0, 0, image_list[0].image, 32, 32, WHITE); + display.setTextSize(2); + display.setTextColor(WHITE); + display.setCursor(40, 10); + display.println("BOSCH"); + display.setTextSize(1); + display.setCursor(40, 00); + display.println(fwVersion); + display.display(); +} + +void display_print_img_string(String label, String value, uint8_t bmp, uint8_t label_size, uint8_t value_size) +{ + display.clearDisplay(); + display.drawBitmap(0, 0, image_list[bmp].image, 32, 32, WHITE); + display.setTextSize(label_size); + display.setTextColor(WHITE); + display.setCursor(40, 0); + display.println(label); + display.setTextSize(value_size); + display.setCursor(40, 20); + display.println(value); + display.display(); +} + diff --git a/examples/octopus_demo/OLED_featherwing_display.h b/examples/octopus_demo/OLED_featherwing_display.h new file mode 100644 index 0000000..65eecea --- /dev/null +++ b/examples/octopus_demo/OLED_featherwing_display.h @@ -0,0 +1,69 @@ +/** Global Library includes */ + +#ifndef __OLED_FEATHERWING_DISPLAY_H_ +#define __OLED_FEATHERWING_DISPLAY_H_ + +#include +#include +#include + +/** Local Library includes */ + +#include "logos.h" + +/** Defines and consts */ +#define NUMBER_OF_IMAGES 5u +#define DISPLAY_I2C_ADDR 0x3c + +/** Structs and enums */ + +struct ImageList +{ + uint8_t image[128]; +}; + +extern ImageList image_list[NUMBER_OF_IMAGES]; + +/** Function declarations */ + +/** + * @brief Function used to initialize local objects for images with + * global consts from logos.h file + */ +void initialize_display(); + +/** + * @brief Function used to clear display and print the input string + * @param text [input] Input string that needs to be printed on display. + */ +void display_print_string(String text, uint8_t x_axis, uint8_t y_axis, uint8_t text_size); + +/** + * @brief Function used to clear display and print the input string + * @param text [input] Input string that needs to be printed on display. + */ +void display_print_multi_string(String line1, uint8_t x_axis1, uint8_t y_axis1, uint8_t text_size1, + String line2_0, + String line2, uint8_t x_axis2, uint8_t y_axis2, uint8_t text_size2); + +/** + * @brief Function used to display BOSCH logo on OLED display. + * @param fwVersion [input] Firmware version that needs to be printed on OLED Display + */ +void display_bosch_logo(String fwVersion); + +/** + * @brief Function used to clear display and print input label and string based on bmp Index. + * @param label [input] Title which needs to be printed on display + * @param value [input] Value which needs to be printed on display + * @param bmp [input] Index number corresponding to bmp files + * @param label_size [input] Size of label string to be printed on OLED display + * @param value_size [input] Size of value string to be printed on OLED display + */ +void display_print_img_string(String label, String value, uint8_t bmp, uint8_t label_size, uint8_t value_size); + +/** Global variables */ + +extern Adafruit_SSD1306 display; + +#endif diff --git a/examples/octopus_demo/README.md b/examples/octopus_demo/README.md new file mode 100644 index 0000000..b5477b9 --- /dev/null +++ b/examples/octopus_demo/README.md @@ -0,0 +1,6 @@ +Install Adafruit SSD1306, Adafruit GFX Library & Adafruit BusIO from the Arduino Library Manager + +Versions used for testing +Adafruit SSD1306 version 2.3.1 +Adafruit GFX Library version 1.9.0 +Adafruit BusIO version 1.3.3 \ No newline at end of file diff --git a/examples/octopus_demo/logos.cpp b/examples/octopus_demo/logos.cpp new file mode 100644 index 0000000..f0e3bfe --- /dev/null +++ b/examples/octopus_demo/logos.cpp @@ -0,0 +1,23 @@ +#include "logos.h" + +void decodeLogo(uint8_t *bitmap, const uint32_t *logo) +{ + uint8_t i, j; + + for (i = 0; i < 128; i++) + bitmap[i] = 0; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 32; j++) + { + bitmap[(4 * j) + i] = (((logo[i * 8] & 1 << j) >> j) << 7) | + (((logo[(i * 8) + 1] & 1 << j) >> j) << 6) | + (((logo[(i * 8) + 2] & 1 << j) >> j) << 5) | + (((logo[(i * 8) + 3] & 1 << j) >> j) << 4) | + (((logo[(i * 8) + 4] & 1 << j) >> j) << 3) | + (((logo[(i * 8) + 5] & 1 << j) >> j) << 2) | + (((logo[(i * 8) + 6] & 1 << j) >> j) << 1) | + (((logo[(i * 8) + 7] & 1 << j) >> j)); + } + } +} diff --git a/examples/octopus_demo/logos.h b/examples/octopus_demo/logos.h new file mode 100644 index 0000000..90b4012 --- /dev/null +++ b/examples/octopus_demo/logos.h @@ -0,0 +1,61 @@ +#ifndef __LOGOS_H_ +#define __LOGOS_H_ + +#include + +void decodeLogo(uint8_t *bitmap, const uint32_t *logo); + +const uint8_t lockBmp[32] = { +B00000000, B00000000, +B00000000, B00000000, +B00000011, B11000000, +B00001100, B00110000, +B00011000, B00011000, +B00011000, B00011000, +B00011000, B00011000, +B00011000, B00011000, +B00111111, B11111100, +B00111110, B01111100, +B00111100, B00111100, +B00111100, B00111100, +B00111110, B01111100, +B00111110, B01111100, +B00111111, B11111100, +B00011111, B11111000 }; + +const uint32_t logo_bosch[32] = { 0x00000000, 0x000FF000, 0x003FFC00, + 0x00F00F00, 0x03C003C0, 0x071FF8E0, 0x067FFE60, 0x0CE00730, 0x19C00398, + 0x3B8001DC, 0x33FFFFCC, 0x33FFFFCC, 0x60381C06, 0x60381C06, 0x60381C06, + 0x60381C06, 0x60381C06, 0x60381C06, 0x60381C06, 0x60381C06, 0x33FFFFCC, + 0x33FFFFCC, 0x3B8001DC, 0x19C00398, 0x0CE00730, 0x067FFE60, 0x071FF8E0, + 0x03C003C0, 0x00F00F00, 0x003FFC00, 0x000FF000, 0x00000000 }; + +const uint32_t logo_temp[32] = { 0x00000000, 0x00000000, 0x00001000, 0x00001000, + 0x00011080, 0x00011080, 0x000113E0, 0x00011080, 0x00011080, 0x00001000, + 0x03C01000, 0x07E01000, 0x1C3FFFFC, 0x193FFFFE, 0x3B80100E, 0x3904522E, + 0x1C3FFFFE, 0x1FFFFFFC, 0x08301000, 0x10101000, 0x20081000, 0x40441000, + 0x40441000, 0x47C41000, 0x40441000, 0x40441000, 0x20081000, 0x10101000, + 0x08201000, 0x07C00000, 0x00000000 }; + +const uint32_t logo_hum[32] = { 0x00000000, 0x00000000, 0x01FF0000, 0x03FFC000, + 0x0701F000, 0x0E007800, 0x1C7C1C00, 0x38E00E00, 0x71800700, 0x73000380, + 0x730001C0, 0x720000E0, 0x72000070, 0x72001FF0, 0x710071E0, 0x38006670, + 0x1FF0CC18, 0x0C09980C, 0x10059006, 0x23E3900C, 0x21A1C818, 0x42E16070, + 0x400131C0, 0x43E11F00, 0x40810000, 0x20810000, 0x23E20000, 0x10040000, + 0x0C080000, 0x03F00000, 0x00000000, 0x00000000 }; + +const uint32_t logo_pres[32] = { 0x00000000, 0x00000400, 0x00000400, 0x1F1FC400, + 0x31BFE404, 0x64FFF008, 0x6E607C10, 0x64303F80, 0x30181C40, 0x180C0C20, + 0x0E060C20, 0x07030C20, 0x03C18C2E, 0x03E0DC20, 0x03B87840, 0x038C3F80, + 0x03871C00, 0x0381CE40, 0x07C07320, 0x08201990, 0x10101EC0, 0x20081BE0, + 0x400418F0, 0x4FE47838, 0x4124F000, 0x4124C000, 0x40C7C000, 0x200F8000, + 0x101F0000, 0x08200000, 0x07C00000, 0x00000000 }; + +const uint32_t logo_gas[32] = { 0x00000000, 0x038000F8, 0x0440018C, 0x08200306, + 0x08200202, 0x08600202, 0x04900202, 0x0389F706, 0x0047F98C, 0x002F10F8, + 0x001E2080, 0x00382100, 0x00381380, 0x00380F80, 0x003E0380, 0x00390380, + 0x00108380, 0x00208700, 0x07E11E80, 0x0833FC40, 0x101DF238, 0x23880124, + 0x444400C2, 0x48240082, 0x49240082, 0x4F240044, 0x41040038, 0x20080000, + 0x10100000, 0x08200000, 0x07C00000, 0x00000000 }; + +#endif diff --git a/examples/octopus_demo/octopus_demo.ino b/examples/octopus_demo/octopus_demo.ino new file mode 100644 index 0000000..e7436df --- /dev/null +++ b/examples/octopus_demo/octopus_demo.ino @@ -0,0 +1,642 @@ +/** + * octopus_demo.cpp + * + * Functionalities: Demo application to showcase the functionality of BME680 by configuring + * the sensor in different modes of operation (ULP, LP and CONT) for different + * data update rates at user level which in turn provides access to various use case. + */ + +/** Global Library includes */ +#include "bsec.h" +#include + +/* Configure the BSEC library with information about the sensor + 18v/33v = Voltage at Vdd. 1.8V or 3.3V + 3s/300s = BSEC operating mode, BSEC_SAMPLE_RATE_LP or BSEC_SAMPLE_RATE_ULP + 4d/28d = Operating age of the sensor in days + generic_18v_3s_4d + generic_18v_3s_28d + generic_18v_300s_4d + generic_18v_300s_28d + generic_33v_3s_4d + generic_33v_3s_28d + generic_33v_300s_4d + generic_33v_300s_28d +*/ +const uint8_t bsec_config_iaq[] = { +#include "config/generic_33v_3s_4d/bsec_iaq.txt" +}; + +/** Local Library includes */ + +#include "OLED_featherwing_display.h" +/** Defines and consts */ + +// #define DEBUG_MODE + +#define BUTTON_A 0 /**< Pin connected to OLED Featherwing on Octopus board */ +#define BUTTON_C 2 /**< Pin connected to OLED Featherwing on Octopus board */ + +/* Save all 3 modes of operating parameters in EEPROM */ + +#define EEPROM_NUMBER_OF_REGIONS 3u +#define EEPROM_BYTES_PER_REGION (BSEC_MAX_STATE_BLOB_SIZE + 1) /* This value indicates max bytes per region including region identifier length*/ + +#define BSEC_EEPROM_ULP_IDENTIFIER 0u +#define BSEC_EEPROM_ULP_REGION_START 1u +#define BSEC_EEPROM_ULP_REGION_END (EEPROM_BYTES_PER_REGION) + +#define BSEC_EEPROM_LP_IDENTIFIER BSEC_EEPROM_ULP_REGION_END +#define BSEC_EEPROM_LP_REGION_START (BSEC_EEPROM_LP_IDENTIFIER + 1) +#define BSEC_EEPROM_LP_REGION_END (BSEC_EEPROM_LP_REGION_START + EEPROM_BYTES_PER_REGION) + +#define BSEC_EEPROM_CONT_IDENTIFIER BSEC_EEPROM_LP_REGION_END +#define BSEC_EEPROM_CONT_REGION_START (BSEC_EEPROM_CONT_IDENTIFIER + 1) +#define BSEC_EEPROM_CONT_REGION_END (BSEC_EEPROM_CONT_REGION_START + EEPROM_BYTES_PER_REGION) + +#define EEPROM_TOTAL_ALLOCATED_BYTES (BSEC_EEPROM_CONT_REGION_END) + +/** Structs and enums */ +typedef enum +{ + ULP_MODE_SCREEN_OFF = 1, + LP_MODE_SCREEN_ON = 2, + CONT_MODE_BREATH = 3 +} OPERATING_MODES; + +/** Global variables */ + +OPERATING_MODES operating_mode = LP_MODE_SCREEN_ON; +static float previous_IAQ = 0; +static uint8_t previous_IAQ_acc = 0; + +uint8_t bsec_state_ulp[BSEC_MAX_STATE_BLOB_SIZE] = { 0 }; +uint8_t bsec_state_lp[BSEC_MAX_STATE_BLOB_SIZE] = { 0 }; +uint8_t bsec_state_cont[BSEC_MAX_STATE_BLOB_SIZE] = { 0 }; + +bsec_virtual_sensor_t sensorList[5] = { + BSEC_OUTPUT_RAW_TEMPERATURE, + BSEC_OUTPUT_RAW_PRESSURE, + BSEC_OUTPUT_RAW_HUMIDITY, + BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE, + BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY +}; + +bsec_virtual_sensor_t sensorIAQ[2] = { + BSEC_OUTPUT_RAW_GAS, + BSEC_OUTPUT_IAQ +}; + +String output; + +// Create a Bsec object +Bsec iaqSensor; + +/** Function declarations */ +void ICACHE_RAM_ATTR button_press_A(void); +void ICACHE_RAM_ATTR button_press_C(void); +bool button_A_intr = false; +bool button_C_intr = false; +void eeprom_initialize(void); +void configure_sensor_mode(OPERATING_MODES operating_mode); +void report_status(void); +void err_leds(void); +void load_state(OPERATING_MODES operating_mode); +void update_state(OPERATING_MODES operating_mode); + +/** + * @brief Setup function for peripherals and other controls of MCU. + * + */ +void setup() +{ + /* Initialize Serial Terminal */ + Serial.begin(115200); + /* Temporary place holder for firmware version */ + String bsecVersion; + /* Initialize I2C */ + Wire.begin(); + + /* Required delay for OLED display to get sufficient time after power on. */ + delay(1000); + pinMode(LED_BUILTIN, OUTPUT); + Serial.print("\nInitializing OLED Display"); + /* Initialize OLED display */ + initialize_display(); + + display_print_string("Initializing...", 0, 0, 1); + + Serial.print("\nInitializing on board EEPROM"); + eeprom_initialize(); + + Serial.print("\nInitializing buttons"); + /* Setup button interrupt to trigger scanning mode */ + pinMode(BUTTON_A, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(BUTTON_A), button_press_A, RISING); + pinMode(BUTTON_C, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(BUTTON_C), button_press_C, RISING); + Serial.print("\nInitializing Sensor connected on I2C Address: "); + Serial.println(BME68X_I2C_ADDR_LOW); + + /* Sensor and Library initialization */ + configure_sensor_mode(operating_mode); + + /* Report loaded library on serial terminal */ + bsecVersion = "BSEC V" + String(iaqSensor.version.major) + "." + String(iaqSensor.version.minor) + "." + String(iaqSensor.version.major_bugfix) + "." + String(iaqSensor.version.minor_bugfix); + Serial.println(bsecVersion); + + // Print the header + output = "Timestamp [ms], raw temp[°C], pressure [hPa], raw relative humidity [%], gas [Ohm], IAQ, IAQ accuracy, comp temp[°C], comp humidity [%], operating mode, bme68x status, bsec status"; + Serial.println(output); + + display_bosch_logo(bsecVersion); +} + +/** + * @brief Arduino continuous looping function. + */ +void loop() +{ + String oled_output_line1, oled_output_line2_0, oled_output_line2; + if (iaqSensor.run()) + { + digitalWrite(LED_BUILTIN, LOW); + output = String(millis()); + output += ", " + String(iaqSensor.rawTemperature); + output += ", " + String(iaqSensor.pressure); + output += ", " + String(iaqSensor.rawHumidity); + output += ", " + String(iaqSensor.gasResistance); + output += ", " + String(iaqSensor.iaq); + output += ", " + String(iaqSensor.iaqAccuracy); + output += ", " + String(iaqSensor.temperature); + output += ", " + String(iaqSensor.humidity); + output += ", " + String(operating_mode); + output += ", " + String(iaqSensor.bme68xStatus); + output += ", " + String(iaqSensor.bsecStatus); + Serial.println(output); + digitalWrite(LED_BUILTIN, HIGH); + + /* Keep updating sensor state values in RAM based on mode of operation */ + switch (operating_mode) + { + case ULP_MODE_SCREEN_OFF: + + iaqSensor.getState(bsec_state_ulp); + + /* Happens only during first time after power on */ + if (EEPROM.read(BSEC_EEPROM_ULP_IDENTIFIER) != BSEC_MAX_STATE_BLOB_SIZE) + { + update_state(ULP_MODE_SCREEN_OFF); + } + + oled_output_line2 = "Mode:ULP"; + break; + + case LP_MODE_SCREEN_ON: + + iaqSensor.getState(bsec_state_lp); + + /* Happens only during first time after power on */ + if (EEPROM.read(BSEC_EEPROM_LP_IDENTIFIER) != BSEC_MAX_STATE_BLOB_SIZE) + { + update_state(LP_MODE_SCREEN_ON); + } + oled_output_line2 = "Mode:LP"; + break; + + case CONT_MODE_BREATH: + + iaqSensor.getState(bsec_state_cont); + /* Happens only during first time after power on */ + if (EEPROM.read(BSEC_EEPROM_CONT_IDENTIFIER) != BSEC_MAX_STATE_BLOB_SIZE) + { + update_state(CONT_MODE_BREATH); + } + oled_output_line2 = "Mode:CONT"; + break; + + default: + break; + + } + + /* String handling segment for OLED display */ + if((iaqSensor.gasResistance == 0) && (iaqSensor.iaq == 0)) + { + oled_output_line1 = "IAQ:" + String(previous_IAQ, 2); + oled_output_line2_0 = " " + String(previous_IAQ_acc); + } + else + { + oled_output_line1 = "IAQ:" + String(iaqSensor.iaq, 2); + previous_IAQ = iaqSensor.iaq; + oled_output_line2_0 = " " + String(iaqSensor.iaqAccuracy); + previous_IAQ_acc = iaqSensor.iaqAccuracy; + } + + oled_output_line2 += " degC:" + + String(iaqSensor.temperature, 1) + + + "\nrH:" + + String(iaqSensor.humidity, 1) + + "% hPa:" + + String((iaqSensor.pressure / 100.0f), 1); + + display_print_multi_string(oled_output_line1, 0, 0, 2, oled_output_line2_0, + oled_output_line2, + 0, 16, 1); + + } + else{ + report_status(); + } + + /* Handle button press interrupt and trigger underlying functionality to switch modes */ + if (button_A_intr == true) + { + switch (operating_mode) + { + case ULP_MODE_SCREEN_OFF: + + /* Update current mode i.e save current values from RAM to EEPROM for LP Mode. */ + update_state(operating_mode); + + /* Toggle operating mode. */ + operating_mode = LP_MODE_SCREEN_ON; + + /* Load settings for new mode from EEPROM to RAM */ + load_state(operating_mode); + + /* Configure sensor operation for updated mode. */ + configure_sensor_mode(operating_mode); + break; + + case LP_MODE_SCREEN_ON: + + /* Update current mode i.e save current values from RAM to EEPROM for LP Mode. */ + update_state(operating_mode); + + /* Toggle operating mode. */ + operating_mode = CONT_MODE_BREATH; + + /* Load settings for new mode from EEPROM to RAM */ + load_state(operating_mode); + + /* Configure sensor operation for updated mode. */ + configure_sensor_mode(operating_mode); + break; + + case CONT_MODE_BREATH: + + /* Reached End of button functionality for this mode. No more further toggling allowed. */ + /* Update current mode i.e save current values from RAM to EEPROM for CONT Mode. */ + operating_mode = CONT_MODE_BREATH; + update_state(operating_mode); + break; + + default: + break; + + } + button_A_intr = false; + } + + /* Handle button press interrupt and trigger underlying functionality to switch modes */ + if (button_C_intr) + { + switch (operating_mode) + { + case ULP_MODE_SCREEN_OFF: + /* Reached End of button functionality for this mode. No more further toggling allowed. */ + /* Update current mode i.e save current values from RAM to EEPROM for ULP Mode. */ + /* Toggle operating mode. */ + operating_mode = ULP_MODE_SCREEN_OFF; + + update_state(operating_mode); + break; + + case LP_MODE_SCREEN_ON: + + /* Update current mode i.e save current values from RAM to EEPROM for LP Mode. */ + update_state(operating_mode); + + /* Toggle operating mode. */ + operating_mode = ULP_MODE_SCREEN_OFF; + + /* Load settings for new mode from EEPROM to RAM */ + load_state(operating_mode); + + /* Configure sensor operation for updated mode. */ + configure_sensor_mode(operating_mode); + break; + + case CONT_MODE_BREATH: + + /* Update current mode i.e save current values from RAM to EEPROM for CONT Mode. */ + update_state(operating_mode); + + /* Toggle operating mode. */ + operating_mode = LP_MODE_SCREEN_ON; + + /* Load settings for new mode from EEPROM to RAM */ + load_state(operating_mode); + + /* Configure sensor operation for updated mode. */ + configure_sensor_mode(operating_mode); + break; + + default: + break; + + } + button_C_intr = false; + } +} + +/** + * @brief Button click A Handler + * Toggle operation: ULP -> LP -> CONT(Breath Mode) + * + */ +void ICACHE_RAM_ATTR button_press_A(void) +{ + button_A_intr = true; +} + +/** + * @brief Button click C Handler + * Toggle operation: CONT(Breath Mode) -> LP -> ULP + * + */ +void ICACHE_RAM_ATTR button_press_C(void) +{ + button_C_intr = true; +} + +/** + * @brief Configuration of bme680 and bsec library can be done using this function. + * @param operating_mode[in] Mode of sensor operation. Can be chosen from the list below. + * -ULP_MODE_SCREEN_OFF + * -LP_MODE_SCREEN_ON + * -CONT_MODE_BREATH + */ +void configure_sensor_mode(OPERATING_MODES operating_mode) +{ +#ifdef DEBUG_MODE + Serial.print("\nConfiguring sensor mode: "); +#endif + /* Initialize BME68X sensor */ + iaqSensor.begin(BME68X_I2C_ADDR_LOW, Wire); + + // Set config + iaqSensor.setConfig(bsec_config_iaq); + + switch (operating_mode) + { + case ULP_MODE_SCREEN_OFF: +#ifdef DEBUG_MODE + Serial.print("ULP Mode"); +#endif + iaqSensor.setState(bsec_state_ulp); + iaqSensor.updateSubscription(sensorList, 5, BSEC_SAMPLE_RATE_LP); + iaqSensor.updateSubscription(sensorIAQ, 2, BSEC_SAMPLE_RATE_ULP); + break; + + case LP_MODE_SCREEN_ON: +#ifdef DEBUG_MODE + Serial.print("LP Mode"); +#endif + iaqSensor.setState(bsec_state_lp); + iaqSensor.updateSubscription(sensorList, 5, BSEC_SAMPLE_RATE_CONT); + iaqSensor.updateSubscription(sensorIAQ, 2, BSEC_SAMPLE_RATE_LP); + break; + + case CONT_MODE_BREATH: +#ifdef DEBUG_MODE + Serial.print("CONT Mode"); +#endif + iaqSensor.setState(bsec_state_cont); + iaqSensor.updateSubscription(sensorList, 5, BSEC_SAMPLE_RATE_CONT); + iaqSensor.updateSubscription(sensorIAQ, 2, BSEC_SAMPLE_RATE_CONT); + break; + + default: + break; + + } +#ifdef DEBUG_MODE + Serial.print("\nUpdate subscription: "); + /* Report Sensor status on serial terminal */ + report_status(); + +#endif +} + +/** + * @brief Initializes EEPROM memory space and loads previously saved values + * @return void + */ +void eeprom_initialize(void) +{ + bsec_state_ulp[BSEC_MAX_STATE_BLOB_SIZE-1] = 10; + /* Initialize EEPROM Memory segment of ESP8266 */ + EEPROM.begin(EEPROM_TOTAL_ALLOCATED_BYTES); // 1st address for the length + + if ((EEPROM.read(BSEC_EEPROM_ULP_IDENTIFIER) == BSEC_MAX_STATE_BLOB_SIZE) || + (EEPROM.read(BSEC_EEPROM_LP_IDENTIFIER) == BSEC_MAX_STATE_BLOB_SIZE) + || + (EEPROM.read(BSEC_EEPROM_CONT_IDENTIFIER) == BSEC_MAX_STATE_BLOB_SIZE)) + { + Serial.print("\nSaved data found, loading previous EEPROM values "); + for (uint16_t array_index = 0; array_index < BSEC_MAX_STATE_BLOB_SIZE; array_index++) + { + bsec_state_ulp[array_index] = EEPROM.read(BSEC_EEPROM_ULP_REGION_START + array_index); + bsec_state_lp[array_index] = EEPROM.read(BSEC_EEPROM_LP_REGION_START + array_index); + bsec_state_cont[array_index] = EEPROM.read(BSEC_EEPROM_CONT_REGION_START + array_index); + } + } + else + { + Serial.print("\nFirst time flash. Erasing complete EEPROM"); + for (uint16_t i = 0; i < EEPROM_TOTAL_ALLOCATED_BYTES; i++) + EEPROM.write(i, 0); + + EEPROM.commit(); + + } +} + +/** + * @brief Save the values from RAM to appropriate memory location in EEPROM based on operating_mode + * @param operating_mode Defines the start EEPROM address for writing to EEPROM + * -ULP_MODE_SCREEN_OFF + * -LP_MODE_SCREEN_ON + * -CONT_MODE_BREATH + */ +void update_state(OPERATING_MODES operating_mode) +{ +#ifdef DEBUG_MODE + Serial.print("\n Writing to EEPROM: "); +#endif + switch (operating_mode) + { + case ULP_MODE_SCREEN_OFF: +#ifdef DEBUG_MODE + Serial.print("ULP_MODE_SCREEN_OFF \n"); +#endif + for (uint16_t array_index = 0; array_index < BSEC_MAX_STATE_BLOB_SIZE; array_index++) + { + EEPROM.write(BSEC_EEPROM_ULP_REGION_START + array_index, bsec_state_ulp[array_index]); + +#ifdef DEBUG_MODE + Serial.print(EEPROM.read(BSEC_EEPROM_ULP_REGION_START + array_index)); + Serial.print(" "); + +#endif + } + EEPROM.write(BSEC_EEPROM_ULP_IDENTIFIER, BSEC_MAX_STATE_BLOB_SIZE); + break; + + case LP_MODE_SCREEN_ON: +#ifdef DEBUG_MODE + Serial.print("LP_MODE_SCREEN_ON \n"); +#endif + for (uint16_t array_index = 0; array_index < BSEC_MAX_STATE_BLOB_SIZE; array_index++) + { + EEPROM.write(BSEC_EEPROM_LP_REGION_START + array_index, bsec_state_lp[array_index]); + +#ifdef DEBUG_MODE + Serial.print(EEPROM.read(BSEC_EEPROM_LP_REGION_START + array_index)); + Serial.print(" "); +#endif + } + EEPROM.write(BSEC_EEPROM_LP_IDENTIFIER, BSEC_MAX_STATE_BLOB_SIZE); + + break; + + case CONT_MODE_BREATH: +#ifdef DEBUG_MODE + Serial.print("CONT_MODE_BREATH \n"); +#endif + for (uint16_t array_index = 0; array_index < EEPROM_BYTES_PER_REGION; array_index++) + { + EEPROM.write(BSEC_EEPROM_CONT_REGION_START + array_index, bsec_state_cont[array_index]); + +#ifdef DEBUG_MODE + Serial.print(EEPROM.read(BSEC_EEPROM_CONT_REGION_START + array_index)); + Serial.print(" "); +#endif + } + EEPROM.write(BSEC_EEPROM_CONT_IDENTIFIER, BSEC_MAX_STATE_BLOB_SIZE); + break; + + default: + break; + } + EEPROM.commit(); +} + +/** + * @brief Load the EEPROM values into appropriate RAM containers based on + * operating_mode + * @param operating_mode Defines the start EEPROM address for reading from EEPROM + * -ULP_MODE_SCREEN_OFF + * -LP_MODE_SCREEN_ON + * -CONT_MODE_BREATH + */ +void load_state(OPERATING_MODES operating_mode) +{ +#ifdef DEBUG_MODE + Serial.print("\n Loading from EEPROM: "); +#endif + switch (operating_mode) + { + case ULP_MODE_SCREEN_OFF: +#ifdef DEBUG_MODE + Serial.print("ULP_MODE_SCREEN_OFF \n"); +#endif + for (uint16_t array_index = 0; array_index < EEPROM_BYTES_PER_REGION; array_index++) + { + bsec_state_ulp[array_index] = EEPROM.read(BSEC_EEPROM_ULP_REGION_START + array_index); + +#ifdef DEBUG_MODE + Serial.print(bsec_state_ulp[array_index]); + Serial.print(" "); +#endif + } + break; + + case LP_MODE_SCREEN_ON: +#ifdef DEBUG_MODE + Serial.print("LP_MODE_SCREEN_ON \n"); +#endif + for (uint16_t array_index = 0; array_index < EEPROM_BYTES_PER_REGION; array_index++) + { + bsec_state_lp[array_index] = EEPROM.read(BSEC_EEPROM_LP_REGION_START + array_index); + +#ifdef DEBUG_MODE + Serial.print(bsec_state_lp[array_index]); + Serial.print(" "); +#endif + } + break; + + case CONT_MODE_BREATH: +#ifdef DEBUG_MODE + Serial.print("CONT_MODE_BREATH \n"); +#endif + for (uint16_t array_index = 0; array_index < EEPROM_BYTES_PER_REGION; array_index++) + { + bsec_state_cont[array_index] = EEPROM.read(BSEC_EEPROM_CONT_REGION_START + array_index); + +#ifdef DEBUG_MODE + Serial.print(bsec_state_cont[array_index]); + Serial.print(" "); +#endif + } + break; + + default: + break; + } +} + +/** + * @brief Report the current status of bme680 and bsec library. + */ +void report_status(void) +{ + /* Report Sensor status on serial terminal */ + if (iaqSensor.bsecStatus != BSEC_OK) { + if (iaqSensor.bsecStatus < BSEC_OK) { + output = "\nBSEC error code : " + String(iaqSensor.bsecStatus); + Serial.println(output); + for (;;) + err_leds(); /* Halt in case of failure */ + } else { + output = "\nBSEC warning code : " + String(iaqSensor.bsecStatus); + Serial.println(output); + } + } + + if (iaqSensor.bme68xStatus != BME68X_OK) { + if (iaqSensor.bme68xStatus < BME68X_OK) { + output = "\nBME68X error code : " + String(iaqSensor.bme68xStatus); + Serial.println(output); + for (;;) + err_leds(); /* Halt in case of failure */ + } else { + output = "\nBME68X warning code : " + String(iaqSensor.bme68xStatus); + Serial.println(output); + } + } +} + +void err_leds(void) +{ + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, HIGH); + delay(100); + digitalWrite(LED_BUILTIN, LOW); + delay(100); +} From 95422f742a279e57b16026839ef445af6f89d47a Mon Sep 17 00:00:00 2001 From: Kevin Goveas Date: Thu, 9 Mar 2023 08:28:14 +0100 Subject: [PATCH 3/5] Fixed a bug with incorrect include paths --- src/bsec.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bsec.h b/src/bsec.h index 369eae0..dcf5ba1 100644 --- a/src/bsec.h +++ b/src/bsec.h @@ -43,9 +43,9 @@ #include "Arduino.h" #include "Wire.h" #include "SPI.h" -#include "bsec_datatypes.h" -#include "bsec_interface.h" -#include "bme68x.h" +#include "inc/bsec_datatypes.h" +#include "inc/bsec_interface.h" +#include "bme68x/bme68x.h" #define BME68X_ERROR INT8_C(-1) #define BME68X_WARNING INT8_C(1) From cac7b752838157f7571cc57a9c69ced5f6b9e364 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 12 Mar 2023 17:36:35 +0100 Subject: [PATCH 4/5] Update library.properties corrected release version number --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index 37427d0..cc79f3f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=BSEC Software Library -version=1.7.1492 +version=1.8.1492 author=Bosch Sensortec maintainer=Bosch Sensortec sentence=Bosch Sensortec Environmental Cluster (BSEC) Software library From 15acc0e0c1f57fc2a83ebf1261c11cda90c80736 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 12 Mar 2023 17:38:29 +0100 Subject: [PATCH 5/5] Update library.json corrected release version number --- library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.json b/library.json index 38195cc..02a9cb6 100644 --- a/library.json +++ b/library.json @@ -6,7 +6,7 @@ "type": "git", "url": "https://github.com/BoschSensortec/BSEC-Arduino-library" }, - "version": "1.7.1492", + "version": v1.8.1492", "authors": { "name": "Bosch Sensortec", "email": "contact@bosch-sensortec.com"