Beispiel #1
0
        void _check_config()
        {
            var config_parameters = this._send_get_config();

            if (!config_parameters.Get <bool>("is_config"))
            {
                if (this._restart_method == RestartMethod.Rpi_usb)
                {
                    // Only configure mcu after usb power reset
                    this._check_restart("full reset before config");
                }
                // Not configured - send config and issue get_config again
                this._send_config(0);
                config_parameters = this._send_get_config();
                logging.Debug($"Config received crc32 {config_parameters.Get<uint>("crc")}");
                if (!config_parameters.Get <bool>("is_config") && !this.is_fileoutput())
                {
                    throw new McuException($"Unable to configure MCU '{this._name}'");
                }
            }
            else
            {
                var start_reason = (string)this._printer.get_start_args().Get("start_reason");
                if (start_reason == "firmware_restart")
                {
                    throw new McuException($"Failed automated reset of MCU '{this._name}'");
                }
                // Already configured - send init commands
                this._send_config(config_parameters.Get <uint>("crc"));
            }
            // Setup steppersync with the move_count returned by get_config
            this._move_count  = config_parameters.Get <int>("move_count");
            this._steppersync = new steppersync(this._serial.serialqueue, this._stepqueues, this._move_count);
            this._steppersync.set_time(0.0, this._mcu_freq);
        }
Beispiel #2
0
 // Restarts
 void _disconnect()
 {
     _serial.disconnect();
     if (_steppersync != null)
     {
         _steppersync.Dispose();
         _steppersync = null;
     }
 }
Beispiel #3
0
        public Mcu(ConfigWrapper config, ClockSync clocksync)
        {
            this._printer   = config.get_printer();
            this._clocksync = clocksync;
            this._reactor   = _printer.get_reactor();
            this._name      = config.get_name();
            if (this._name.StartsWith("mcu "))
            {
                this._name = this._name.Substring(4);
            }
            this._printer.register_event_handler("klippy:connect", this._connect);
            this._printer.register_event_handler("klippy:shutdown", this._shutdown);
            this._printer.register_event_handler("klippy:disconnect", this._disconnect);
            // Serial port
            this._serialport = config.get("serial", "/dev/ttyS0");
            var baud = 0;

            if (!(this._serialport.StartsWith("/dev/rpmsg_") || this._serialport.StartsWith("/tmp/klipper_host_")))
            {
                baud = (int)config.getint("baud", 250000, minval: 2400);
            }
            this._serial = new SerialReader(this._reactor, this._serialport, baud);
            // Restarts
            this._restart_method = RestartMethod.Command;
            if (baud != 0)
            {
                this._restart_method = config.getEnum <RestartMethod>("restart_method", RestartMethod.None);
            }
            this._reset_cmd          = null;
            this._emergency_stop_cmd = null;
            this._is_shutdown        = false;
            this._shutdown_msg       = "";
            // Config building
            this._printer.lookup_object <PrinterPins>("pins").register_chip(this._name, this);
            this._oid_count        = 0;
            this._config_callbacks = new List <Action>();
            this._init_cmds        = new List <string>();
            this._config_cmds      = new List <string>();
            this._pin_map          = config.get("pin_map", null);
            this._custom           = config.get("custom", "");
            this._mcu_freq         = 0.0;
            // Move command queuing
            this._max_stepper_error = config.getfloat("max_stepper_error", 2.5E-05, minval: 0.0);
            this._move_count        = 0;
            this._stepqueues        = new List <stepcompress>();
            this._steppersync       = null;
            // Stats
            this._stats_sumsq_base = 0.0;
            this._mcu_tick_avg     = 0.0;
            this._mcu_tick_stddev  = 0.0;
            this._mcu_tick_awake   = 0.0;
        }