Implemented screen timeout and button detection
This commit is contained in:
parent
b1600ab1d6
commit
df61b1f24d
@ -1,47 +0,0 @@
|
||||
|
||||
# Error codes reference
|
||||
During startup a number of error codes may be presented. This document serves as a reference for tracing the problem.
|
||||
|
||||
### height sensor
|
||||
Errors are logged as "code @ position". Code is the status code as returned by the VL53L0X API, and position determines which API call during initialization failed. Test
|
||||
|
||||
|
||||
| Code | Constant | Description |
|
||||
|--|--|--|
|
||||
| -1 | VL53L0X_ERROR_CALIBRATION_WARNING | Warning invalid calibration data may be in used VL53L0X_InitData(), VL53L0X_GetOffsetCalibrationData, VL53L0X_SetOffsetCalibrationData |
|
||||
| -2 | VL53L0X_ERROR_MIN_CLIPPED | Warning parameter passed was clipped to min before to be applied |
|
||||
| -3 | VL53L0X_ERROR_UNDEFINED | Unqualified error |
|
||||
| -4 | VL53L0X_ERROR_INVALID_PARAMS | Parameter passed is invalid or out of range |
|
||||
| -5 | VL53L0X_ERROR_NOT_SUPPORTED | Function is not supported in current mode or configuration |
|
||||
| -6 | VL53L0X_ERROR_RANGE_ERROR | Device report a ranging error interrupt status |
|
||||
| -7 | VL53L0X_ERROR_TIME_OUT | Aborted due to time out |
|
||||
| -8 | VL53L0X_ERROR_MODE_NOT_SUPPORTED | Asked mode is not supported by the device |
|
||||
| -9 | VL53L0X_ERROR_BUFFER_TOO_SMALL | ... |
|
||||
| -10 | VL53L0X_ERROR_GPIO_NOT_EXISTING | User tried to setup a non-existing GPIO pin |
|
||||
| -11 | VL53L0X_ERROR_GPIO_FUNCTIONALITY_NOT_SUPPORTED | unsupported GPIO functionality |
|
||||
| -12 | VL53L0X_ERROR_INTERRUPT_NOT_CLEARED | Error during interrupt clear |
|
||||
| -20 | VL53L0X_ERROR_CONTROL_INTERFACE | error reported from IO functions |
|
||||
| -30 | VL53L0X_ERROR_INVALID_COMMAND | The command is not allowed in the current device state (power down) |
|
||||
| -40 | VL53L0X_ERROR_DIVISION_BY_ZERO | In the function a division by zero occurs |
|
||||
| -50 | VL53L0X_ERROR_REF_SPAD_INIT | Error during reference SPAD initialization |
|
||||
| -99 | VL53L0X_ERROR_NOT_IMPLEMENTED |
|
||||
|
||||
<br>
|
||||
|
||||
| Position | Description |
|
||||
|--|--|
|
||||
| 1 | VL53L0X_DataInit |
|
||||
| 2 | VL53L0X_SetDeviceAddress |
|
||||
| 3 | VL53L0X_GetDeviceInfo |
|
||||
| 4 | VL53L0X_StaticInit |
|
||||
| 5 | VL53L0X_PerformRefSpadManagement |
|
||||
| 6 | VL53L0X_PerformRefCalibration |
|
||||
| 7 | VL53L0X_SetDeviceMode |
|
||||
| 8 | VL53L0X_SetLimitCheckEnable(VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE) |
|
||||
| 9 | VL53L0X_SetLimitCheckEnable(VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE) |
|
||||
| 10 | VL53L0X_SetLimitCheckEnable(VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD) |
|
||||
| 11 | VL53L0X_SetLimitCheckValue(VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD) |
|
||||
|
||||
|
||||
### timing budget
|
||||
Errors are logged as an VL53L0X API code. See the table above for reference.
|
@ -17,13 +17,11 @@ lib_deps =
|
||||
Bounce2
|
||||
Adafruit GFX Library
|
||||
Adafruit ST7735 and ST7789 Library
|
||||
Adafruit_VL53L0X
|
||||
|
||||
|
||||
[env:uno]
|
||||
platform = atmelavr
|
||||
board = atmega328p
|
||||
board_build.f_cpu = 16000000L
|
||||
board = uno
|
||||
framework = arduino
|
||||
|
||||
upload_port = COM3
|
||||
|
@ -27,6 +27,16 @@
|
||||
class Config
|
||||
{
|
||||
public:
|
||||
/*
|
||||
|
||||
Buttons
|
||||
|
||||
*/
|
||||
static const uint8_t ButtonPortUp = 3;
|
||||
static const uint8_t ButtonPortMenu = 5;
|
||||
static const uint8_t ButtonPortDown = 6;
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Display
|
||||
@ -47,6 +57,9 @@ class Config
|
||||
static const uint8_t DisplayPortBL = 7;
|
||||
|
||||
|
||||
static const uint16_t DisplayIdleTime = 10000;
|
||||
|
||||
|
||||
/*
|
||||
Height sensor
|
||||
Settings for a VL53L0X time-of-flight sensor.
|
||||
|
@ -1,7 +1,29 @@
|
||||
#include "./screen.h"
|
||||
#include "include/config.h"
|
||||
|
||||
|
||||
Adafruit_GFX* BaseScreen::getDisplay()
|
||||
{
|
||||
return this->screenManager->getDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ScreenManager::init()
|
||||
{
|
||||
pinMode(Config::DisplayPortBL, OUTPUT);
|
||||
digitalWrite(Config::DisplayPortBL, HIGH);
|
||||
}
|
||||
|
||||
|
||||
void ScreenManager::displayOff()
|
||||
{
|
||||
digitalWrite(Config::DisplayPortBL, LOW);
|
||||
this->display->sendCommand(ST77XX_SLPIN);
|
||||
}
|
||||
|
||||
|
||||
void ScreenManager::displayOn()
|
||||
{
|
||||
this->display->sendCommand(ST77XX_SLPOUT);
|
||||
digitalWrite(Config::DisplayPortBL, HIGH);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef __screen
|
||||
#define __screen
|
||||
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_ST7789.h>
|
||||
#include "include/config.h"
|
||||
|
||||
|
||||
@ -43,11 +43,14 @@ class BaseScreen
|
||||
class ScreenManager
|
||||
{
|
||||
public:
|
||||
ScreenManager(Adafruit_GFX* display)
|
||||
ScreenManager(Adafruit_ST7789* display)
|
||||
{
|
||||
this->display = display;
|
||||
}
|
||||
|
||||
void init();
|
||||
|
||||
inline void button(Button button) { this->getCurrentScreen()->onButton(button); }
|
||||
inline void tick() { this->getCurrentScreen()->onTick(); }
|
||||
|
||||
inline BaseScreen* getCurrentScreen() { return this->currentScreen; }
|
||||
@ -66,8 +69,12 @@ class ScreenManager
|
||||
this->currentScreen->onShow();
|
||||
}
|
||||
|
||||
|
||||
void displayOff();
|
||||
void displayOn();
|
||||
|
||||
private:
|
||||
Adafruit_GFX* display;
|
||||
Adafruit_ST7789* display;
|
||||
|
||||
BaseScreen* currentScreen = nullptr;
|
||||
};
|
||||
|
@ -38,6 +38,16 @@ void HomeScreen::onShow()
|
||||
|
||||
void HomeScreen::onButton(Button button)
|
||||
{
|
||||
if (this->idle)
|
||||
{
|
||||
this->getScreenManager()->displayOn();
|
||||
this->idle = false;
|
||||
this->showTime = State.CurrentTime;
|
||||
|
||||
// TODO should preset buttons activate immediately?
|
||||
return;
|
||||
}
|
||||
|
||||
switch (button)
|
||||
{
|
||||
case Button::Up:
|
||||
@ -59,8 +69,11 @@ void HomeScreen::onButton(Button button)
|
||||
|
||||
void HomeScreen::onTick()
|
||||
{
|
||||
// TODO turn off screen after timeout
|
||||
//if (State.CurrentTime )
|
||||
if (!this->idle && State.CurrentTime - this->showTime >= Config::DisplayIdleTime)
|
||||
{
|
||||
this->getScreenManager()->displayOff();
|
||||
this->idle = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,7 +19,8 @@ class HomeScreen : public BaseScreen
|
||||
void onTick();
|
||||
|
||||
private:
|
||||
uint32_t showTime;
|
||||
uint32_t showTime = 0;
|
||||
bool idle = false;
|
||||
|
||||
void drawPreset1();
|
||||
void drawPreset2();
|
||||
|
41
src/main.cpp
41
src/main.cpp
@ -2,6 +2,7 @@
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_ST7789.h>
|
||||
#include <Bounce2.h>
|
||||
|
||||
#include "./include/config.h"
|
||||
#include "./lib/debug.h"
|
||||
@ -42,6 +43,8 @@ auto heightSensor = VL53L0X();
|
||||
|
||||
auto screenManager = ScreenManager(&display);
|
||||
|
||||
Bounce buttons[3];
|
||||
|
||||
|
||||
/*
|
||||
|
||||
@ -50,15 +53,17 @@ auto screenManager = ScreenManager(&display);
|
||||
*/
|
||||
void setup()
|
||||
{
|
||||
State.CurrentTime = millis();
|
||||
DebugInit();
|
||||
|
||||
pinMode(Config::DisplayPortBL, OUTPUT);
|
||||
digitalWrite(Config::DisplayPortBL, HIGH);
|
||||
buttons[0].attach(Config::ButtonPortUp, INPUT_PULLUP);
|
||||
buttons[1].attach(Config::ButtonPortMenu, INPUT_PULLUP);
|
||||
buttons[2].attach(Config::ButtonPortDown, INPUT_PULLUP);
|
||||
|
||||
display.init(Config::DisplayWidth, Config::DisplayHeight, SPI_MODE3);
|
||||
display.setRotation(Config::DisplayRotation);
|
||||
|
||||
screenManager.init();
|
||||
|
||||
initSequenceStart();
|
||||
|
||||
// Load settings from EEPROM
|
||||
@ -73,6 +78,8 @@ void setup()
|
||||
initSequenceEnd();
|
||||
|
||||
|
||||
State.CurrentTime = millis();
|
||||
|
||||
if (initialized)
|
||||
{
|
||||
State.CurrentHeight = currentHeight;
|
||||
@ -190,6 +197,20 @@ void loop()
|
||||
updateHeight();
|
||||
}
|
||||
|
||||
buttons[0].update();
|
||||
buttons[1].update();
|
||||
buttons[2].update();
|
||||
|
||||
|
||||
if (buttons[0].rose())
|
||||
screenManager.button(Button::Up);
|
||||
|
||||
if (buttons[1].rose())
|
||||
screenManager.button(Button::Menu);
|
||||
|
||||
if (buttons[2].rose())
|
||||
screenManager.button(Button::Down);
|
||||
|
||||
screenManager.tick();
|
||||
}
|
||||
|
||||
@ -225,20 +246,6 @@ bool heightSensorGetRange(uint16_t* measurement)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
For display sleep:
|
||||
|
||||
|
||||
delay(1000);
|
||||
display.sendCommand(ST77XX_SLPIN);
|
||||
// toggle backlight pin
|
||||
|
||||
|
||||
For motor sleep toggle slp pin
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user