![]() |
CAPS Universe documentation
1.0.4
All you need to know to be successful
|
Functions to monitor the attached USB printer device. More...
Functions | |
| static bool | caps_drv_printer_is_busy (unsigned status) |
| static bool | caps_drv_printer_is_error (unsigned status) |
| static bool | caps_drv_printer_is_oop (unsigned status) |
| static bool | caps_drv_status_bit_changed (unsigned old_status, unsigned new_status, unsigned check_bit) |
| static void | caps_drv_active_state_enter (struct caps_pp_handle *instance, unsigned prn_status, int printing) |
| static void | caps_drv_error_state_enter (struct caps_pp_handle *instance, unsigned prn_status) |
| void | caps_drv_printer_tweak_status (struct caps_drv *cdrv) |
| static int | caps_drv_printer_status_query (int fd, unsigned *prn_status) |
| int | caps_drv_is_offline (struct caps_drv *cdrv) |
| int | caps_drv_is_fault_state (struct caps_drv *cdrv) |
| int | caps_drv_is_empty (struct caps_drv *cdrv) |
| int | caps_drv_printer_check (struct caps_drv *cdrv) |
The monitor isn't perfect when reporting the printer's state. It tries its best, but some states aren't distinguishable and thus reported wrong. But it seems it is good enough to have some important information at hand (like "out of paper" for example).
|
static |
Check if the printer is busy
| [in] | status | Current status read via ioctl() from the printer |
| true | If the printer signals it is busy |
| false | If the printer signals it is idle |
Interpreting these status bits is always confusing, since some are of negative logic and some other not.
The busy bit (LP_PBUSY) is '1' if the printer is busy.
|
static |
Check if the printer is in error state
| [in] | status | Current status read via ioctl() from the printer |
| true | If the printer signals it is in an error state |
| false | If the printer signals it is not in an error state |
Interpreting these status bits is always confusing, since some are of negative logic and some other not.
The error bit (LP_PERRORP) is '0' if the printer is in error state.
|
static |
Check if the printer is out of paper
| [in] | status | Current status read via ioctl() from the printer |
| true | If the printer signals it is out of paper |
| false | If the printer signals it is out of paper |
Interpreting these status bits is always confusing, since some are of negative logic and some other not.
The out of paper bit (LP_POUTPA) is '1' if the printer is out of paper.
|
static |
Check if specific bits in two status differ
| [in] | old_status | One status |
| [in] | new_status | A second status |
| [in] | check_bit | Bit mask of to be checked bits |
| true | If the status bit(s) differ |
| false | If the status bit(s) is/are still the same |
|
static |
Setup the next printer state report to reflect its real state (printing or power save)
| [in] | instance | Connection info to the printing coordinator |
| [in] | prn_status | Current printer's state |
| [in] | printing | '0' if currently no job is printed, else currently a job is printed |
If we return from a printer error state into the printer active state, we need to report the correct printer's and the driver's state . This routine detects if currently a job is processed and returns to the PRINTING state, else in the POWER-SAVE state.
|
static |
Generate an error report based on the status bits of the USB printer
| [in] | instance | Connection info to the printing coordinator |
| [in] | prn_status | Current printer's state |
Assumption is: the printer device reports:
| void caps_drv_printer_tweak_status | ( | struct caps_drv * | cdrv | ) |
Eval the printer's monitoring setting
| [in,out] | cdrv | Full state information |
This function deals with the setting described in Feature: control printer monitoring
It always falls back to "never", if it detects the file descriptor points to a file instead of a printer.
Sets up two of the printer tweaks: CAPS_TWEAK_SKIP_STATUS_WHEN_PRINTING and CAPS_TWEAK_SKIP_STATUS
The default is "always" and is documented in Feature: control printer monitoring
|
static |
Query and return the status of a USB printer
| [in] | fd | File descriptor to access the printer |
| [out] | prn_status | The printer's current status |
| 0 | The prn_status contains the printer's current status |
| -ENODEV | The printer device behind the file descriptor seems gone (e.g. offline) |
| -EBADF | fd is invalid (should not happen) |
| negative | More possible error codes from an ioctl() call |
Only three bits are known to work (at least with my printer):
| Bit No | Bit Name | Bit description | Mask Macro |
|---|---|---|---|
| 7 | BUSY | low = idle, high = busy | LP_PBUSY |
| 5 | OOP | high = Out of Paper | LP_POUTPA |
| 3 | ERROR | high = Error | LP_PERRORP |
-ENODEV return value case. Printers can disappear at any time. | int caps_drv_printer_check | ( | struct caps_drv * | cdrv | ) |
Monitor the state of the attached printer device and create reports for the printing coordinator accordingly
| [in,out] | cdrv | Full state information |
| '0' | printer is ready to print jobs |
| -EBUSY | The printer isn't ready to print jobs, due to an error (out of paper for example) |
| -ENODEV | The printer is gone |
| -EINVAL | Terminate current job, but continue. |
This function monitors the state of the attached printer and creates printer state reports for the printing coordinator. The main goal is to inform the user in a precise way about the state of the printer. You should call it periodically.
Within three bits the printer informs the host about its current state.
The important facts are the transitions between these static states. Most of them need a report to the printing coordinator about the transition.
This means the printer changed from some state of waiting for data into an active state (e.g. printing) or into an error state. Or - at least in the case of my printer - if it moves into the power save mode. All of these transitions need a new state report.
Example: you start a new printing job
Example: you remove the paper from your idling printer
Example: your printer is in trouble somehow
This always means the printer has moved to active idle and waits for data and a new state must be reported.
This always means the printer is still in active idle mode and waits for data. No new state needs to be reported.
This means the printer has left the error state. Maybe it now immediately continues to print or needs first a warm-up phase again to do so.
This means the printer changed into an error state, coming from state printing or state warm-up (but not from state idle, because then the 'Busy' status changes first)
Here the user can load new paper, but there is still a paper jam in the printer.
You start a new printing job and then the paper tray is empty
You start a new printing job and the paper jams
You start a new printing job and it finishes
Your printer is idling for a long time and enters a power save mode.