Skip to content

Commit c7b5c30

Browse files
committed
Add power down and display to system test sketch
1 parent c505ef7 commit c7b5c30

File tree

4 files changed

+96
-4
lines changed

4 files changed

+96
-4
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//If we have a power button tap, or if the display is not yet started (no I2C!)
2+
//then don't display a shutdown screen
3+
void powerDown(bool displayInfo)
4+
{
5+
//Disable SD card use
6+
//endSD(false, false);
7+
8+
//Prevent other tasks from logging, even if access to the microSD card was denied
9+
online.logging = false;
10+
11+
if (displayInfo == true)
12+
{
13+
//displayShutdown();
14+
//delay(2000);
15+
}
16+
17+
pinMode(pin_powerSenseAndControl, OUTPUT);
18+
digitalWrite(pin_powerSenseAndControl, LOW);
19+
20+
pinMode(pin_powerFastOff, OUTPUT);
21+
digitalWrite(pin_powerFastOff, LOW);
22+
23+
while (1)
24+
delay(1);
25+
}

Firmware/Test Sketches/System_Check/Display.ino

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,56 @@ void beginDisplay()
2525
}
2626
}
2727
}
28+
29+
//Attempt to send to display regardless of its online status
30+
//The I2C bus may allow it even if bus is misbehaving
31+
void displayHelloWorld()
32+
{
33+
//if (online.display == true)
34+
//{
35+
oled.erase();
36+
37+
uint8_t fontHeight = 15;
38+
uint8_t yPos = oled.getHeight() / 2 - fontHeight;
39+
40+
printTextCenter("Accel", yPos, QW_FONT_8X16, 1, false); //text, y, font type, kerning, inverted
41+
printTextCenter("Failed", yPos + fontHeight, QW_FONT_8X16, 1, false); //text, y, font type, kerning, inverted
42+
43+
oled.display();
44+
45+
// delay(displayTime);
46+
//}
47+
}
48+
49+
//Given text, and location, print text center of the screen
50+
void printTextCenter(const char *text, uint8_t yPos, QwiicFont & fontType, uint8_t kerning, bool highlight) //text, y, font type, kearning, inverted
51+
{
52+
oled.setFont(fontType);
53+
oled.setDrawMode(grROPXOR);
54+
55+
uint8_t fontWidth = fontType.width;
56+
if (fontWidth == 8) fontWidth = 7; //8x16, but widest character is only 7 pixels.
57+
58+
uint8_t xStart = (oled.getWidth() / 2) - ((strlen(text) * (fontWidth + kerning)) / 2) + 1;
59+
60+
uint8_t xPos = xStart;
61+
for (int x = 0 ; x < strlen(text) ; x++)
62+
{
63+
oled.setCursor(xPos, yPos);
64+
oled.print(text[x]);
65+
xPos += fontWidth + kerning;
66+
}
67+
68+
if (highlight) //Draw a box, inverted over text
69+
{
70+
uint8_t textPixelWidth = strlen(text) * (fontWidth + kerning);
71+
72+
//Error check
73+
int xBoxStart = xStart - 5;
74+
if (xBoxStart < 0) xBoxStart = 0;
75+
int xBoxEnd = textPixelWidth + 9;
76+
if (xBoxEnd > oled.getWidth() - 1) xBoxEnd = oled.getWidth() - 1;
77+
78+
oled.rectangleFill(xBoxStart, yPos, xBoxEnd, 12, 1); //x, y, width, height, color
79+
}
80+
}

Firmware/Test Sketches/System_Check/System_Check.ino

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ float battChangeRate = 0.0;
147147
//External Display
148148
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
149149
#include <SparkFun_Qwiic_OLED.h> //http://librarymanager/All#SparkFun_Qwiic_Graphic_OLED
150+
151+
#include <res/qw_fnt_5x7.h>
152+
#include <res/qw_fnt_8x16.h>
153+
#include <res/qw_fnt_largenum.h>
150154
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
151155

152156
//microSD Interface
@@ -175,7 +179,6 @@ uint32_t sdFreeSpaceMB = 0;
175179
uint32_t sdUsedSpaceMB = 0;
176180
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
177181

178-
179182
//Hardware serial and BT buffers
180183
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
181184
HardwareSerial serialGNSS(2); //TX on 17, RX on 16
@@ -190,8 +193,6 @@ unsigned long splashStart = 0; //Controls how long the splash is displayed for.
190193

191194
char platformPrefix[40] = "Surveyor"; //Sets the prefix for broadcast names
192195
bool zedUartPassed = false; //Goes true during testing if ESP can communicate with ZED over UART
193-
194-
bool i2cBorked = false;
195196
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
196197

197198
void setup()
@@ -244,7 +245,10 @@ void setup()
244245
Wire.beginTransmission(0x15); //Dummy address
245246
int endValue = Wire.endTransmission();
246247
Serial.printf("Response time: %d endValue: %d\n\r", millis() - startTime, endValue);
247-
if(endValue == 2) online.i2c = true;
248+
if(endValue == 2)
249+
online.i2c = true;
250+
else if (endValue == 5)
251+
Serial.println("It appears something is shorting the I2C lines.");
248252

249253
beginBoard(); //Determine what hardware platform we are running on and check on button
250254

@@ -259,6 +263,9 @@ void setup()
259263

260264
beginSD(); //Test if SD is present
261265

266+
beginDisplay(); //Start display first to be able to display any errors
267+
displayHelloWorld(); //Display something, ignore I2C bus status
268+
262269
menuSystem();
263270
}
264271

Firmware/Test Sketches/System_Check/menuSystem.ino

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ void menuSystem()
143143
Serial.println(F("S) Verbose scan of I2C"));
144144
Serial.println(F("t) Toggle pin"));
145145
Serial.println(F("r) Reset"));
146+
Serial.println(F("p) Power Down"));
146147

147148
byte incoming = getByteChoice(menuTimeout); //Timeout after x seconds
148149

@@ -259,6 +260,12 @@ void menuSystem()
259260
ESP.restart();
260261
}
261262
}
263+
else if (incoming == 'p')
264+
{
265+
Serial.println("Power down");
266+
267+
powerDown(false); //No display
268+
}
262269
else if (incoming == STATUS_GETBYTE_TIMEOUT)
263270
{
264271
//break;

0 commit comments

Comments
 (0)