Skip to content

Commit

Permalink
Merge pull request #39 from bdring/Devt
Browse files Browse the repository at this point in the history
Devt
  • Loading branch information
bdring authored Oct 3, 2021
2 parents 830ffee + ddd1ddb commit ca68365
Show file tree
Hide file tree
Showing 59 changed files with 1,063 additions and 351 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ jobs:
uses: actions/upload-artifact@v2
with:
name: releaseZipFile
path: release
path: release
11 changes: 7 additions & 4 deletions FluidNC/Custom/oled_basic.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if 0
// Copyright (c) 2020 - Bart Dring
// Use of this source code is governed by a GPLv3 license that can be found in the LICENSE file.

Expand All @@ -16,8 +17,9 @@
Library Infor:
https://github.com/ThingPulse/esp8266-oled-ssd1306


Install to PlatformIO with this typed at the terminal
platformio lib install 562
platformio lib install 2978

Add this to your machine definition file
#define DISPLAY_CODE_FILENAME "Custom/oled_basic.cpp"
Expand All @@ -26,7 +28,7 @@
// Include the correct display library

#include "SSD1306Wire.h"
#include "../src/WebUI/WebSettings.h"
#include "../WebUI/WebSettings.h"

#ifndef OLED_ADDRESS
# define OLED_ADDRESS 0x3c
Expand Down Expand Up @@ -216,7 +218,7 @@ void displayUpdate(void* pvParameters) {
sd_get_current_filename(path);
display.drawString(63, 12, path);

int progress = sd_report_perc_complete();
int progress = sd_percent_complete();
// draw the progress bar
display.drawProgressBar(0, 45, 120, 10, progress);

Expand All @@ -240,7 +242,7 @@ void displayUpdate(void* pvParameters) {

void display_init() {
// Initialising the UI will init the display too.
log_info("Init Basic OLED SDA:" << pinName(OLED_SDA) << " SCL:" pinName(OLED_SCL));
log_info("Init Basic OLED SDA:gpio." << OLED_SDA << " SCL:gpio." OLED_SCL);
display.init();

display.flipScreenVertically();
Expand Down Expand Up @@ -269,3 +271,4 @@ void display_init() {
// core
);
}
#endif
11 changes: 11 additions & 0 deletions FluidNC/src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,14 @@ const double PARKING_RATE = 800.0; // Parking fast rate after pull
const double PARKING_PULLOUT_RATE = 250.0; // Pull-out/plunge slow feed rate in mm/min.
const double PARKING_PULLOUT_INCREMENT = 5.0; // Spindle pull-out and plunge distance in mm. Incremental distance.
// Must be positive value or equal to zero.

// INCLUDE_OLED_IO enables access to a basic OLED library. To use it you must uncomment the
// "thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays" line in platformio.ini
// You must uncomment it if you use either INCLUDE_OLED_TINY or INCLUDE_OLED_BASIC
// #define INCLUDE_OLED_IO

// INCLUDE_OLED_TINY includes a driver for a very small 64x48 OLED display
// #define INCLUDE_OLED_TINY

// INCLUDE_OLED_BASIC includes a driver for a modest sized OLED display
// #define INCLUDE_OLED_BASIC
14 changes: 7 additions & 7 deletions FluidNC/src/Configuration/JsonGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace Configuration {
void JsonGenerator::item(const char* name, bool& value) {
enter(name);
const char* val = value ? "Yes" : "No";
_encoder.begin_webui(name, _currentPath, "B", val);
_encoder.begin_webui(_currentPath, _currentPath, "B", val);
_encoder.begin_array("O");
{
_encoder.begin_object();
Expand All @@ -68,15 +68,15 @@ namespace Configuration {
enter(name);
char buf[32];
itoa(value, buf, 10);
_encoder.begin_webui(name, _currentPath, "I", buf, minValue, maxValue);
_encoder.begin_webui(_currentPath, _currentPath, "I", buf, minValue, maxValue);
_encoder.end_object();
leave();
}

void JsonGenerator::item(const char* name, float& value, float minValue, float maxValue) {
enter(name);
// WebUI does not explicitly recognize the R type, but nevertheless handles it correctly.
_encoder.begin_webui(name, _currentPath, "R", String(value, 3).c_str());
_encoder.begin_webui(_currentPath, _currentPath, "R", String(value, 3).c_str());
_encoder.end_object();
leave();
}
Expand All @@ -88,7 +88,7 @@ namespace Configuration {

void JsonGenerator::item(const char* name, String& value, int minLength, int maxLength) {
enter(name);
_encoder.begin_webui(name, _currentPath, "S", value.c_str(), minLength, maxLength);
_encoder.begin_webui(_currentPath, _currentPath, "S", value.c_str(), minLength, maxLength);
_encoder.end_object();
leave();
}
Expand All @@ -99,15 +99,15 @@ namespace Configuration {
/*
enter(name);
auto sv = value.name();
_encoder.begin_webui(name, _currentPath, "S", sv.c_str(), 0, 255);
_encoder.begin_webui(_currentPath, _currentPath, "S", sv.c_str(), 0, 255);
_encoder.end_object();
leave();
*/
}

void JsonGenerator::item(const char* name, IPAddress& value) {
enter(name);
_encoder.begin_webui(name, _currentPath, "A", value.toString().c_str());
_encoder.begin_webui(_currentPath, _currentPath, "A", value.toString().c_str());
_encoder.end_object();
leave();
}
Expand All @@ -122,7 +122,7 @@ namespace Configuration {
}
}

_encoder.begin_webui(name, _currentPath, "B", str);
_encoder.begin_webui(_currentPath, _currentPath, "B", str);
_encoder.begin_array("O");
for (; e->name; ++e) {
_encoder.begin_object();
Expand Down
4 changes: 2 additions & 2 deletions FluidNC/src/Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include "ControlPin.h"

class Control : public Configuration::Configurable {
private:
// private:
// TODO: Should we not just put this in an array so we can enumerate it easily?

public:
ControlPin _safetyDoor;
ControlPin _reset;
ControlPin _feedHold;
Expand Down
249 changes: 249 additions & 0 deletions FluidNC/src/Custom/oled_basic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
// Copyright (c) 2020 - Bart Dring
// Use of this source code is governed by a GPLv3 license that can be found in the LICENSE file.

/*
OLED display code.
It is designed to be used with a machine that has no easily accessible serial connection
It shows basic status and connection information.
When in alarm mode it will show the current Wifi/BT paramaters and status
Most machines will start in alarm mode (needs homing)
If the machine is running a job from SD it will show the progress
In other modes it will show state and 3 axis DROs
Thats All!
*/
#include "../Config.h"

#ifdef INCLUDE_OLED_BASIC
# include "oled_io.h"
# include "../Main.h" // display_init()

# include "../Machine/MachineConfig.h"
# include "WiFi.h"
# include "../WebUI/WebSettings.h"
# include "../SettingsDefinitions.h"
# include "../Report.h"
# include "../Machine/Axes.h"
# include "../Uart.h"

static TaskHandle_t oledUpdateTaskHandle = 0;

// This displays the status of the ESP32 Radios...BT, WiFi, etc
static void oledRadioInfo() {
String radio_addr = "";
String radio_name = "";
String radio_status = "";

# ifdef ENABLE_BLUETOOTH
if (bt_enable->get()) {
radio_name = String("BT: ") + WebUI::bt_name->get();
;
}
# endif
# ifdef ENABLE_WIFI
if (radio_name == "") {
if ((WiFi.getMode() == WIFI_MODE_STA) || (WiFi.getMode() == WIFI_MODE_APSTA)) {
radio_name = "STA: " + WiFi.SSID();
radio_addr = WiFi.localIP().toString();
} else if ((WiFi.getMode() == WIFI_MODE_AP) || (WiFi.getMode() == WIFI_MODE_APSTA)) {
radio_name = String("AP:") + WebUI::wifi_ap_ssid->get();
radio_addr = WiFi.softAPIP().toString();
} else {
radio_name = "Radio Mode: None";
}
}
# endif

if (radio_name == "") {
radio_name = "Radio Mode:Disabled";
}

oled->setTextAlignment(TEXT_ALIGN_LEFT);
oled->setFont(ArialMT_Plain_10);

if (sys.state == State::Alarm) { // print below Alarm:
oled->drawString(0, 18, radio_name);
oled->drawString(0, 30, radio_addr);

} else { // print next to status
# ifdef ENABLE_BLUETOOTH
oled->drawString(55, 2, config->_comms->_bluetoothConfig ? radio_name : radio_addr);
# endif
}
}

static void draw_checkbox(int16_t x, int16_t y, int16_t width, int16_t height, bool checked) {
if (checked)
oled->fillRect(x, y, width, height); // If log.0
else
oled->drawRect(x, y, width, height); // If log.1
}

static void oledDRO() {
uint8_t oled_y_pos;
//float wco[MAX_N_AXIS];

oled->setTextAlignment(TEXT_ALIGN_LEFT);
oled->setFont(ArialMT_Plain_10);

char axisVal[20];

oled->drawString(80, 14, "L"); // Limit switch

auto n_axis = config->_axes->_numberAxis;
auto ctrl_pins = config->_control;
bool prb_pin_state = config->_probe->get_state();

oled->setTextAlignment(TEXT_ALIGN_RIGHT);

float* print_position = get_mpos();
if (bits_are_true(status_mask->get(), RtStatus::Position)) {
oled->drawString(60, 14, "M Pos");
} else {
oled->drawString(60, 14, "W Pos");
mpos_to_wpos(print_position);
}

for (uint8_t axis = X_AXIS; axis < n_axis; axis++) {
oled_y_pos = 24 + (axis * 10);

String axis_letter = String(Machine::Axes::_names[axis]);
axis_letter += ":";
oled->setTextAlignment(TEXT_ALIGN_LEFT);
oled->drawString(0, oled_y_pos, axis_letter); // String('X') + ":");

oled->setTextAlignment(TEXT_ALIGN_RIGHT);
snprintf(axisVal, 20 - 1, "%.3f", print_position[axis]);
oled->drawString(60, oled_y_pos, axisVal);

//if (bitnum_is_true(limitAxes, axis)) { // only draw the box if a switch has been defined
// draw_checkbox(80, 27 + (axis * 10), 7, 7, limits_check(bitnum_to_mask(axis)));
//}
}

oled_y_pos = 14;

if (config->_probe->exists()) {
oled->drawString(110, oled_y_pos, "P");
draw_checkbox(120, oled_y_pos + 3, 7, 7, prb_pin_state);
oled_y_pos += 10;
}
if (ctrl_pins->_feedHold._pin.defined()) {
oled->drawString(110, oled_y_pos, "H");
draw_checkbox(120, oled_y_pos + 3, 7, 7, ctrl_pins->_feedHold.get());
oled_y_pos += 10;
}
if (ctrl_pins->_cycleStart._pin.defined()) {
oled->drawString(110, oled_y_pos, "S");
draw_checkbox(120, oled_y_pos + 3, 7, 7, ctrl_pins->_cycleStart.get());
oled_y_pos += 10;
}

if (ctrl_pins->_reset._pin.defined()) {
oled->drawString(110, oled_y_pos, "R");
draw_checkbox(120, oled_y_pos + 3, 7, 7, ctrl_pins->_reset.get());
oled_y_pos += 10;
}

if (ctrl_pins->_safetyDoor._pin.defined()) {
oled->drawString(110, oled_y_pos, "D");
draw_checkbox(120, oled_y_pos + 3, 7, 7, ctrl_pins->_safetyDoor.get());
oled_y_pos += 10;
}
}

static void oledUpdate(void* pvParameters) {
TickType_t xLastWakeTime;
const TickType_t xOledFrequency = 100; // in ticks (typically ms)
xLastWakeTime = xTaskGetTickCount(); // Initialise the xLastWakeTime variable with the current time.

vTaskDelay(2500);
uint16_t sd_file_ticker = 0;

oled->init();
oled->flipScreenVertically();

while (true) {
oled->clear();

String state_string = "";

oled->setTextAlignment(TEXT_ALIGN_LEFT);
oled->setFont(ArialMT_Plain_16);
oled->drawString(0, 0, state_name());

if (config->_sdCard->get_state() == SDCard::State::BusyPrinting) {
oled->clear();
oled->setTextAlignment(TEXT_ALIGN_CENTER);
oled->setFont(ArialMT_Plain_10);
state_string = "SD File";
for (int i = 0; i < sd_file_ticker % 10; i++) {
state_string += ".";
}
sd_file_ticker++;
oled->drawString(63, 0, state_string);

oled->drawString(63, 12, config->_sdCard->filename());

int progress = config->_sdCard->percent_complete();
// draw the progress bar
oled->drawProgressBar(0, 45, 120, 10, progress);

// draw the percentage as String
oled->setFont(ArialMT_Plain_10);
oled->setTextAlignment(TEXT_ALIGN_CENTER);
oled->drawString(64, 25, String(progress) + "%");

} else if (sys.state == State::Alarm) {
oledRadioInfo();
} else {
oledDRO();
oledRadioInfo();
}

oled->display();

vTaskDelayUntil(&xLastWakeTime, xOledFrequency);
}
}

void display_init() {
init_oled(0x3c, GPIO_NUM_14, GPIO_NUM_13, GEOMETRY_128_64);

oled->flipScreenVertically();
oled->setTextAlignment(TEXT_ALIGN_LEFT);

oled->clear();
oled->display();

xTaskCreatePinnedToCore(oledUpdate, // task
"oledUpdateTask", // name for task
4096, // size of task stack
NULL, // parameters
1, // priority
&oledUpdateTaskHandle,
CONFIG_ARDUINO_RUNNING_CORE // must run the task on same core
// core
);
}
static void oled_show_string(String s) {
oled->clear();
oled->drawString(0, 0, s);
oled->display();
}

void display(const char* tag, String s) {
if (!strcmp(tag, "IP")) {
oled_show_string(s);
return;
}
if (!strcmp(tag, "MACHINE")) {
// remove characters from the end until the string fits
while (oled->getStringWidth(s) > 64) {
s = s.substring(0, s.length() - 1);
}
oled_show_string(s);
}
}
#endif
Loading

0 comments on commit ca68365

Please sign in to comment.