Framework code
This commit is contained in:
parent
23f432712b
commit
271c7de255
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,4 +1,3 @@
|
||||
.pioenvs
|
||||
.piolibdeps
|
||||
.pio
|
||||
*.kicad_pcb-bak
|
||||
*.sublime-workspace
|
@ -3,7 +3,8 @@
|
||||
[
|
||||
{
|
||||
"path": ".",
|
||||
"file_exclude_patterns": ["*.sublime-project"]
|
||||
"file_exclude_patterns": ["*.sublime-project"],
|
||||
"folder_exclude_patterns": [".pioenvs"]
|
||||
}
|
||||
]
|
||||
}
|
20
README.md
Normal file
20
README.md
Normal file
@ -0,0 +1,20 @@
|
||||
# DeskControl
|
||||
This project is for motorizing a (very specific) manually controlled standing desk. I wanted to call it AutoDesk, but I don't like getting sued :-)
|
||||
|
||||
Contained in this repository are the hardware designs and software source code. I doubt it's useful to anyone but me, but it may contain some interesting bits of code.
|
||||
|
||||
All contents are released under the [Unlicense](https://unlicense.org/). Help yourself!
|
||||
|
||||
## Building and uploading
|
||||
This project uses [PlatformIO](https://platformio.org/). For reference, here are some of the common commands:
|
||||
|
||||
|
||||
|
||||
_Building_
|
||||
```pio run```
|
||||
|
||||
_Building and uploading_
|
||||
```pio run -t upload```
|
||||
|
||||
_Installing the libraries (without building)_
|
||||
```pio lib install```
|
24
UNLICENSE
Normal file
24
UNLICENSE
Normal file
@ -0,0 +1,24 @@
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
BIN
doc/DeskControl UI mockup - LCD version.psd
Normal file
BIN
doc/DeskControl UI mockup - LCD version.psd
Normal file
Binary file not shown.
BIN
mount/Mount.factory
Normal file
BIN
mount/Mount.factory
Normal file
Binary file not shown.
@ -21,3 +21,6 @@ board_build.f_cpu = 8000000L
|
||||
|
||||
lib_deps =
|
||||
Bounce2
|
||||
Adafruit GFX Library
|
||||
Adafruit ST7735 and ST7789 Library
|
||||
Adafruit_VL53L0X
|
14
src/include/display.h
Normal file
14
src/include/display.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef __ports
|
||||
#define __ports
|
||||
|
||||
// Settings for an ST7789 based 240x240 pixel LCD.
|
||||
#define DISPLAY_WIDTH 240
|
||||
#define DISPLAY_HEIGHT 240
|
||||
#define DISPLAY_ROTATION 2
|
||||
|
||||
// Control pins. Data is sent over the hardware SPI pins.
|
||||
#define DISPLAY_PORT_CS 10
|
||||
#define DISPLAY_PORT_RST 9
|
||||
#define DISPLAY_PORT_DC 8
|
||||
|
||||
#endif
|
6
src/include/heightsensor.h
Normal file
6
src/include/heightsensor.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef __heightsensor
|
||||
#define __heightsensor
|
||||
|
||||
#define HEIGHTSENSOR_I2C_ADDRESS 0x29
|
||||
|
||||
#endif
|
7
src/lib/menu.cpp
Normal file
7
src/lib/menu.cpp
Normal file
@ -0,0 +1,7 @@
|
||||
#include "./menu.h"
|
||||
#include <Fonts/FreeSansBold18pt7b.h>
|
||||
|
||||
void Menu::init()
|
||||
{
|
||||
this->display->setFont(&FreeSansBold18pt7b);
|
||||
}
|
25
src/lib/menu.h
Normal file
25
src/lib/menu.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef __menu
|
||||
#define __menu
|
||||
|
||||
#include <Adafruit_GFX.h>
|
||||
#include "include/display.h"
|
||||
|
||||
#if DISPLAY_WIDTH != 240 || DISPLAY_HEIGHT != 240
|
||||
#error "The menu assumes a display pixel size of 240x240"
|
||||
#endif
|
||||
|
||||
class Menu
|
||||
{
|
||||
private:
|
||||
Adafruit_GFX* display;
|
||||
|
||||
public:
|
||||
Menu(Adafruit_GFX* display)
|
||||
{
|
||||
this->display = display;
|
||||
}
|
||||
|
||||
void init();
|
||||
};
|
||||
|
||||
#endif
|
56
src/lib/vl53l0x.cpp
Normal file
56
src/lib/vl53l0x.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#include "VL53L0X.h"
|
||||
|
||||
bool VL53L0X::init(uint8_t address)
|
||||
{
|
||||
device.I2cDevAddr = address;
|
||||
device.comms_type = 1;
|
||||
device.comms_speed_khz = 400;
|
||||
device.i2c = &Wire;
|
||||
|
||||
if (!VL53L0X_DataInit(&device))
|
||||
return false;
|
||||
|
||||
//if (!VL53L0X_GetDeviceInfo(&device, &deviceInfo))
|
||||
// return false;
|
||||
|
||||
if (!VL53L0X_StaticInit(&device))
|
||||
return false;
|
||||
|
||||
|
||||
uint32_t refSpadCount;
|
||||
uint8_t isApertureSpads;
|
||||
|
||||
if (!VL53L0X_PerformRefSpadManagement(&device, &refSpadCount, &isApertureSpads))
|
||||
return false;
|
||||
|
||||
|
||||
// TODO expose as API to be run before changing desk positions
|
||||
uint8_t vhvSettings;
|
||||
uint8_t phaseCal;
|
||||
|
||||
if (!VL53L0X_PerformRefCalibration(&device, &vhvSettings, &phaseCal))
|
||||
return false;
|
||||
|
||||
if (!VL53L0X_SetDeviceMode(&device, VL53L0X_DEVICEMODE_SINGLE_RANGING))
|
||||
return false;
|
||||
|
||||
if (!VL53L0X_SetLimitCheckEnable(&device, VL53L0X_CHECKENABLE_SIGMA_FINAL_RANGE, 1))
|
||||
return false;
|
||||
|
||||
if (!VL53L0X_SetLimitCheckEnable(&device, VL53L0X_CHECKENABLE_SIGNAL_RATE_FINAL_RANGE, 1))
|
||||
return false;
|
||||
|
||||
if (!VL53L0X_SetLimitCheckEnable(&device, VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, 1))
|
||||
return false;
|
||||
|
||||
if (!VL53L0X_SetLimitCheckValue(&device, VL53L0X_CHECKENABLE_RANGE_IGNORE_THRESHOLD, (FixPoint1616_t)( 1.5 * 0.023 * 65536)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool VL53L0X::getSingleRangingMeasurement(VL53L0X_RangingMeasurementData_t *data)
|
||||
{
|
||||
return VL53L0X_PerformSingleRangingMeasurement(&device, data);
|
||||
}
|
37
src/lib/vl53l0x.h
Normal file
37
src/lib/vl53l0x.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
|
||||
The Adafruit VL53L0X library is included because it's an easy way to get
|
||||
access to the VL53L0X API headers. I will not be using the Adafruit library
|
||||
however because it lacks a way to set the timing budget, which I found to be
|
||||
very much required for accurate results.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef __vl53l0x
|
||||
#define __vl53l0x
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Wire.h"
|
||||
#include "vl53l0x_api.h"
|
||||
|
||||
|
||||
// TODO if begin fails, return a struct with the step and API status code
|
||||
|
||||
#define VL53L0X_BEGIN_SUCCESS 0
|
||||
#define VL53L0X_BEGIN_SUCCESS 0
|
||||
|
||||
|
||||
class VL53L0X
|
||||
{
|
||||
public:
|
||||
bool init(uint8_t address);
|
||||
|
||||
// TODO set timing budget
|
||||
|
||||
bool getSingleRangingMeasurement(VL53L0X_RangingMeasurementData_t* data);
|
||||
|
||||
private:
|
||||
VL53L0X_Dev_t device;
|
||||
};
|
||||
|
||||
#endif
|
47
src/main.cpp
47
src/main.cpp
@ -1,4 +1,47 @@
|
||||
int main()
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_ST7789.h>
|
||||
|
||||
#include "./include/display.h"
|
||||
#include "./include/heightsensor.h"
|
||||
#include "./lib/menu.h"
|
||||
#include "./lib/vl53l0x.h"
|
||||
|
||||
|
||||
Adafruit_ST7789 display = Adafruit_ST7789(DISPLAY_PORT_CS, DISPLAY_PORT_DC, DISPLAY_PORT_RST);
|
||||
VL53L0X heightSensor = VL53L0X();
|
||||
|
||||
Menu menu = Menu(&display);
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
return 0;
|
||||
display.init(DISPLAY_WIDTH, DISPLAY_HEIGHT, SPI_MODE3);
|
||||
display.setRotation(DISPLAY_ROTATION);
|
||||
display.fillScreen(ST77XX_BLACK);
|
||||
|
||||
menu.init();
|
||||
|
||||
// TODO draw "initializing" text
|
||||
|
||||
Wire.begin();
|
||||
heightSensor.init(HEIGHTSENSOR_I2C_ADDRESS);
|
||||
|
||||
/*
|
||||
Wire.begin();
|
||||
if (!heightSensor.begin())
|
||||
{
|
||||
// TODO draw "height sensor error" text
|
||||
|
||||
while(1);
|
||||
}
|
||||
|
||||
display.fillScreen(ST77XX_BLACK);
|
||||
*/
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// TODO
|
||||
}
|
@ -1 +0,0 @@
|
||||
& platformio run --target upload
|
Loading…
Reference in New Issue
Block a user