diff --git a/.gitignore b/.gitignore index a974556..eb635d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -.pioenvs -.piolibdeps +.pio *.kicad_pcb-bak *.sublime-workspace \ No newline at end of file diff --git a/DeskControl.sublime-project b/DeskControl.sublime-project index b01586b..c8ddc3f 100644 --- a/DeskControl.sublime-project +++ b/DeskControl.sublime-project @@ -3,7 +3,8 @@ [ { "path": ".", - "file_exclude_patterns": ["*.sublime-project"] + "file_exclude_patterns": ["*.sublime-project"], + "folder_exclude_patterns": [".pioenvs"] } ] } \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e0416ba --- /dev/null +++ b/README.md @@ -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``` diff --git a/UNLICENSE b/UNLICENSE new file mode 100644 index 0000000..00d2e13 --- /dev/null +++ b/UNLICENSE @@ -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 \ No newline at end of file diff --git a/build.ps1 b/build.ps1 deleted file mode 100644 index c2fb43d..0000000 --- a/build.ps1 +++ /dev/null @@ -1 +0,0 @@ -& platformio run \ No newline at end of file diff --git a/doc/DeskControl UI mockup - LCD version.psd b/doc/DeskControl UI mockup - LCD version.psd new file mode 100644 index 0000000..45aac42 Binary files /dev/null and b/doc/DeskControl UI mockup - LCD version.psd differ diff --git a/mount/Mount.factory b/mount/Mount.factory new file mode 100644 index 0000000..0e69074 Binary files /dev/null and b/mount/Mount.factory differ diff --git a/platformio.ini b/platformio.ini index 9a40e91..4a39861 100644 --- a/platformio.ini +++ b/platformio.ini @@ -21,3 +21,6 @@ board_build.f_cpu = 8000000L lib_deps = Bounce2 + Adafruit GFX Library + Adafruit ST7735 and ST7789 Library + Adafruit_VL53L0X \ No newline at end of file diff --git a/src/include/display.h b/src/include/display.h new file mode 100644 index 0000000..4aeec71 --- /dev/null +++ b/src/include/display.h @@ -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 \ No newline at end of file diff --git a/src/include/heightsensor.h b/src/include/heightsensor.h new file mode 100644 index 0000000..ccc9abc --- /dev/null +++ b/src/include/heightsensor.h @@ -0,0 +1,6 @@ +#ifndef __heightsensor +#define __heightsensor + +#define HEIGHTSENSOR_I2C_ADDRESS 0x29 + +#endif \ No newline at end of file diff --git a/src/lib/menu.cpp b/src/lib/menu.cpp new file mode 100644 index 0000000..8ca49cd --- /dev/null +++ b/src/lib/menu.cpp @@ -0,0 +1,7 @@ +#include "./menu.h" +#include + +void Menu::init() +{ + this->display->setFont(&FreeSansBold18pt7b); +} \ No newline at end of file diff --git a/src/lib/menu.h b/src/lib/menu.h new file mode 100644 index 0000000..6d6e1e6 --- /dev/null +++ b/src/lib/menu.h @@ -0,0 +1,25 @@ +#ifndef __menu +#define __menu + +#include +#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 \ No newline at end of file diff --git a/src/lib/vl53l0x.cpp b/src/lib/vl53l0x.cpp new file mode 100644 index 0000000..86e3e02 --- /dev/null +++ b/src/lib/vl53l0x.cpp @@ -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); +} \ No newline at end of file diff --git a/src/lib/vl53l0x.h b/src/lib/vl53l0x.h new file mode 100644 index 0000000..4fa7a1d --- /dev/null +++ b/src/lib/vl53l0x.h @@ -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 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index b8c1e6e..6afbc7b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,47 @@ -int main() +#include +#include +#include +#include + +#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 } \ No newline at end of file diff --git a/upload.ps1 b/upload.ps1 deleted file mode 100644 index 9b3c625..0000000 --- a/upload.ps1 +++ /dev/null @@ -1 +0,0 @@ -& platformio run --target upload \ No newline at end of file