jni增加获取设备配置的接口

This commit is contained in:
luoliangyi 2023-11-04 12:59:56 +08:00
parent 62966eaf71
commit 8f3ede3bdb
4 changed files with 218 additions and 20 deletions

View File

@ -47,4 +47,5 @@ Java_com_easing_java_HGScannerLib_CloseDevice
Java_com_easing_java_HGScannerLib_GetDeviceSN
Java_com_easing_java_HGScannerLib_GetDeviceFWVersion
Java_com_easing_java_HGScannerLib_StartDeviceScan
Java_com_easing_java_HGScannerLib_StopDeviceScan
Java_com_easing_java_HGScannerLib_StopDeviceScan
Java_com_easing_java_HGScannerLib_GetDeviceParamGroupList

View File

@ -112,11 +112,12 @@ void hg_settingdialog::apply_scheme(SANE_Handle dev, LPSANEAPI api, gb::sane_con
if (!desc)
continue;
if (0 == strcmp(SANE_STD_OPT_NAME_RESTORE, desc->name))
api->sane_control_option_api(dev, i, SANE_ACTION_SET_VALUE, NULL, NULL);
if (desc->type == SANE_TYPE_BUTTON || desc->type == SANE_TYPE_GROUP)
continue;
api->sane_control_option_api(dev, i, SANE_ACTION_SET_AUTO, nullptr, nullptr);
SOD sod;
sod.id = i;
sod.desc = desc;
@ -2760,10 +2761,11 @@ void hg_settingdialog::restoreDeviceScheme()
if (!opt)
continue;
if (opt->type == SANE_TYPE_BUTTON || opt->type == SANE_TYPE_GROUP)
continue;
m_saneAPI.sane_control_option_api(m_devHandle, i, SANE_ACTION_SET_AUTO, NULL, NULL);
if (0 == strcmp(SANE_STD_OPT_NAME_RESTORE, opt->name))
{
m_saneAPI.sane_control_option_api(m_devHandle, i, SANE_ACTION_SET_VALUE, NULL, NULL);
break;
}
}
}

View File

@ -85,11 +85,11 @@ extern "C" JNIEXPORT jobject JNICALL Java_com_easing_java_HGScannerLib_GetImageI
printf("ret=%d\n", ret);
if (ret)
{
env->SetIntField(imgInfo, env->GetFieldID(cls, "width", "I"), imgInfo2.width);
env->SetIntField(imgInfo, env->GetFieldID(cls, "height", "I"), imgInfo2.height);
env->SetIntField(imgInfo, env->GetFieldID(cls, "type", "I"), imgInfo2.type);
env->SetIntField(imgInfo, env->GetFieldID(cls, "widthStep", "I"), imgInfo2.widthStep);
env->SetIntField(imgInfo, env->GetFieldID(cls, "origin", "I"), imgInfo2.origin);
env->SetIntField(imgInfo, env->GetFieldID(cls, "width", "I"), (jint)imgInfo2.width);
env->SetIntField(imgInfo, env->GetFieldID(cls, "height", "I"), (jint)imgInfo2.height);
env->SetIntField(imgInfo, env->GetFieldID(cls, "type", "I"), (jint)imgInfo2.type);
env->SetIntField(imgInfo, env->GetFieldID(cls, "widthStep", "I"), (jint)imgInfo2.widthStep);
env->SetIntField(imgInfo, env->GetFieldID(cls, "origin", "I"), (jint)imgInfo2.origin);
}
printf("\n");
@ -143,8 +143,8 @@ extern "C" JNIEXPORT jobject JNICALL Java_com_easing_java_HGScannerLib_GetImageD
printf("ret=%d\n", ret);
if (ret)
{
env->SetIntField(imgDpi, env->GetFieldID(cls, "xDpi", "I"), xDpi);
env->SetIntField(imgDpi, env->GetFieldID(cls, "yDpi", "I"), yDpi);
env->SetIntField(imgDpi, env->GetFieldID(cls, "xDpi", "I"), (jint)xDpi);
env->SetIntField(imgDpi, env->GetFieldID(cls, "yDpi", "I"), (jint)yDpi);
}
printf("\n");
@ -253,6 +253,7 @@ extern "C" JNIEXPORT jobjectArray JNICALL Java_com_easing_java_HGScannerLib_GetD
printf("\nJava_com_easing_java_HGScannerLib_GetDeviceNameList\n");
jobjectArray devNameList;
jclass cls = env->FindClass("java/lang/String");
HGChar** devNameList2 = HGLib_GetDeviceNameList();
printf("devNameList=0x%p\n", devNameList2);
@ -268,8 +269,6 @@ extern "C" JNIEXPORT jobjectArray JNICALL Java_com_easing_java_HGScannerLib_GetD
}
printf("count=%u\n", count);
jclass cls = env->FindClass("java/lang/String");
devNameList = env->NewObjectArray(count, cls, env->NewStringUTF(NULL));
HGUInt i = 0;
@ -284,8 +283,6 @@ extern "C" JNIEXPORT jobjectArray JNICALL Java_com_easing_java_HGScannerLib_GetD
else
{
printf("cound=%u\n", 0);
jclass cls = env->FindClass("java/lang/String");
devNameList = env->NewObjectArray(0, cls, env->NewStringUTF(NULL));
}
@ -532,3 +529,106 @@ extern "C" JNIEXPORT jboolean JNICALL Java_com_easing_java_HGScannerLib_StopDevi
printf("\n");
return (jboolean)ret;
}
extern "C" JNIEXPORT jobjectArray JNICALL Java_com_easing_java_HGScannerLib_GetDeviceParamGroupList(
JNIEnv* env, jclass clazz, jlong dev)
{
(void)clazz;
printf("\nJava_com_easing_java_HGScannerLib_GetDeviceParamGroupList\n");
jobjectArray devParamGroupList;
jclass clsDeviceParamGroup = env->FindClass("com/easing/java/HGLibDeviceParamGroup");
jmethodID initDeviceParamGroup = env->GetMethodID(clsDeviceParamGroup, "<init>", "()V");
jclass clsDeviceParam = env->FindClass("com/easing/java/HGLibDeviceParam");
jmethodID initDeviceParam = env->GetMethodID(clsDeviceParam, "<init>", "()V");
jclass clsIntValueRange = env->FindClass("com/easing/java/HGLibDeviceIntValueRange");
jmethodID initIntValueRange = env->GetMethodID(clsIntValueRange, "<init>", "()V");
jclass clsDoubleValueRange = env->FindClass("com/easing/java/HGLibDeviceDoubleValueRange");
jmethodID initDoubleValueRange = env->GetMethodID(clsDoubleValueRange, "<init>", "()V");
HGUInt count = 0;
HGLibDeviceParamGroup* devParamGroupList2 = HGLib_GetDeviceParamGroupList((HGLibDevice)dev, &count);
if (NULL != devParamGroupList2)
{
devParamGroupList = env->NewObjectArray(count, clsDeviceParamGroup, env->NewObject(clsDeviceParamGroup, initDeviceParamGroup));
for (HGUInt i = 0; i < count; ++i)
{
jobject devParamGroup = env->NewObject(clsDeviceParamGroup, initDeviceParamGroup);
env->SetIntField(devParamGroup, env->GetFieldID(clsDeviceParamGroup, "group", "I"), (jint)devParamGroupList2[i].group);
jobjectArray devParamList = env->NewObjectArray(devParamGroupList2[i].paramCount, clsDeviceParam, env->NewObject(clsDeviceParam, initDeviceParam));
for (HGUInt j = 0; j < devParamGroupList2[i].paramCount; ++j)
{
jobject devParam = env->NewObject(clsDeviceParam, initDeviceParam);
env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "option", "I"), (jint)devParamGroupList2[i].param[j].option);
env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "type", "I"), (jint)devParamGroupList2[i].param[j].type);
if (HGLIB_OPTION_VALUETYPE_INT == devParamGroupList2[i].param[j].type)
{
env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "intValue", "I"), (jint)devParamGroupList2[i].param[j].intValue);
}
else if (HGLIB_OPTION_VALUETYPE_ENUM == devParamGroupList2[i].param[j].type)
{
env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "enumValue", "I"), (jint)devParamGroupList2[i].param[j].enumValue);
}
else if (HGLIB_OPTION_VALUETYPE_DOUBLE == devParamGroupList2[i].param[j].type)
{
env->SetDoubleField(devParam, env->GetFieldID(clsDeviceParam, "doubleValue", "D"), (jdouble)devParamGroupList2[i].param[j].doubleValue);
}
else if (HGLIB_OPTION_VALUETYPE_BOOL == devParamGroupList2[i].param[j].type)
{
env->SetBooleanField(devParam, env->GetFieldID(clsDeviceParam, "boolValue", "Z"), (jboolean)devParamGroupList2[i].param[j].boolValue);
}
env->SetIntField(devParam, env->GetFieldID(clsDeviceParam, "rangeType", "I"), (jint)devParamGroupList2[i].param[j].rangeType);
if (HGLIB_OPTION_VALUERANGETYPE_INTLIST == devParamGroupList2[i].param[j].rangeType)
{
jintArray intValueList = env->NewIntArray(devParamGroupList2[i].param[j].intValueList.count);
env->SetIntArrayRegion(intValueList, 0, devParamGroupList2[i].param[j].intValueList.count, (jint*)devParamGroupList2[i].param[j].intValueList.value);
env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "intValueList", "[I"), intValueList);
}
else if (HGLIB_OPTION_VALUERANGETYPE_ENUMLIST == devParamGroupList2[i].param[j].rangeType)
{
jintArray enumValueList = env->NewIntArray(devParamGroupList2[i].param[j].enumValueList.count);
env->SetIntArrayRegion(enumValueList, 0, devParamGroupList2[i].param[j].enumValueList.count, (jint*)devParamGroupList2[i].param[j].enumValueList.value);
env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "enumValueList", "[I"), enumValueList);
}
else if (HGLIB_OPTION_VALUERANGETYPE_DOUBLELIST == devParamGroupList2[i].param[j].rangeType)
{
jdoubleArray doubleValueList = env->NewDoubleArray(devParamGroupList2[i].param[j].doubleValueList.count);
env->SetDoubleArrayRegion(doubleValueList, 0, devParamGroupList2[i].param[j].doubleValueList.count, (jdouble*)devParamGroupList2[i].param[j].doubleValueList.value);
env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "doubleValueList", "[D"), doubleValueList);
}
else if (HGLIB_OPTION_VALUERANGETYPE_INTRANGE == devParamGroupList2[i].param[j].rangeType)
{
jobject intValueRange = env->NewObject(clsIntValueRange, initIntValueRange);
env->SetIntField(intValueRange, env->GetFieldID(clsIntValueRange, "minValue", "I"), (jint)devParamGroupList2[i].param[j].intValueRange.minValue);
env->SetIntField(intValueRange, env->GetFieldID(clsIntValueRange, "maxValue", "I"), (jint)devParamGroupList2[i].param[j].intValueRange.maxValue);
env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "intValueRange", "Lcom/easing/java/HGLibDeviceIntValueRange;"), intValueRange);
}
else if (HGLIB_OPTION_VALUERANGETYPE_DOUBLERANGE == devParamGroupList2[i].param[j].rangeType)
{
jobject doubleValueRange = env->NewObject(clsDoubleValueRange, initDoubleValueRange);
env->SetDoubleField(doubleValueRange, env->GetFieldID(clsDoubleValueRange, "minValue", "D"), (jdouble)devParamGroupList2[i].param[j].doubleValueRange.minValue);
env->SetDoubleField(doubleValueRange, env->GetFieldID(clsDoubleValueRange, "maxValue", "D"), (jdouble)devParamGroupList2[i].param[j].doubleValueRange.maxValue);
env->SetObjectField(devParam, env->GetFieldID(clsDeviceParam, "doubleValueRange", "Lcom/easing/java/HGLibDeviceDoubleValueRange;"), doubleValueRange);
}
env->SetObjectArrayElement(devParamList, j, devParam);
}
env->SetObjectField(devParamGroup, env->GetFieldID(clsDeviceParamGroup, "params", "[Lcom/easing/java/HGLibDeviceParam;"), devParamList);
env->SetObjectArrayElement(devParamGroupList, i, devParamGroup);
}
HGLib_ReleaseDeviceParamGroupList(devParamGroupList2, count);
}
else
{
devParamGroupList = env->NewObjectArray(0, clsDeviceParamGroup, env->NewObject(clsDeviceParamGroup, initDeviceParamGroup));
}
return devParamGroupList;
}

View File

@ -20,6 +20,38 @@ class HGLibImageDpi {
public int yDpi;
}
class HGLibDeviceIntValueRange {
public int minValue;
public int maxValue;
}
class HGLibDeviceDoubleValueRange {
public double minValue;
public double maxValue;
}
class HGLibDeviceParam {
public int option;
public int type;
public int intValue;
public int enumValue;
public double doubleValue;
public boolean boolValue;
public int rangeType;
public int[] intValueList;
public int[] enumValueList;
public double[] doubleValueList;
public HGLibDeviceIntValueRange intValueRange;
public HGLibDeviceDoubleValueRange doubleValueRange;
}
class HGLibDeviceParamGroup {
public int group;
public HGLibDeviceParam[] params;
}
public class HGScannerLib {
static {
@ -42,7 +74,11 @@ public class HGScannerLib {
public native String GetDeviceFWVersion(long dev);
public native boolean StartDeviceScan(long dev);
public native boolean StopDeviceScan(long dev);
public native HGLibDeviceParamGroup[] GetDeviceParamGroupList(long dev);
public native HGLibDeviceParam GetDeviceParam(long dev, int option);
public native boolean SetDeviceParam(long dev, HGLibDeviceParam deviceParam);
public native boolean ResetDeviceParam(long dev);
;
public void onDeviceHotPlugEvent(int event, String deviceName) {
System.out.println("onDeviceHotPlugEvent");
System.out.println("event=" + event);
@ -110,7 +146,66 @@ public class HGScannerLib {
String fwVersion = inst.GetDeviceFWVersion(dev);
System.out.println("fwVersion=" + fwVersion);
inst.StartDeviceScan(dev);
HGLibDeviceParamGroup[] devParamGroups = inst.GetDeviceParamGroupList(dev);
for (int i = 0; i < devParamGroups.length; ++i)
{
System.out.println("devParamGroups group=" + devParamGroups[i].group + ":");
for (int j = 0; j < devParamGroups[i].params.length; ++j)
{
System.out.println(" devParam option=" + devParamGroups[i].params[j].option);
System.out.println(" type=" + devParamGroups[i].params[j].type);
if (1 == devParamGroups[i].params[j].type)
System.out.println(" intValue=" + devParamGroups[i].params[j].intValue);
else if (2 == devParamGroups[i].params[j].type)
System.out.println(" enumValue=" + devParamGroups[i].params[j].enumValue);
else if (3 == devParamGroups[i].params[j].type)
System.out.println(" doubleValue=" + devParamGroups[i].params[j].doubleValue);
else if (4 == devParamGroups[i].params[j].type)
System.out.println(" boolValue=" + devParamGroups[i].params[j].boolValue);
System.out.println(" rangeType=" + devParamGroups[i].params[j].rangeType);
if (1 == devParamGroups[i].params[j].rangeType)
{
System.out.println(" intValueList:");
for (int k = 0; k < devParamGroups[i].params[j].intValueList.length; ++k)
{
System.out.println(" " + devParamGroups[i].params[j].intValueList[k]);
}
}
else if (2 == devParamGroups[i].params[j].rangeType)
{
System.out.println(" enumValueList:");
for (int k = 0; k < devParamGroups[i].params[j].enumValueList.length; ++k)
{
System.out.println(" " + devParamGroups[i].params[j].enumValueList[k]);
}
}
else if (3 == devParamGroups[i].params[j].rangeType)
{
System.out.println(" doubleValueList:");
for (int k = 0; k < devParamGroups[i].params[j].doubleValueList.length; ++k)
{
System.out.println(" " + devParamGroups[i].params[j].doubleValueList[k]);
}
}
else if (4 == devParamGroups[i].params[j].rangeType)
{
System.out.println(" intValueRange:");
System.out.println(" min:" + devParamGroups[i].params[j].intValueRange.minValue);
System.out.println(" max:" + devParamGroups[i].params[j].intValueRange.maxValue);
}
else if (5 == devParamGroups[i].params[j].rangeType)
{
System.out.println(" doubleValueRange:");
System.out.println(" min:" + devParamGroups[i].params[j].doubleValueRange.minValue);
System.out.println(" max:" + devParamGroups[i].params[j].doubleValueRange.maxValue);
}
}
}
//inst.StartDeviceScan(dev);
//inst.StopDeviceScan(dev);