Make a CNC based watchscreen for panel, shows WCS and MCS
[clinton/Smoothieware.git] / src / modules / utils / panel / screens / cnc / WatchScreen.cpp
index fb065d0..761fb4c 100644 (file)
@@ -13,7 +13,6 @@
 #include "WatchScreen.h"
 #include "libs/nuts_bolts.h"
 #include "libs/utils.h"
-#include "modules/tools/temperaturecontrol/TemperatureControlPublicAccess.h"
 #include "Robot.h"
 #include "modules/robot/Conveyor.h"
 #include "modules/utils/player/PlayerPublicAccess.h"
@@ -21,8 +20,8 @@
 #include "PublicData.h"
 #include "SwitchPublicAccess.h"
 #include "checksumm.h"
-#include "TemperatureControlPool.h"
-
+#include "StepperMotor.h"
+#include "BaseSolution.h"
 
 #include <math.h>
 #include <string.h>
@@ -61,31 +60,14 @@ WatchScreen::~WatchScreen()
 void WatchScreen::on_enter()
 {
     THEPANEL->lcd->clear();
-    THEPANEL->setup_menu(4);
+    THEPANEL->setup_menu(7);
     get_current_status();
-    get_current_pos(this->pos);
+    get_wpos();
     get_sd_play_info();
     this->current_speed = lroundf(get_current_speed());
     this->refresh_screen(false);
     THEPANEL->enter_control_mode(1, 0.5);
     THEPANEL->set_control_value(this->current_speed);
-
-    // enumerate temperature controls
-    temp_controllers.clear();
-    std::vector<struct pad_temperature> controllers;
-    bool ok = PublicData::get_value(temperature_control_checksum, poll_controls_checksum, &controllers);
-    if (ok) {
-        for (auto &c : controllers) {
-            temp_controllers.push_back(c.id);
-        }
-    }
-}
-
-static struct pad_temperature getTemperatures(uint16_t heater_cs)
-{
-    struct pad_temperature temp;
-    PublicData::get_value( temperature_control_checksum, current_temperature_checksum, heater_cs, &temp );
-    return temp;
 }
 
 void WatchScreen::on_refresh()
@@ -115,7 +97,7 @@ void WatchScreen::on_refresh()
     update_counts++;
     if ( update_counts % 20 == 0 ) {
         get_sd_play_info();
-        get_current_pos(this->pos);
+        get_wpos();
         get_current_status();
         if (this->speed_changed) {
             this->issue_change_speed = true; // trigger actual command to change speed
@@ -128,47 +110,31 @@ void WatchScreen::on_refresh()
         }
 
         this->refresh_screen(THEPANEL->lcd->hasGraphics() ? true : false); // graphics screens should be cleared
-
-        // for LCDs with leds set them according to heater status
-        bool bed_on= false, hotend_on= false, is_hot= false;
-        uint8_t heon=0, hemsk= 0x01; // bit set for which hotend is on bit0: hotend1, bit1: hotend2 etc
-        for(auto id : temp_controllers) {
-            struct pad_temperature c= getTemperatures(id);
-            if(c.current_temperature > 50) is_hot= true; // anything is hot
-            if(c.designator.front() == 'B' && c.target_temperature > 0) bed_on= true;   // bed on/off
-            if(c.designator.front() == 'T') { // a hotend by convention
-                if(c.target_temperature > 0){
-                    hotend_on= true;// hotend on/off (anyone)
-                    heon |= hemsk;
-                }
-                hemsk <<= 1;
-            }
-        }
-
-        THEPANEL->lcd->setLed(LED_BED_ON, bed_on);
-        THEPANEL->lcd->setLed(LED_HOTEND_ON, hotend_on);
-        THEPANEL->lcd->setLed(LED_HOT, is_hot);
-
-        THEPANEL->lcd->setLed(LED_FAN_ON, this->fan_state);
-
-        if (THEPANEL->lcd->hasGraphics()) {
-            // display the graphical icons below the status are
-            // for (int i = 0; i < 5; ++i) {
-            //     THEPANEL->lcd->bltGlyph(i*24, 42, 16, 16, icons, 15, i*24, 0);
-            // }
-            if(heon&0x01) THEPANEL->lcd->bltGlyph(0, 42, 16, 16, icons, 2, 0, 0);
-            if(heon&0x02) THEPANEL->lcd->bltGlyph(27, 42, 16, 16, icons, 2, 0, 16);
-            if(heon&0x04) THEPANEL->lcd->bltGlyph(55, 42, 16, 16, icons, 2, 0, 32);
-
-            if (bed_on)
-                THEPANEL->lcd->bltGlyph(83, 42, 16, 16, icons, 2, 0, 48);
-
-            if(this->fan_state)
-                THEPANEL->lcd->bltGlyph(111, 42, 16, 16, icons, 2, 0, 64);
-        }
     }
 }
 
+void WatchScreen::get_wpos()
+{
+    // get real time positions
+    // current actuator position in mm
+    ActuatorCoordinates current_position{
+        THEKERNEL->robot->actuators[X_AXIS]->get_current_position(),
+        THEKERNEL->robot->actuators[Y_AXIS]->get_current_position(),
+        THEKERNEL->robot->actuators[Z_AXIS]->get_current_position()
+    };
+
+    // get machine position from the actuator position using FK
+    float mpos[3];
+    THEKERNEL->robot->arm_solution->actuator_to_cartesian(current_position, mpos);
+    Robot::wcs_t wpos= THEKERNEL->robot->mcs2wcs(mpos);
+    this->wpos[0]= THEKERNEL->robot->from_millimeters(std::get<X_AXIS>(wpos));
+    this->wpos[1]= THEKERNEL->robot->from_millimeters(std::get<Y_AXIS>(wpos));
+    this->wpos[2]= THEKERNEL->robot->from_millimeters(std::get<Z_AXIS>(wpos));
+    this->mpos[0]= THEKERNEL->robot->from_millimeters(mpos[0]);
+    this->mpos[1]= THEKERNEL->robot->from_millimeters(mpos[1]);
+    this->mpos[2]= THEKERNEL->robot->from_millimeters(mpos[2]);
+}
+
 // queuing gcodes needs to be done from main loop
 void WatchScreen::on_main_loop()
 {
@@ -182,14 +148,14 @@ void WatchScreen::on_main_loop()
 // fetch the data we are displaying
 void WatchScreen::get_current_status()
 {
-    // get fan status
+    // get spindle status
     struct pad_switch s;
     bool ok = PublicData::get_value( switch_checksum, fan_checksum, 0, &s );
     if (ok) {
-        this->fan_state = s.state;
+        this->spindle_state = s.state;
     } else {
-        // fan probably disabled
-        this->fan_state = false;
+        // spindle probably disabled
+        this->spindle_state = false;
     }
 }
 
@@ -220,38 +186,12 @@ void WatchScreen::display_menu_line(uint16_t line)
 {
     // in menu mode
     switch ( line ) {
-        case 0:
-        {
-            auto& tm= this->temp_controllers;
-            if(tm.size() > 0) {
-                // only if we detected heaters in config
-                int n= 0;
-                if(tm.size() > 2) {
-                    // more than two temps we need to cycle between them
-                    n= update_counts/100; // increments every 5 seconds
-                    int ntemps= (tm.size()+1)/2;
-                    n= n%ntemps; // which of the pairs of temps to display
-                }
-
-                int off= 0;
-                for (size_t i = 0; i < 2; ++i) {
-                    size_t o= i+(n*2);
-                    if(o>tm.size()-1) break;
-                    struct pad_temperature temp= getTemperatures(tm[o]);
-                    int t= std::min(999, (int)roundf(temp.current_temperature));
-                    int tt= roundf(temp.target_temperature);
-                    THEPANEL->lcd->setCursor(off, 0); // col, row
-                    off += THEPANEL->lcd->printf("%s:%03d/%03d ", temp.designator.substr(0, 2).c_str(), t, tt);
-                }
-
-            }else{
-                //THEPANEL->lcd->printf("No Heaters");
-            }
-            break;
-        }
-        case 1: THEPANEL->lcd->printf("X%4d Y%4d Z%7.2f", (int)round(this->pos[0]), (int)round(this->pos[1]), this->pos[2]); break;
-        case 2: THEPANEL->lcd->printf("%3d%% %2lu:%02lu %3u%% sd", this->current_speed, this->elapsed_time / 60, this->elapsed_time % 60, this->sd_pcnt_played); break;
-        case 3: THEPANEL->lcd->printf("%19s", this->get_status()); break;
+        case 0: THEPANEL->lcd->printf("     WCS      MCS "); break;
+        case 1: THEPANEL->lcd->printf("X %8.3f %8.3f", wpos[0], mpos[0]); break;
+        case 2: THEPANEL->lcd->printf("Y %8.3f %8.3f", wpos[1], mpos[1]); break;
+        case 3: THEPANEL->lcd->printf("Z %8.3f %8.3f", wpos[2], mpos[2]); break;
+        case 4: THEPANEL->lcd->printf("%3d%% %2lu:%02lu %3u%% sd", this->current_speed, this->elapsed_time / 60, this->elapsed_time % 60, this->sd_pcnt_played); break;
+        case 5: THEPANEL->lcd->printf("%19s", this->get_status()); break;
     }
 }
 
@@ -261,7 +201,7 @@ const char *WatchScreen::get_status()
         return THEPANEL->getMessage().c_str();
 
     if (THEKERNEL->is_halted())
-        return "HALTED Reset or M999";
+        return "ALARM";
 
     if (THEPANEL->is_suspended())
         return "Suspended";
@@ -270,11 +210,11 @@ const char *WatchScreen::get_status()
         return THEPANEL->get_playing_file();
 
     if (!THEKERNEL->conveyor->is_queue_empty())
-        return "Printing";
+        return "Running";
 
     const char *ip = get_network();
     if (ip == NULL) {
-        return "Smoothie ready";
+        return "Idle";
     } else {
         return ip;
     }