Ejemplo n.º 1
0
template<> PinName Arguments::getArg<PinName>(void) {
    index++;
    return parse_pins(argv[index]);
}
Ejemplo n.º 2
0
void Panel::on_module_loaded()
{
    // Exit if this module is not enabled
    if ( !THEKERNEL->config->value( panel_checksum, enable_checksum )->by_default(false)->as_bool() ) {
        delete this;
        return;
    }

    // Initialise the LCD, see which LCD to use
    if (this->lcd != NULL) delete this->lcd;
    int lcd_cksm = get_checksum(THEKERNEL->config->value(panel_checksum, lcd_checksum)->by_default("reprap_discount_glcd")->as_string());

    // Note checksums are not const expressions when in debug mode, so don't use switch
    if (lcd_cksm == rrd_glcd_checksum) {
        this->lcd = new ReprapDiscountGLCD();
    } else if (lcd_cksm == st7565_glcd_checksum) {
        this->lcd = new ST7565();
    } else if (lcd_cksm == viki2_checksum) {
        this->lcd = new ST7565(1); // variant 1
    } else if (lcd_cksm == mini_viki2_checksum) {
        this->lcd = new ST7565(2); // variant 2
    } else if (lcd_cksm == universal_adapter_checksum) {
        this->lcd = new UniversalAdapter();
    } else {
        // no known lcd type defined
        delete this;
        return;
    }

    // external sd
    if(THEKERNEL->config->value( panel_checksum, ext_sd_checksum )->by_default(false)->as_bool()) {
        this->external_sd_enable= true;
        // external sdcard detect
        this->sdcd_pin.from_string(THEKERNEL->config->value( panel_checksum, ext_sd_checksum, sdcd_pin_checksum )->by_default("nc")->as_string())->as_input();
        this->extsd_spi_channel = THEKERNEL->config->value(panel_checksum, ext_sd_checksum, spi_channel_checksum)->by_default(0)->as_number();
        string s= THEKERNEL->config->value( panel_checksum, ext_sd_checksum, spi_cs_pin_checksum)->by_default("2.8")->as_string();
        s= "P" + s; // Pinnames need to be Px_x
        this->extsd_spi_cs= parse_pins(s.c_str());
        this->register_for_event(ON_SECOND_TICK);
    }

    // these need to be called here as they need the config cache loaded as they enumerate modules
    this->custom_screen= new CustomScreen();

    // some panels may need access to this global info
    this->lcd->setPanel(this);

    // the number of screen lines the panel supports
    this->screen_lines = this->lcd->get_screen_lines();

    // some encoders may need more clicks to move menu, this is a divisor and is in config as it is
    // an end user usability issue
    this->menu_offset = THEKERNEL->config->value( panel_checksum, menu_offset_checksum )->by_default(0)->as_number();

    // override default encoder resolution if needed
    this->encoder_click_resolution = THEKERNEL->config->value( panel_checksum, encoder_resolution_checksum )->by_default(this->lcd->getEncoderResolution())->as_number();

    // load jogging feedrates in mm/min
    jogging_speed_mm_min[0] = THEKERNEL->config->value( panel_checksum, jog_x_feedrate_checksum )->by_default(3000.0f)->as_number();
    jogging_speed_mm_min[1] = THEKERNEL->config->value( panel_checksum, jog_y_feedrate_checksum )->by_default(3000.0f)->as_number();
    jogging_speed_mm_min[2] = THEKERNEL->config->value( panel_checksum, jog_z_feedrate_checksum )->by_default(300.0f )->as_number();

    // load the default preset temeratures
    default_hotend_temperature = THEKERNEL->config->value( panel_checksum, hotend_temp_checksum )->by_default(185.0f )->as_number();
    default_bed_temperature    = THEKERNEL->config->value( panel_checksum, bed_temp_checksum    )->by_default(60.0f  )->as_number();


    this->up_button.up_attach(    this, &Panel::on_up );
    this->down_button.up_attach(  this, &Panel::on_down );
    this->click_button.up_attach( this, &Panel::on_select );
    this->back_button.up_attach(  this, &Panel::on_back );


    //setting longpress_delay
    int longpress_delay =  THEKERNEL->config->value( panel_checksum, longpress_delay_checksum )->by_default(0)->as_number();
    this->up_button.set_longpress_delay(longpress_delay);
    this->down_button.set_longpress_delay(longpress_delay);
//    this->click_button.set_longpress_delay(longpress_delay);
//    this->back_button.set_longpress_delay(longpress_delay);
//    this->pause_button.set_longpress_delay(longpress_delay);


    THEKERNEL->slow_ticker->attach( 50,  this, &Panel::button_tick );
    if(lcd->encoderReturnsDelta()) {
        // panel handles encoder pins and returns a delta
        THEKERNEL->slow_ticker->attach( 10, this, &Panel::encoder_tick );
    } else {
        // read encoder pins
        THEKERNEL->slow_ticker->attach( 1000, this, &Panel::encoder_check );
    }

    // Register for events
    this->register_for_event(ON_IDLE);
    this->register_for_event(ON_MAIN_LOOP);
    this->register_for_event(ON_SET_PUBLIC_DATA);

    // Refresh timer
    THEKERNEL->slow_ticker->attach( 20, this, &Panel::refresh_tick );
}