mirror of
https://git.planet-casio.com/Lephenixnoir/fxsdk.git
synced 2024-12-28 04:23:37 +01:00
libfxlink: add status functions to avoid looking into fdev fields
This commit is contained in:
parent
394d05726d
commit
7b77fb9c0b
4 changed files with 27 additions and 5 deletions
|
@ -469,8 +469,8 @@ bool TUI_core_update(bool allow_console, bool auto_refresh, bool *has_command)
|
||||||
struct fxlink_device *fdev = &TUI.devices.devices[i];
|
struct fxlink_device *fdev = &TUI.devices.devices[i];
|
||||||
|
|
||||||
/* Check for devices ready to connect to */
|
/* Check for devices ready to connect to */
|
||||||
if(fdev->status == FXLINK_FDEV_STATUS_IDLE && fdev->comm
|
if(fxlink_device_ready_to_connect(fdev)
|
||||||
&& fdev->comm->ep_bulk_IN != 0xff) {
|
&& fxlink_device_has_fxlink_interface(fdev)) {
|
||||||
if(fxlink_device_claim_fxlink(fdev))
|
if(fxlink_device_claim_fxlink(fdev))
|
||||||
fxlink_device_start_bulk_IN(fdev);
|
fxlink_device_start_bulk_IN(fdev);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
# Locate the library file and includes
|
# Locate the library file and includes
|
||||||
|
|
||||||
message("test: $ENV{HOME}/.local/lib $ENV{FXSDK_PATH}/lib")
|
|
||||||
find_library(
|
find_library(
|
||||||
LIBFXLINK_PATH "fxlink"
|
LIBFXLINK_PATH "fxlink"
|
||||||
HINTS "$ENV{HOME}/.local/lib" "$ENV{FXSDK_PATH}/lib"
|
HINTS "$ENV{HOME}/.local/lib" "$ENV{FXSDK_PATH}/lib"
|
||||||
|
|
|
@ -280,10 +280,23 @@ void fxlink_device_analysis_2(struct fxlink_device *fdev)
|
||||||
fdev->status = FXLINK_FDEV_STATUS_IDLE;
|
fdev->status = FXLINK_FDEV_STATUS_IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool fxlink_device_ready_to_connect(struct fxlink_device const *fdev)
|
||||||
|
{
|
||||||
|
bool status = (fdev->status == FXLINK_FDEV_STATUS_IDLE) ||
|
||||||
|
(fdev->status == FXLINK_FDEV_STATUS_CONNECTED);
|
||||||
|
return fdev->calc && fdev->comm && status;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool fxlink_device_has_fxlink_interface(struct fxlink_device const *fdev)
|
||||||
|
{
|
||||||
|
return fdev->calc && fdev->comm && (fdev->comm->ep_bulk_IN != 0xff);
|
||||||
|
}
|
||||||
|
|
||||||
bool fxlink_device_claim_fxlink(struct fxlink_device *fdev)
|
bool fxlink_device_claim_fxlink(struct fxlink_device *fdev)
|
||||||
{
|
{
|
||||||
/* Only connect to calculators with an fxlink interface */
|
if(!fxlink_device_ready_to_connect(fdev) ||
|
||||||
if(!fdev->comm || fdev->status != FXLINK_FDEV_STATUS_IDLE)
|
!fxlink_device_has_fxlink_interface(fdev) ||
|
||||||
|
fdev->comm->claimed)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Allocate transfer data */
|
/* Allocate transfer data */
|
||||||
|
|
|
@ -195,6 +195,16 @@ struct fxlink_comm {
|
||||||
bool cancelled_OUT;
|
bool cancelled_OUT;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Check whether the device is ready to have interfaces claimed. This function
|
||||||
|
only checks that the device is a calculator and could be opened; it doesn't
|
||||||
|
guarantee that claiming the interfaces will succeed. This function returns
|
||||||
|
true even after an interface has been claimed since multiple interfaces can
|
||||||
|
be claimed at the same time. */
|
||||||
|
bool fxlink_device_ready_to_connect(struct fxlink_device const *fdev);
|
||||||
|
|
||||||
|
/* Check whether the device exposes an fxlink interface. */
|
||||||
|
bool fxlink_device_has_fxlink_interface(struct fxlink_device const *fdev);
|
||||||
|
|
||||||
/* Claim the fxlink interface (for a device that has one). Returns false and
|
/* Claim the fxlink interface (for a device that has one). Returns false and
|
||||||
sets the status to ERROR on failure. */
|
sets the status to ERROR on failure. */
|
||||||
bool fxlink_device_claim_fxlink(struct fxlink_device *fdev);
|
bool fxlink_device_claim_fxlink(struct fxlink_device *fdev);
|
||||||
|
|
Loading…
Reference in a new issue