refactor the panel to be a singleton saving having to store panel pointer in every screen
lazy load the configure screen
#include "checksumm.h"
#include "ConfigValue.h"
+#define temperature_control_checksum CHECKSUM("temperature_control")
+#define enable_checksum CHECKSUM("enable")
+
TemperatureControlPool::TemperatureControlPool(){}
void TemperatureControlPool::on_module_loaded(){
vector<uint16_t> modules;
THEKERNEL->config->get_module_list( &modules, temperature_control_checksum );
-
+ int cnt= 0;
for( unsigned int i = 0; i < modules.size(); i++ ){
// If module is enabled
if( THEKERNEL->config->value(temperature_control_checksum, modules[i], enable_checksum )->as_bool() == true ){
TemperatureControl* controller = new TemperatureControl(modules[i]);
controller->pool = this;
- controllers.push_back( controller );
- controller->pool_index = controllers.size() - 1;
+ //controllers.push_back( controller );
+ //controller->pool_index = controllers.size() - 1;
+ controller->pool_index = cnt++;
THEKERNEL->add_module(controller);
}
}
class TemperatureControl;
class PID_Autotuner;
-#define temperature_control_checksum CHECKSUM("temperature_control")
-#define enable_checksum CHECKSUM("enable")
-
class TemperatureControlPool : public Module {
public:
TemperatureControlPool();
void on_module_loaded();
+ friend class TemperatureControl;
- vector<TemperatureControl*> controllers;
+ private:
+ //vector<TemperatureControl*> controllers;
PID_Autotuner* PIDtuner;
};
#include "SlowTicker.h"
#include "Gcode.h"
#include "Pauser.h"
+#include "TemperatureControlPublicAccess.h"
+#include "ModifyValuesScreen.h"
+#include "PublicDataRequest.h"
#include "PublicData.h"
#include "panels/I2CLCD.h"
#define hotend_temp_checksum CHECKSUM("hotend_temperature")
#define bed_temp_checksum CHECKSUM("bed_temperature")
+Panel* Panel::instance= nullptr;
+
Panel::Panel()
{
+ instance= this;
this->counter_changed = false;
this->click_changed = false;
this->refresh_flag = false;
return;
}
- this->custom_screen= new CustomScreen(); // this needs to be called here as it needs the config cache loaded
+ // these need to be called here as they need the config cache loaded as they enumerate modules
+ this->custom_screen= new CustomScreen();
+ setup_temperature_screen();
// some panels may need access to this global info
this->lcd->setPanel(this);
// Enter a screen, we only care about it now
void Panel::enter_screen(PanelScreen *screen)
{
- screen->panel = this;
this->current_screen = screen;
this->reset_counter();
this->current_screen->on_enter();
// Default top screen
this->top_screen= new MainMenuScreen();
- this->top_screen->set_panel(this);
this->custom_screen->set_parent(this->top_screen);
this->start_up = false;
return;
strncpy(playing_file, f.substr(n + 1, 19).c_str(), sizeof(playing_file));
playing_file[sizeof(playing_file) - 1] = 0;
}
+
+static float getTargetTemperature(uint16_t heater_cs)
+{
+ void *returned_data;
+ bool ok = THEKERNEL->public_data->get_value( temperature_control_checksum, heater_cs, current_temperature_checksum, &returned_data );
+
+ if (ok) {
+ struct pad_temperature temp = *static_cast<struct pad_temperature *>(returned_data);
+ return temp.target_temperature;
+ }
+
+ return 0.0F;
+}
+
+void Panel::setup_temperature_screen()
+{
+ // setup temperature screen
+ auto mvs= new ModifyValuesScreen();
+ this->temperature_screen= mvs;
+
+ // enumerate heaters and add a menu item for each one
+ vector<uint16_t> modules;
+ THEKERNEL->config->get_module_list( &modules, temperature_control_checksum );
+
+ for(auto i : modules) {
+ if (!THEKERNEL->config->value(temperature_control_checksum, i, enable_checksum )->as_bool()) continue;
+ void *returned_data;
+ bool ok = THEKERNEL->public_data->get_value( temperature_control_checksum, i, current_temperature_checksum, &returned_data );
+ if (!ok) continue;
+
+ struct pad_temperature t = *static_cast<struct pad_temperature *>(returned_data);
+
+ // rename if two of the known types
+ const char *name;
+ if(t.designator == "T") name= "Hotend";
+ else if(t.designator == "B") name= "Bed";
+ else name= t.designator.c_str();
+
+ mvs->addMenuItem(name, // menu name
+ [i]() -> float { return getTargetTemperature(i); }, // getter
+ [i](float t) { THEKERNEL->public_data->set_value( temperature_control_checksum, i, &t ); }, // setter
+ 1.0F, // increment
+ 0.0F, // Min
+ 500.0F // Max
+ );
+ }
+}
#define MENU_MODE 0
#define CONTROL_MODE 1
+#define THEPANEL Panel::instance
+
class LcdBase;
class PanelScreen;
public:
Panel();
virtual ~Panel();
+ static Panel* instance;
void on_module_loaded();
uint32_t button_tick(uint32_t dummy);
// TODO pass lcd into ctor of each sub screen
LcdBase* lcd;
PanelScreen* custom_screen;
+ PanelScreen* temperature_screen;
// as panelscreen accesses private fields in Panel
friend class PanelScreen;
private:
+ void setup_temperature_screen();
+
// Menu
char menu_offset;
int menu_selected_line;
void PanelScreen::on_refresh() {}
void PanelScreen::on_main_loop() {}
-PanelScreen *PanelScreen::set_panel(Panel *parent)
-{
- this->panel = parent;
- return this;
-}
-
void PanelScreen::on_enter() {}
void PanelScreen::refresh_menu(bool clear)
{
- if (clear) this->panel->lcd->clear();
- for (uint16_t i = this->panel->menu_start_line; i < this->panel->menu_start_line + min( this->panel->menu_rows, this->panel->panel_lines ); i++ ) {
- this->panel->lcd->setCursor(2, i - this->panel->menu_start_line );
+ if (clear) THEPANEL->lcd->clear();
+ for (uint16_t i = THEPANEL->menu_start_line; i < THEPANEL->menu_start_line + min( THEPANEL->menu_rows, THEPANEL->panel_lines ); i++ ) {
+ THEPANEL->lcd->setCursor(2, i - THEPANEL->menu_start_line );
this->display_menu_line(i);
}
- this->panel->lcd->setCursor(0, this->panel->menu_current_line - this->panel->menu_start_line );
- this->panel->lcd->printf(">");
+ THEPANEL->lcd->setCursor(0, THEPANEL->menu_current_line - THEPANEL->menu_start_line );
+ THEPANEL->lcd->printf(">");
}
void PanelScreen::refresh_screen(bool clear)
{
- if (clear) this->panel->lcd->clear();
- for (uint16_t i = this->panel->menu_start_line; i < this->panel->menu_start_line + min( this->panel->menu_rows, this->panel->panel_lines ); i++ ) {
- this->panel->lcd->setCursor(0, i - this->panel->menu_start_line );
+ if (clear) THEPANEL->lcd->clear();
+ for (uint16_t i = THEPANEL->menu_start_line; i < THEPANEL->menu_start_line + min( THEPANEL->menu_rows, THEPANEL->panel_lines ); i++ ) {
+ THEPANEL->lcd->setCursor(0, i - THEPANEL->menu_start_line );
this->display_menu_line(i);
}
}
PanelScreen *PanelScreen::set_parent(PanelScreen *passed_parent)
{
this->parent = passed_parent;
- this->set_panel( passed_parent->panel );
return this;
}
#include <string>
class Panel;
+
class PanelScreen
{
public:
PanelScreen();
virtual void on_refresh();
virtual void on_main_loop();
- PanelScreen *set_panel(Panel *parent);
PanelScreen *set_parent(PanelScreen *passed_parent);
virtual void on_enter();
// if you completely rewrite the screen do not clear it, this avoids flicker
virtual void display_menu_line(uint16_t line) = 0;
// default idle timeout for a screen, each screen can override this
virtual int idle_timeout_secs(){ return 10; }
- Panel *panel;
- PanelScreen *parent;
+ friend class Panel;
protected:
void send_gcode(std::string g);
void send_gcode(const char *gm_code, char parameter, float value);
void send_command(const char *gcstr);
+
+ PanelScreen *parent;
};
#endif
void ControlScreen::on_enter()
{
- this->panel->enter_menu_mode();
- this->panel->setup_menu(4);
+ THEPANEL->enter_menu_mode();
+ THEPANEL->setup_menu(4);
get_current_pos(this->pos);
this->refresh_menu();
this->pos_changed = false;
// called in on_idle()
void ControlScreen::on_refresh()
{
- if ( this->panel->menu_change() ) {
+ if ( THEPANEL->menu_change() ) {
this->refresh_menu();
}
if (this->control_mode == AXIS_CONTROL_MODE) {
- if ( this->panel->click() ) {
+ if ( THEPANEL->click() ) {
this->enter_menu_control();
this->refresh_menu();
- } else if (this->panel->control_value_change()) {
- this->pos[this->controlled_axis - 'X'] = this->panel->get_control_value();
- this->panel->lcd->setCursor(0, 2);
+ } else if (THEPANEL->control_value_change()) {
+ this->pos[this->controlled_axis - 'X'] = THEPANEL->get_control_value();
+ THEPANEL->lcd->setCursor(0, 2);
this->display_axis_line(this->controlled_axis);
this->pos_changed = true; // make the gcode in main_loop
}
} else {
- if ( this->panel->click() ) {
- this->clicked_menu_entry(this->panel->get_menu_current_line());
+ if ( THEPANEL->click() ) {
+ this->clicked_menu_entry(THEPANEL->get_menu_current_line());
}
}
}
{
// in menu mode
switch ( line ) {
- case 0: this->panel->lcd->printf("Back"); break;
+ case 0: THEPANEL->lcd->printf("Back"); break;
case 1: this->display_axis_line('X'); break;
case 2: this->display_axis_line('Y'); break;
case 3: this->display_axis_line('Z'); break;
void ControlScreen::display_axis_line(char axis)
{
- this->panel->lcd->printf("Move %c %8.3f", axis, this->pos[axis - 'X']);
+ THEPANEL->lcd->printf("Move %c %8.3f", axis, this->pos[axis - 'X']);
}
void ControlScreen::clicked_menu_entry(uint16_t line)
{
switch ( line ) {
- case 0: this->panel->enter_screen(this->parent ); break;
+ case 0: THEPANEL->enter_screen(this->parent ); break;
case 1: this->enter_axis_control('X'); break;
case 2: this->enter_axis_control('Y'); break;
case 3: this->enter_axis_control('Z'); break;
{
this->control_mode = AXIS_CONTROL_MODE;
this->controlled_axis = axis;
- this->panel->enter_control_mode(this->jog_increment, this->jog_increment / 10);
- this->panel->set_control_value(this->pos[axis - 'X']);
- this->panel->lcd->clear();
- this->panel->lcd->setCursor(0, 2);
+ THEPANEL->enter_control_mode(this->jog_increment, this->jog_increment / 10);
+ THEPANEL->set_control_value(this->pos[axis - 'X']);
+ THEPANEL->lcd->clear();
+ THEPANEL->lcd->setCursor(0, 2);
this->display_axis_line(this->controlled_axis);
}
void ControlScreen::enter_menu_control()
{
this->control_mode = NULL_CONTROL_MODE;
- this->panel->enter_menu_mode();
+ THEPANEL->enter_menu_mode();
}
void ControlScreen::get_current_pos(float *cp)
{
// change pos by issuing a G0 Xnnn
char buf[32];
- int n = snprintf(buf, sizeof(buf), "G0 %c%f F%d", axis, p, (int)round(panel->get_jogging_speed(axis)));
+ int n = snprintf(buf, sizeof(buf), "G0 %c%f F%d", axis, p, (int)round(THEPANEL->get_jogging_speed(axis)));
string g(buf, n);
send_gcode(g);
}
void CustomScreen::on_enter()
{
- this->panel->enter_menu_mode();
- this->panel->setup_menu(menu_items.size() + 1);
+ THEPANEL->enter_menu_mode();
+ THEPANEL->setup_menu(menu_items.size() + 1);
this->refresh_menu();
}
void CustomScreen::on_refresh()
{
- if ( this->panel->menu_change() ) {
+ if ( THEPANEL->menu_change() ) {
this->refresh_menu();
}
- if ( this->panel->click() ) {
- this->clicked_menu_entry(this->panel->get_menu_current_line());
+ if ( THEPANEL->click() ) {
+ this->clicked_menu_entry(THEPANEL->get_menu_current_line());
}
}
void CustomScreen::display_menu_line(uint16_t line)
{
if (line == 0) {
- this->panel->lcd->printf("Back");
+ THEPANEL->lcd->printf("Back");
} else {
- this->panel->lcd->printf(std::get<0>(menu_items[line-1]));
+ THEPANEL->lcd->printf(std::get<0>(menu_items[line-1]));
}
}
void CustomScreen::clicked_menu_entry(uint16_t line)
{
if (line == 0) {
- this->panel->enter_screen(this->parent);
+ THEPANEL->enter_screen(this->parent);
} else {
command = std::get<1>(menu_items[line-1]);
}
void ExtruderScreen::on_enter()
{
- this->panel->enter_menu_mode();
- this->panel->setup_menu(3);
+ THEPANEL->enter_menu_mode();
+ THEPANEL->setup_menu(3);
this->refresh_menu();
}
void ExtruderScreen::on_refresh()
{
- if ( this->panel->menu_change() ) {
+ if ( THEPANEL->menu_change() ) {
this->refresh_menu();
}
- if ( this->panel->click() ) {
- this->clicked_menu_entry(this->panel->get_menu_current_line());
+ if ( THEPANEL->click() ) {
+ this->clicked_menu_entry(THEPANEL->get_menu_current_line());
}
}
void ExtruderScreen::display_menu_line(uint16_t line)
{
switch ( line ) {
- case 0: this->panel->lcd->printf("Back"); break;
- case 1: this->panel->lcd->printf("Extrude 5mm"); break;
- case 2: this->panel->lcd->printf("Retract 5mm"); break;
+ case 0: THEPANEL->lcd->printf("Back"); break;
+ case 1: THEPANEL->lcd->printf("Extrude 5mm"); break;
+ case 2: THEPANEL->lcd->printf("Retract 5mm"); break;
}
}
void ExtruderScreen::clicked_menu_entry(uint16_t line)
{
switch ( line ) {
- case 0: this->panel->enter_screen(this->parent); return;
+ case 0: THEPANEL->enter_screen(this->parent); return;
case 1: command = "G91\nG1 E5 F100\nG90"; break;
case 2: command = "G91\nG1 E-5 F100\nG90"; break;
}
// When entering this screen
void FileScreen::on_enter()
{
- this->panel->lcd->clear();
+ THEPANEL->lcd->clear();
// Default folder to enter
if ( this->current_folder.compare("") == 0 ) {
// For every ( potential ) refresh of the screen
void FileScreen::on_refresh()
{
- if ( this->panel->menu_change() ) {
+ if ( THEPANEL->menu_change() ) {
this->refresh_menu();
}
- if ( this->panel->click() ) {
- this->clicked_line(this->panel->get_menu_current_line());
+ if ( THEPANEL->click() ) {
+ this->clicked_line(THEPANEL->get_menu_current_line());
}
}
uint16_t number_of_files_in_folder = this->count_folder_content(this->current_folder);
// Setup menu
- this->panel->setup_menu(number_of_files_in_folder + 1); // same number of files as menu items
- this->panel->enter_menu_mode();
+ THEPANEL->setup_menu(number_of_files_in_folder + 1); // same number of files as menu items
+ THEPANEL->enter_menu_mode();
// Display menu
this->refresh_menu();
void FileScreen::display_menu_line(uint16_t line)
{
if ( line == 0 ) {
- this->panel->lcd->printf("..");
+ THEPANEL->lcd->printf("..");
} else {
- this->panel->lcd->printf("%s", (this->file_at(line - 1).substr(0, 18)).c_str());
+ THEPANEL->lcd->printf("%s", (this->file_at(line - 1).substr(0, 18)).c_str());
}
}
if ( line == 0 ) {
if ( this->current_folder.compare("/") == 0 ) {
// Exit file navigation
- this->panel->enter_screen(this->parent);
+ THEPANEL->enter_screen(this->parent);
} else {
// Go up one folder
this->current_folder = this->current_folder.substr(0, this->current_folder.find_last_of('/') + 1);
{
if (this->start_play) {
this->start_play = false;
- this->panel->set_playing_file(this->play_path);
+ THEPANEL->set_playing_file(this->play_path);
this->play(this->play_path);
- this->panel->enter_screen(this->parent);
+ THEPANEL->enter_screen(this->parent);
return;
}
}
void JogScreen::on_enter()
{
- this->panel->enter_menu_mode();
- this->panel->setup_menu(4);
+ THEPANEL->enter_menu_mode();
+ THEPANEL->setup_menu(4);
this->refresh_menu();
}
void JogScreen::on_refresh()
{
- if ( this->panel->menu_change() ) {
+ if ( THEPANEL->menu_change() ) {
this->refresh_menu();
}
- if ( this->panel->click() ) {
- this->clicked_menu_entry(this->panel->get_menu_current_line());
+ if ( THEPANEL->click() ) {
+ this->clicked_menu_entry(THEPANEL->get_menu_current_line());
}
}
void JogScreen::display_menu_line(uint16_t line)
{
switch ( line ) {
- case 0: this->panel->lcd->printf("Back"); break;
- case 1: this->panel->lcd->printf("Move 10.0mm \x7E"); break;
- case 2: this->panel->lcd->printf("Move 1.0mm \x7E"); break;
- case 3: this->panel->lcd->printf("Move 0.1mm \x7E"); break;
+ case 0: THEPANEL->lcd->printf("Back"); break;
+ case 1: THEPANEL->lcd->printf("Move 10.0mm \x7E"); break;
+ case 2: THEPANEL->lcd->printf("Move 1.0mm \x7E"); break;
+ case 3: THEPANEL->lcd->printf("Move 0.1mm \x7E"); break;
}
}
void JogScreen::clicked_menu_entry(uint16_t line)
{
switch ( line ) {
- case 0: this->panel->enter_screen(this->parent); return;
+ case 0: THEPANEL->enter_screen(this->parent); return;
case 1: this->control_screen->set_jog_increment(10.0); break;
case 2: this->control_screen->set_jog_increment(1.0); break;
case 3: this->control_screen->set_jog_increment(0.1); break;
}
- this->panel->enter_screen(this->control_screen);
+ THEPANEL->enter_screen(this->control_screen);
}
this->watch_screen = (new WatchScreen() )->set_parent(this);
this->file_screen = (new FileScreen() )->set_parent(this);
this->prepare_screen = (new PrepareScreen() )->set_parent(this);
- this->configure_screen = setupConfigureScreen();
+ this->configure_screen = nullptr; // lazy load this the first time it is used
this->set_parent(this->watch_screen);
}
void MainMenuScreen::on_enter()
{
- this->panel->enter_menu_mode();
- this->panel->setup_menu(6);
+ THEPANEL->enter_menu_mode();
+ THEPANEL->setup_menu(6);
this->refresh_menu();
}
void MainMenuScreen::on_refresh()
{
- if ( this->panel->menu_change() ) {
+ if ( THEPANEL->menu_change() ) {
this->refresh_menu();
}
- if ( this->panel->click() ) {
- this->clicked_menu_entry(this->panel->get_menu_current_line());
+ if ( THEPANEL->click() ) {
+ this->clicked_menu_entry(THEPANEL->get_menu_current_line());
}
}
void MainMenuScreen::display_menu_line(uint16_t line)
{
switch ( line ) {
- case 0: this->panel->lcd->printf("Watch"); break;
- case 1: this->panel->lcd->printf(panel->is_playing() ? "Abort" : "Play"); break;
- case 2: this->panel->lcd->printf("Jog"); break;
- case 3: this->panel->lcd->printf("Prepare"); break;
- case 4: this->panel->lcd->printf("Custom"); break;
- case 5: this->panel->lcd->printf("Configure"); break;
- //case 5: this->panel->lcd->printf("Tune"); break;
+ case 0: THEPANEL->lcd->printf("Watch"); break;
+ case 1: THEPANEL->lcd->printf(THEPANEL->is_playing() ? "Abort" : "Play"); break;
+ case 2: THEPANEL->lcd->printf("Jog"); break;
+ case 3: THEPANEL->lcd->printf("Prepare"); break;
+ case 4: THEPANEL->lcd->printf("Custom"); break;
+ case 5: THEPANEL->lcd->printf("Configure"); break;
+ //case 5: THEPANEL->lcd->printf("Tune"); break;
}
}
void MainMenuScreen::clicked_menu_entry(uint16_t line)
{
switch ( line ) {
- case 0: this->panel->enter_screen(this->watch_screen ); break;
- case 1: this->panel->is_playing() ? abort_playing() : this->panel->enter_screen(this->file_screen); break;
- case 2: this->panel->enter_screen(this->jog_screen ); break;
- case 3: this->panel->enter_screen(this->prepare_screen ); break;
- case 4: this->panel->enter_screen(this->panel->custom_screen ); break;
- case 5: this->panel->enter_screen(this->configure_screen ); break;
+ case 0: THEPANEL->enter_screen(this->watch_screen ); break;
+ case 1: THEPANEL->is_playing() ? abort_playing() : THEPANEL->enter_screen(this->file_screen); break;
+ case 2: THEPANEL->enter_screen(this->jog_screen ); break;
+ case 3: THEPANEL->enter_screen(this->prepare_screen ); break;
+ case 4: THEPANEL->enter_screen(THEPANEL->custom_screen ); break;
+ case 5: if(this->configure_screen == nullptr) this->configure_screen= setupConfigureScreen();
+ THEPANEL->enter_screen(this->configure_screen );
+ break;
}
}
void MainMenuScreen::abort_playing()
{
THEKERNEL->public_data->set_value(player_checksum, abort_play_checksum, NULL);
- this->panel->enter_screen(this->watch_screen);
+ THEPANEL->enter_screen(this->watch_screen);
}
control_mode = MENU_CONTROL_MODE;
}
+ModifyValuesScreen::~ModifyValuesScreen()
+{
+ // free up the strdup() name
+ for(auto i : menu_items) {
+ free(std::get<0>(i));
+ }
+}
+
void ModifyValuesScreen::on_enter()
{
- this->panel->enter_menu_mode();
- this->panel->setup_menu(menu_items.size() + 1);
+ THEPANEL->enter_menu_mode();
+ THEPANEL->setup_menu(menu_items.size() + 1);
this->refresh_menu();
}
void ModifyValuesScreen::on_refresh()
{
- if ( this->panel->menu_change() ) {
+ if ( THEPANEL->menu_change() ) {
this->refresh_menu();
}
if (this->control_mode == VALUE_CONTROL_MODE) {
- if ( this->panel->click() ) {
+ if ( THEPANEL->click() ) {
// done changing value
execute_function= selected_item; // this causes on_main_loop to change the value
this->control_mode = MENU_CONTROL_MODE;
- this->panel->enter_menu_mode(true);
+ THEPANEL->enter_menu_mode(true);
- } else if (this->panel->control_value_change()) {
- this->new_value = this->panel->get_control_value();
+ } else if (THEPANEL->control_value_change()) {
+ this->new_value = THEPANEL->get_control_value();
if(!isnan(this->min_value) && this->new_value < this->min_value) {
- this->panel->set_control_value((this->new_value = this->min_value));
- this->panel->reset_counter();
+ THEPANEL->set_control_value((this->new_value = this->min_value));
+ THEPANEL->reset_counter();
}
if(!isnan(this->max_value) && this->new_value > this->max_value) {
- this->panel->set_control_value((this->new_value = this->max_value));
- this->panel->reset_counter();
+ THEPANEL->set_control_value((this->new_value = this->max_value));
+ THEPANEL->reset_counter();
}
- this->panel->lcd->setCursor(0, 2);
- this->panel->lcd->printf("%10.3f ", this->new_value);
+ THEPANEL->lcd->setCursor(0, 2);
+ THEPANEL->lcd->printf("%10.3f ", this->new_value);
}
} else {
- if ( this->panel->click() ) {
- this->clicked_menu_entry(this->panel->get_menu_current_line());
+ if ( THEPANEL->click() ) {
+ this->clicked_menu_entry(THEPANEL->get_menu_current_line());
}
}
}
void ModifyValuesScreen::display_menu_line(uint16_t line)
{
if (line == 0) {
- this->panel->lcd->printf("Back");
+ THEPANEL->lcd->printf("Back");
} else {
line--;
const char *name = std::get<0>(menu_items[line]);
float value = std::get<1>(menu_items[line])();
- this->panel->lcd->printf("%-12s %8.3f", name, value);
+ THEPANEL->lcd->printf("%-12s %8.3f", name, value);
}
}
void ModifyValuesScreen::clicked_menu_entry(uint16_t line)
{
if (line == 0) {
- this->panel->enter_screen(this->parent);
+ THEPANEL->enter_screen(this->parent);
} else {
line--;
const char *name = std::get<0>(menu_items[line]);
float value = std::get<1>(menu_items[line])();
float inc= std::get<3>(menu_items[line]);
- this->panel->enter_control_mode(inc, inc / 10);
+ THEPANEL->enter_control_mode(inc, inc / 10);
this->min_value= std::get<4>(menu_items[line]);
this->max_value= std::get<5>(menu_items[line]);
- this->panel->set_control_value(value);
- this->panel->lcd->clear();
- this->panel->lcd->setCursor(0, 0);
- this->panel->lcd->printf("%s", name);
- this->panel->lcd->setCursor(0, 2);
- this->panel->lcd->printf("%10.3f", value);
+ THEPANEL->set_control_value(value);
+ THEPANEL->lcd->clear();
+ THEPANEL->lcd->setCursor(0, 0);
+ THEPANEL->lcd->printf("%s", name);
+ THEPANEL->lcd->setCursor(0, 2);
+ THEPANEL->lcd->printf("%10.3f", value);
}
}
execute_function = -1;
}
-void ModifyValuesScreen::addMenuItem(const MenuItemType& item)
-{
- menu_items.push_back(item);
-}
-
void ModifyValuesScreen::addMenuItem(const char *name, std::function<float()> getter, std::function<void(float)> setter, float inc, float min, float max)
{
- menu_items.push_back(make_tuple(name, getter, setter, inc, min, max));
+ menu_items.push_back(make_tuple(strdup(name), getter, setter, inc, min, max));
}
{
public:
ModifyValuesScreen();
+ virtual ~ModifyValuesScreen();
void on_refresh();
void on_enter();
void clicked_menu_entry(uint16_t line);
int idle_timeout_secs(){ return 60; }
- typedef std::tuple<const char *, std::function<float()>, std::function<void(float)>, float, float, float> MenuItemType;
+ typedef std::tuple<char *, std::function<float()>, std::function<void(float)>, float, float, float> MenuItemType;
void addMenuItem(const MenuItemType& item);
void addMenuItem(const char *name, std::function<float()> getter, std::function<void(float)> setter, float inc= 1.0F, float min= NAN, float max= NAN);
#include "ExtruderScreen.h"
#include "libs/nuts_bolts.h"
#include "libs/utils.h"
-#include "PublicDataRequest.h"
-#include "modules/tools/temperaturecontrol/TemperatureControlPublicAccess.h"
-#include "PublicData.h"
#include "checksumm.h"
#include "ModifyValuesScreen.h"
+#include "PublicDataRequest.h"
+#include "PublicData.h"
+#include "TemperatureControlPublicAccess.h"
#include <string>
using namespace std;
-static float getTargetTemperature(uint16_t heater_cs)
-{
- void *returned_data;
- bool ok = THEKERNEL->public_data->get_value( temperature_control_checksum, heater_cs, current_temperature_checksum, &returned_data );
-
- if (ok) {
- struct pad_temperature temp = *static_cast<struct pad_temperature *>(returned_data);
- return temp.target_temperature;
- }
-
- return 0.0F;
-}
-
-static void setTargetTemperature(uint16_t heater_cs, float temp)
-{
- THEKERNEL->public_data->set_value( temperature_control_checksum, heater_cs, &temp );
-}
-
PrepareScreen::PrepareScreen()
{
// Children screens
this->extruder_screen = (new ExtruderScreen() )->set_parent(this);
- // setup temperature screen
- auto mvs= new ModifyValuesScreen();
- this->temperature_screen= mvs;
- this->temperature_screen->set_parent(this);
-
- // TODO need to enumerate hotends
- mvs->addMenuItem("Hotend1", // menu name
- []() -> float { return getTargetTemperature(get_checksum("hotend")); }, // getter
- [](float t) { setTargetTemperature(get_checksum("hotend"), t); }, // setter
- 1.0F, // increment
- 0.0F, // Min
- 500.0F // Max
- );
- mvs->addMenuItem("Bed", []() -> float { return getTargetTemperature(get_checksum("bed")); }, [](float t) { setTargetTemperature(get_checksum("bed"), t); }, 1.0F, 0.0F, 500.0F);
+ THEPANEL->temperature_screen->set_parent(this);
}
void PrepareScreen::on_enter()
{
- this->panel->enter_menu_mode();
- this->panel->setup_menu(9);
+ THEPANEL->enter_menu_mode();
+ THEPANEL->setup_menu(9);
this->refresh_menu();
}
void PrepareScreen::on_refresh()
{
- if ( this->panel->menu_change() ) {
+ if ( THEPANEL->menu_change() ) {
this->refresh_menu();
}
- if ( this->panel->click() ) {
- this->clicked_menu_entry(this->panel->get_menu_current_line());
+ if ( THEPANEL->click() ) {
+ this->clicked_menu_entry(THEPANEL->get_menu_current_line());
}
}
void PrepareScreen::display_menu_line(uint16_t line)
{
switch ( line ) {
- case 0: this->panel->lcd->printf("Back" ); break;
- case 1: this->panel->lcd->printf("Home All Axis" ); break;
- case 2: this->panel->lcd->printf("Set Home" ); break;
- case 3: this->panel->lcd->printf("Set Z0" ); break;
- case 4: this->panel->lcd->printf("Pre Heat" ); break;
- case 5: this->panel->lcd->printf("Cool Down" ); break;
- case 6: this->panel->lcd->printf("Extrude" ); break;
- case 7: this->panel->lcd->printf("Motors off" ); break;
- case 8: this->panel->lcd->printf("Set Temperature"); break;
+ case 0: THEPANEL->lcd->printf("Back" ); break;
+ case 1: THEPANEL->lcd->printf("Home All Axis" ); break;
+ case 2: THEPANEL->lcd->printf("Set Home" ); break;
+ case 3: THEPANEL->lcd->printf("Set Z0" ); break;
+ case 4: THEPANEL->lcd->printf("Pre Heat" ); break;
+ case 5: THEPANEL->lcd->printf("Cool Down" ); break;
+ case 6: THEPANEL->lcd->printf("Extrude" ); break;
+ case 7: THEPANEL->lcd->printf("Motors off" ); break;
+ case 8: THEPANEL->lcd->printf("Set Temperature"); break;
}
}
void PrepareScreen::clicked_menu_entry(uint16_t line)
{
switch ( line ) {
- case 0: this->panel->enter_screen(this->parent); break;
+ case 0: THEPANEL->enter_screen(this->parent); break;
case 1: command = "G28"; break;
case 2: command = "G92 X0 Y0 Z0"; break;
case 3: command = "G92 Z0"; break;
case 4: this->preheat(); break;
case 5: this->cooldown(); break;
- case 6: this->panel->enter_screen(this->extruder_screen); break;
+ case 6: THEPANEL->enter_screen(this->extruder_screen); break;
case 7: command = "M84"; break;
- case 8: this->panel->enter_screen(this->temperature_screen); break;
+ case 8: THEPANEL->enter_screen(THEPANEL->temperature_screen); break;
}
}
void PrepareScreen::preheat()
{
- float t = panel->get_default_hotend_temp();
+ float t = THEPANEL->get_default_hotend_temp();
THEKERNEL->public_data->set_value( temperature_control_checksum, hotend_checksum, &t );
- t = panel->get_default_bed_temp();
+ t = THEPANEL->get_default_bed_temp();
THEKERNEL->public_data->set_value( temperature_control_checksum, bed_checksum, &t );
}
int idle_timeout_secs() { return 60; }
private:
+
PanelScreen *extruder_screen;
- PanelScreen *temperature_screen;
void preheat();
void cooldown();
-
+ void setup_temperature_screen();
string command;
};
void WatchScreen::on_enter()
{
- this->panel->lcd->clear();
- this->panel->setup_menu(4);
+ THEPANEL->lcd->clear();
+ THEPANEL->setup_menu(4);
get_temp_data();
get_current_pos(this->pos);
get_sd_play_info();
this->current_speed = lround(get_current_speed());
this->refresh_screen(false);
- this->panel->enter_control_mode(1, 0.5);
- this->panel->set_control_value(this->current_speed);
+ THEPANEL->enter_control_mode(1, 0.5);
+ THEPANEL->set_control_value(this->current_speed);
}
void WatchScreen::on_refresh()
{
// Exit if the button is clicked
- if ( this->panel->click() ) {
- this->panel->enter_screen(this->parent);
+ if ( THEPANEL->click() ) {
+ THEPANEL->enter_screen(this->parent);
return;
}
// see if speed is being changed
- if (this->panel->control_value_change()) {
- this->current_speed = this->panel->get_control_value();
+ if (THEPANEL->control_value_change()) {
+ this->current_speed = THEPANEL->get_control_value();
if (this->current_speed < 10) {
this->current_speed = 10;
- this->panel->set_control_value(this->current_speed);
- this->panel->reset_counter();
+ THEPANEL->set_control_value(this->current_speed);
+ THEPANEL->reset_counter();
} else {
// flag the update to change the speed, we don't want to issue hundreds of M220s
// but we do want to display the change we are going to make
} else if (!this->issue_change_speed) { // change still queued
// read it in case it was changed via M220
this->current_speed = lround(get_current_speed());
- this->panel->set_control_value(this->current_speed);
- this->panel->reset_counter();
+ THEPANEL->set_control_value(this->current_speed);
+ THEPANEL->reset_counter();
}
- this->refresh_screen(this->panel->lcd->hasGraphics() ? true : false); // graphics screens should be cleared
+ this->refresh_screen(THEPANEL->lcd->hasGraphics() ? true : false); // graphics screens should be cleared
// for LCDs with leds set them according to heater status
// TODO should be enabled and disabled and settable from config
- this->panel->lcd->setLed(LED_BED_ON, this->bedtarget > 0);
- this->panel->lcd->setLed(LED_HOTEND_ON, this->hotendtarget > 0);
- this->panel->lcd->setLed(LED_FAN_ON, this->fan_state);
+ THEPANEL->lcd->setLed(LED_BED_ON, this->bedtarget > 0);
+ THEPANEL->lcd->setLed(LED_HOTEND_ON, this->hotendtarget > 0);
+ THEPANEL->lcd->setLed(LED_FAN_ON, this->fan_state);
- if (this->panel->lcd->hasGraphics()) {
+ if (THEPANEL->lcd->hasGraphics()) {
// display the graphical icons below the status are
- //this->panel->lcd->bltGlyph(0, 34, 115, 19, icons);
+ //THEPANEL->lcd->bltGlyph(0, 34, 115, 19, icons);
// for (int i = 0; i < 5; ++i) {
- // this->panel->lcd->bltGlyph(i*24, 38, 23, 19, icons, 15, i*24, 0);
+ // THEPANEL->lcd->bltGlyph(i*24, 38, 23, 19, icons, 15, i*24, 0);
// }
if (this->hotendtarget > 0)
- this->panel->lcd->bltGlyph(8, 38, 20, 19, icons, 15, 0, 0);
+ THEPANEL->lcd->bltGlyph(8, 38, 20, 19, icons, 15, 0, 0);
if (this->bedtarget > 0)
- this->panel->lcd->bltGlyph(32, 38, 23, 19, icons, 15, 64, 0);
+ THEPANEL->lcd->bltGlyph(32, 38, 23, 19, icons, 15, 64, 0);
if(this->fan_state)
- this->panel->lcd->bltGlyph(96, 38, 23, 19, icons, 15, 96, 0);
+ THEPANEL->lcd->bltGlyph(96, 38, 23, 19, icons, 15, 96, 0);
}
}
}
struct pad_progress p = *static_cast<struct pad_progress *>(returned_data);
this->elapsed_time = p.elapsed_secs;
this->sd_pcnt_played = p.percent_complete;
- this->panel->set_playing_file(p.filename);
+ THEPANEL->set_playing_file(p.filename);
} else {
this->elapsed_time = 0;
{
// in menu mode
switch ( line ) {
- case 0: this->panel->lcd->printf("H%03d/%03dc B%03d/%03dc", this->hotendtemp, this->hotendtarget, this->bedtemp, this->bedtarget); break;
- case 1: this->panel->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: this->panel->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: this->panel->lcd->printf("%19s", this->get_status()); break;
+ case 0: THEPANEL->lcd->printf("H%03d/%03dc B%03d/%03dc", this->hotendtemp, this->hotendtarget, this->bedtemp, this->bedtarget); 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;
}
}
const char *WatchScreen::get_status()
{
- if (panel->hasMessage()) {
- return panel->getMessage().c_str();
+ if (THEPANEL->hasMessage()) {
+ return THEPANEL->getMessage().c_str();
}
if (THEKERNEL->pauser->paused())
return "Paused";
- if (panel->is_playing())
- return panel->get_playing_file();
+ if (THEPANEL->is_playing())
+ return THEPANEL->get_playing_file();
if (!THEKERNEL->conveyor->is_queue_empty()) {
return "Printing";