-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathArduino_MKRIoTCarrier.cpp
115 lines (90 loc) · 3.23 KB
/
Arduino_MKRIoTCarrier.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
This file is part of the Arduino_MKRIoTCarrier library.
Copyright (c) 2020 Arduino SA.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <Arduino_MKRIoTCarrier.h>
//Touch pads values for using the case or just directly on the board
//Define on the sketch to use it
bool CARRIER_CASE = false;
MKRIoTCarrier::MKRIoTCarrier() {
}
int MKRIoTCarrier::_revision = -1;
int MKRIoTCarrier::begin() {
pinMode(AREF_PIN,INPUT_PULLUP);
if (digitalRead(AREF_PIN) == LOW) {
MKRIoTCarrier::_revision = BOARD_REVISION_2;
} else {
MKRIoTCarrier::_revision = BOARD_REVISION_1;
}
if (!CARRIER_CASE) {
Buttons.updateConfig(200);
}
//Display
if (_revision == BOARD_REVISION_2){
Adafruit_ST7789 _display = Adafruit_ST7789(mkr_iot_carrier_rev2::TFT_CS, mkr_iot_carrier_rev2::TFT_DC, -1);
display = _display;
} else {
Adafruit_ST7789 _display = Adafruit_ST7789(mkr_iot_carrier_rev1::TFT_CS, mkr_iot_carrier_rev1::TFT_DC, -1);
display = _display;
}
display.init(240, 240);//.begin(true); // Initialize ST7789 screen
pinMode(3,INPUT_PULLUP); // RESET fix
//Default rotation to align it with the carrier
display.setRotation(2);
display.fillScreen(ST77XX_BLACK);
Buttons.begin(); //init buttons
//init LEDs
leds.begin();
leds.clear();
leds.show();
//PMIC init
PMIC.begin();
PMIC.enableBoostMode();
Relay1.begin();
Relay2.begin();
//Sensors
uint8_t sensorsOK = !Light.begin() << 0 | !Pressure.begin() << 1 | !IMUmodule.begin() << 2 | !Env.begin() << 3 |
(_revision == BOARD_REVISION_2 ? !AirQuality.begin() << 4 : 0);
//If some of the sensors are not connected
if(sensorsOK > 0 ){
Serial.println("Error detected!");
if(sensorsOK & 0b0001){
Serial.println("Ambient light sensor is not connected!");
}
if(sensorsOK & 0b0010){
Serial.println("Pressure sensor is not connected!");
}
if(sensorsOK & 0b0100){
Serial.println("IMU is not connected");
}
if(sensorsOK & 0b1000){
Serial.println("Environmental sensor is not connected!");
}
if(sensorsOK & 0b10000){
Serial.println("Air quality sensor is not connected!");
}
return false;
}
if(!SD.begin(SD_CS)) {
Serial.println("Sd card not detected");
}
if (_revision == BOARD_REVISION_2){
pinMode(TFT_BACKLIGHT, OUTPUT);
digitalWrite(TFT_BACKLIGHT, HIGH);
}
return true;
}
int MKRIoTCarrier::getBoardRevision() {
return MKRIoTCarrier::_revision;
}