docs: Update Code_Overview.md with removal of printer_state() callback

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-01-08 11:34:09 -05:00
parent 857e7ed5f1
commit 33f5b5f285
1 changed files with 21 additions and 11 deletions

View File

@ -262,16 +262,26 @@ The following may also be useful:
will have been instantiated. The "gcode" and "pins" modules will will have been instantiated. The "gcode" and "pins" modules will
always be available, but for other modules it is a good idea to always be available, but for other modules it is a good idea to
defer the lookup. defer the lookup.
* Define a `printer_state()` method if the code needs to be called * Register event handlers using the `printer.register_event_handler()`
during printer setup and/or shutdown. This method is called twice method if the code needs to be called during "events" raised by
during setup (with "connect" and then "ready") and may also be other printer objects. Each event name is a string, and by
called at run-time (with "shutdown" or "disconnect"). It is common convention it is the name of the main source module that raises the
to perform "printer object" lookup during the "connect" and "ready" event along with a short name for the action that is occurring (eg,
phases. "klippy:connect"). The parameters passed to each event handler are
specific to the given event (as are exception handling and execution
context). Two common startup events are:
* klippy:connect - This event is generated after all printer objects
are instantiated. It is commonly used to lookup other printer
objects, to verify config settings, and to perform an initial
"handshake" with printer hardware.
* klippy:ready - This event is generated after all connect handlers
have completed successfully. It indicates the printer is
transitioning to a state ready to handle normal operations. Do not
raise an error in this callback.
* If there is an error in the user's config, be sure to raise it * If there is an error in the user's config, be sure to raise it
during the `load_config()` or `printer_state("connect")` phases. Use during the `load_config()` or "connect event" phases. Use either
either `raise config.error("my error")` or `raise `raise config.error("my error")` or `raise printer.config_error("my
printer.config_error("my error")` to report the error. error")` to report the error.
* Use the "pins" module to configure a pin on a micro-controller. This * Use the "pins" module to configure a pin on a micro-controller. This
is typically done with something similar to is typically done with something similar to
`printer.lookup_object("pins").setup_pin("pwm", `printer.lookup_object("pins").setup_pin("pwm",
@ -286,8 +296,8 @@ The following may also be useful:
printer object returned from the `load_config()` function. This is printer object returned from the `load_config()` function. This is
important as otherwise the RESTART command may not perform as important as otherwise the RESTART command may not perform as
expected. Also, for similar reasons, if any external files (or expected. Also, for similar reasons, if any external files (or
sockets) are opened then be sure to close them from the sockets) are opened then be sure to register a "klippy:disconnect"
`printer_state("disconnect")` callback. event handler and close them from that callback.
* Avoid accessing the internal member variables (or calling methods * Avoid accessing the internal member variables (or calling methods
that start with an underscore) of other printer objects. Observing that start with an underscore) of other printer objects. Observing
this convention makes it easier to manage future changes. this convention makes it easier to manage future changes.