Commit 000e3496 authored by pengguangpu's avatar pengguangpu

硬件开放平台初始工程

parents
*.iml
.gradle
/local.properties
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
.DS_Store
/build
/captures
.externalNativeBuild
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<Objective-C-extensions>
<file>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
</file>
<class>
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
</class>
<extensions>
<pair source="cpp" header="h" fileNamingConvention="NONE" />
<pair source="c" header="h" fileNamingConvention="NONE" />
</extensions>
</Objective-C-extensions>
</code_scheme>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
<option value="$PROJECT_DIR$/print" />
<option value="$PROJECT_DIR$/weighing" />
</set>
</option>
<option name="resolveModulePerSourceSet" value="false" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
<option name="id" value="Android" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" />
<option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.miya.hardware"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//打印sdk
api project(':print')
//称重sdk
api project(':weighing')
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.miya.hardware;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.miya.hardware", appContext.getPackageName());
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.miya.hardware">
<application
android:name=".app.HardwareApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".HardwareActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".WeighingActivity" />
<activity android:name=".PrintActivity" />
</application>
</manifest>
\ No newline at end of file
package com.miya.hardware;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
public class HardwareActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
}
package com.miya.hardware;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
public class PrintActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_print);
}
}
package com.miya.hardware;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
public class WeighingActivity extends Activity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weighing);
}
}
package com.miya.hardware.app;
import android.app.Application;
import com.miya.weighing.WeighingManager;
public class HardwareApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
WeighingManager.getInstance().init(this);
}
}
<vector xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:aapt="http://schemas.android.com/aapt"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
<path
android:fillType="evenOdd"
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
android:strokeColor="#00000000"
android:strokeWidth="1">
<aapt:attr name="android:fillColor">
<gradient
android:endX="78.5885"
android:endY="90.9159"
android:startX="48.7653"
android:startY="61.0927"
android:type="linear">
<item
android:color="#44000000"
android:offset="0.0" />
<item
android:color="#00000000"
android:offset="1.0" />
</gradient>
</aapt:attr>
</path>
<path
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
android:strokeColor="#00000000"
android:strokeWidth="1" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportHeight="108"
android:viewportWidth="108">
<path
android:fillColor="#26A69A"
android:pathData="M0,0h108v108h-108z" />
<path
android:fillColor="#00000000"
android:pathData="M9,0L9,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,0L19,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M29,0L29,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M39,0L39,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M49,0L49,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M59,0L59,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M69,0L69,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M79,0L79,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M89,0L89,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M99,0L99,108"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,9L108,9"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,19L108,19"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,29L108,29"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,39L108,39"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,49L108,49"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,59L108,59"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,69L108,69"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,79L108,79"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,89L108,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M0,99L108,99"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,29L89,29"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,39L89,39"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,49L89,49"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,59L89,59"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,69L89,69"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M19,79L89,79"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M29,19L29,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M39,19L39,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M49,19L49,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M59,19L59,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M69,19L69,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
<path
android:fillColor="#00000000"
android:pathData="M79,19L79,89"
android:strokeColor="#33FFFFFF"
android:strokeWidth="0.8" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.constraint.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
</resources>
<resources>
<string name="app_name">hardware</string>
</resources>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
package com.miya.hardware;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Mon Dec 17 10:16:39 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.miya.print;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.miya.print.test", appContext.getPackageName());
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.miya.print" />
<resources>
<string name="app_name">print</string>
</resources>
package com.miya.print;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
include ':app', ':print', ':weighing'
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//商米称重驱动
implementation files('libs/scale-service-part-lib-1.1.jar')
//创捷称重驱动jar包(自制)
implementation files('libs/chuangjieweighing.jar')
//映泰机器称重驱动jar包(自制)
implementation files('libs/yingtaiweighing.jar')
}
E:\SDK3\app\.externalNativeBuild\ndkBuild\debug\obj/local/armeabi-v7a/objs/serial_port/SerialPort.o: \
E:/SDK3/app/src/main/jni/SerialPort.c \
E:/SDK3/app/src/main/jni/SerialPort.h
E:/SDK3/app/src/main/jni/SerialPort.h:
E:\SDK3\app\.externalNativeBuild\ndkBuild\debug\obj/local/armeabi/objs/serial_port/SerialPort.o: \
E:/SDK3/app/src/main/jni/SerialPort.c \
E:/SDK3/app/src/main/jni/SerialPort.h
E:/SDK3/app/src/main/jni/SerialPort.h:
E:\SDK3\app\.externalNativeBuild\ndkBuild\debug\obj/local/mips/objs/serial_port/SerialPort.o: \
E:/SDK3/app/src/main/jni/SerialPort.c \
E:/SDK3/app/src/main/jni/SerialPort.h
E:/SDK3/app/src/main/jni/SerialPort.h:
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.miya.weighing;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.miya.weighing.test", appContext.getPackageName());
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.miya.weighing" />
package com.hisense.optionalservice.aidl;
interface OnDataReceiveListener {
void onDataReceive(float weight, int size);
}
package com.hisense.optionalservice.aidl;
import com.hisense.optionalservice.aidl.UartScale;
interface OptionalApi {
UartScale getUartScale();
}
package com.hisense.optionalservice.aidl;
import com.hisense.optionalservice.aidl.OnDataReceiveListener;
interface UartScale {
void resetZero();
void readWeight();
int open(String path, int baudrate, int flowCtl);
void close();
void setOnDataReceiveListener(OnDataReceiveListener onDataReceiveListener);
}
package com.miya.weighing;
import android.content.Context;
/**
* 标准称重接口的实现基类
*
* @author pupu
* @time 2018/10/19
*/
public class BaseWeighing implements Weighing {
/**
* 保存调用者上下文
*/
Context context;
/**
* 重量回调
*/
WeighingCallback weighingCallback;
/**
* 当前称台重量,单位g
*/
int curWeight;
/**
* 皮重
*/
int tare;
/**
* 硬件名称
*/
String name;
@Override
public void setWeighingName(String name) {
this.name = name;
}
@Override
public String getWeighingName() {
return name;
}
@Override
public boolean init(Context context) {
this.context = context;
return false;
}
@Override
public boolean release() {
return false;
}
@Override
public int getWeight() {
return curWeight;
}
@Override
public boolean resetZero() {
return false;
}
@Override
public boolean setTare(int tare) {
this.tare = tare;
return true;
}
@Override
public boolean setGravity(double gravity) {
return false;
}
@Override
public boolean markWeight(int weight) {
return false;
}
@Override
public int getWeightWithOutTare() {
return 0;
}
@Override
public void setWeighingCallback(WeighingCallback weighingCallback) {
this.weighingCallback = weighingCallback;
}
/**
* 将保留3位小数的重量转换位去掉小数点的整形重量,方便计算,避免float等的精度损失
*
* @param kg 单位为kg的重量
* @return 单位为g的重量,返回去掉小数点的整形
*/
public int parseKg2g(String kg) {
if (kg.contains(".")) {
String result = "";
int index = kg.indexOf(".");
String tmp1 = kg.substring(0, index);
String tmp2 = kg.substring(index + 1, kg.length());
if (tmp2.length() == 0) {
tmp2 = "000";
} else if (tmp2.length() == 1) {
tmp2 = tmp2 + "00";
} else if (tmp2.length() == 2) {
tmp2 = tmp2 + "0";
} else if (tmp2.length() > 3) {
tmp2 = tmp2.substring(0, 3);
}
result = tmp1 + tmp2;
//担心数据库中有非数字的值,最后考虑还是catch下;同时防止pos出现负数重量的奇葩傻逼情况,最后考虑还是绝对值abs一下
int resultInt = 0;
try {
resultInt = Integer.parseInt(result);
} catch (Exception ex) {
ex.printStackTrace();
}
return resultInt;
} else {
//担心数据库中有非数字的值,最后考虑还是catch下
int resultInt = 0;
try {
resultInt = Integer.parseInt(kg + "000");
} catch (Exception ex) {
ex.printStackTrace();
}
return resultInt;
}
}
/**
* 将单位为g的重量转换为kg,保留3为小数
*
* @param g
* @return
*/
public double parseg2kg(int g) {
return g / 1000.000d;
}
}
package com.miya.weighing;
import android.content.Context;
import android.os.CountDownTimer;
import android.util.Log;
import com.pupu.chuangjieweighing.ReadSerialPort;
import com.pupu.chuangjieweighing.SerialPortFunction;
/**
* 创捷称重驱动
*
* @author pupu
* @time 2018/11/06
*/
public class ChuangjieWeighing extends BaseWeighing {
final static String TAG = ChuangjieWeighing.class.getSimpleName();
/**
* 方法提供类
*/
SerialPortFunction serialPortFunction;
/**
* 标志是否正在置零
*/
boolean isResetZeroing = false;
@Override
public boolean init(Context context) {
serialPortFunction = SerialPortFunction.getInstance();
serialPortFunction.setContext(context);
try {
serialPortFunction.getWeighingSerialPort("/dev/ttyS4", 9600);
serialPortFunction.startReadWeight(new ReadSerialPort.DataWeight() {
@Override
public void weight(String s) {
Log.i(TAG, "当前重量为:" + s);
curWeight = parseKg2g(s.trim());
if (weighingCallback != null && curWeight > 0) {
weighingCallback.returnWeight(curWeight, true);
}
if (curWeight < 0) {
//发送置零指令
if (isResetZeroing == false) {
resetZero();
}
}
}
});
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public boolean resetZero() {
if (serialPortFunction != null) {
isResetZeroing = true;
//发送置零指令,有2s的耗时,内部为线程池异步操作
serialPortFunction.sendEle("410D0A");
//3s后改变状态
new CountDownTimer(3000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
}
@Override
public void onFinish() {
isResetZeroing = false;
}
}.start();
return true;
}
return false;
}
}
package com.miya.weighing;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import com.hisense.optionalservice.aidl.OnDataReceiveListener;
import com.hisense.optionalservice.aidl.OptionalApi;
import com.hisense.optionalservice.aidl.UartScale;
/**
* 海信称重实现子类
*
* @author pupu
* @time 2018/10/19
*/
public class HisenseWeighing extends BaseWeighing {
final static String TAG = HisenseWeighing.class.getSimpleName();
/**
* 服务名称
*/
final static String SERVICE_PACKAGE = "com.hisense.optionalapi";
/**
* 服务action
*/
final static String SERVICE_ACTION = "com.hisense.optionalapi";
/**
* aidl接口
*/
OptionalApi optionApi;
/**
* 重量操作者
*/
UartScale uartScale;
@Override
public boolean init(Context context) {
this.context = context;
Intent intent = new Intent();
intent.setPackage(SERVICE_PACKAGE);
return this.context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
}
@Override
public int getWeight() {
try {
uartScale.readWeight();
} catch (Exception e) {
e.printStackTrace();
}
return curWeight;
}
@Override
public void setWeighingCallback(WeighingCallback weighingCallback) {
if (weighingCallback != null) {
this.weighingCallback = weighingCallback;
}
}
@Override
public boolean resetZero() {
try {
uartScale.resetZero();
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public boolean setTare(int tare) {
if (tare < 0) {
return false;
}
this.tare = tare;
return true;
}
@Override
public int getWeightWithOutTare() {
return curWeight - tare;
}
@Override
public boolean release() {
this.context.unbindService(serviceConnection);
try {
uartScale.close();
} catch (Exception e) {
e.printStackTrace();
}
curWeight = 0;
tare = 0;
weighingCallback = null;
return true;
}
/**
* 服务连接器
*/
ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
optionApi = OptionalApi.Stub.asInterface(service);
if (optionApi != null) {
try {
uartScale = optionApi.getUartScale();
if (uartScale != null) {
//初始化
uartScale.open("/dev/ttySAC3", 9600, 0);
//设置重量监听回调
try {
uartScale.readWeight();
uartScale.setOnDataReceiveListener(new OnDataReceiveListener.Stub() {
@Override
public void onDataReceive(float weight, int status) throws RemoteException {
Log.i("pupu", "weight==>" + weight + ";" + "status==>" + status);
if (status > 0) {
//读取正常
curWeight = parseKg2g(weight + "");
if (weighingCallback != null) {
weighingCallback.returnWeight(curWeight, true);
}
} else if (status == -1) {
//读取超时,失败。考虑是否串口接触不良或者秤故障
curWeight = -1;
} else if (status == -2) {
//读取的重量为负值,需要重置零点
curWeight = -2;
uartScale.resetZero();
}
}
});
Log.i(TAG, "称重连接成功!");
} catch (Exception ex) {
//设置监听失败
ex.printStackTrace();
}
} else {
//连接失败
Log.i(TAG, "防损称连接失败");
}
} catch (Exception e) {
e.printStackTrace();
//连接失败
Log.i(TAG, "防损称连接失败");
}
} else {
//连接服务失败
Log.i(TAG, "防损称连接失败");
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
//连接断开
}
};
}
package com.miya.weighing;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import com.sunmi.electronicscaleservice.ScaleCallback;
import com.sunmi.electronicscaleservice.ScaleService;
/**
* 商米称重硬件驱动(注意:无需使用jar包中的ScaleManager!!!)
*
* @author pupu
* @time 2018/10/26
*/
public class SunmiWeighing extends BaseWeighing {
final static String TAG = SunmiWeighing.class.getSimpleName();
final static String SERVICE_PACKAGE = "com.sunmi.electronicscaleservice";
final static String SERVICE_ACTION = "com.sunmi.scaleservice";
/**
* 称重服务
*/
ScaleService scaleService;
@Override
public boolean init(Context context) {
this.context = context;
Intent intent = new Intent();
intent.setPackage(SERVICE_PACKAGE);
intent.setAction(SERVICE_ACTION);
return this.context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
}
@Override
public void setWeighingCallback(WeighingCallback weighingCallback) {
this.weighingCallback = weighingCallback;
}
@Override
public boolean resetZero() {
try {
scaleService.zero();
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
/**
* 服务连接器
*/
ServiceConnection serviceConnection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
scaleService = ScaleService.Stub.asInterface(service);
if (scaleService != null) {
//设置重量回调
try {
scaleService.getData(new ScaleCallback.Stub() {
@Override
public void getData(int net, int tare, int status) throws RemoteException {
Log.i(TAG, "商米称重硬件==>原始重量:" + net + ";皮重:" + tare + ";状态:" + status);
if (weighingCallback != null) {
String stateStr = Integer.toBinaryString(status);
boolean isStable;
if (stateStr.substring(stateStr.length() - 1).equals("1")) {
// 稳定
isStable = true;
if (net < 0) {
//程序置零一次,可能会失败
resetZero();
}
} else {
// 动态值
isStable = false;
}
curWeight = net;
weighingCallback.returnWeight(net, isStable);
}
}
});
} catch (Exception e) {
e.printStackTrace();
Log.i(TAG, "称重服务初始化失败!");
}
} else {
Log.i(TAG, "防损称连接失败!");
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
scaleService = null;
}
};
}
package com.miya.weighing;
import android.content.Context;
/**
* 称重组件开放平台:标准称重接口
*
* @author pupu
* @time 2018/10/19
*/
public interface Weighing {
/**
* 设置当前称重台硬件名称
*
* @param name 硬件名称
*/
void setWeighingName(String name);
/**
* 获取当前称重台硬件名称
*
* @return 当前称重台硬件名称
*/
String getWeighingName();
/**
* 初始化
*
* @param context 上下文引用,一般为ApplicationContext ,与application同生命周期
* @return true:初始化成功;false:初始化失败。在此方法加抛异常,供外部感知失败
*/
boolean init(Context context);
/**
* 释放硬件资源
*
* @return true:释放成功;false:释放失败。在此方法加抛异常,供外部感知失败原因
*/
boolean release();
/**
* 获取当前称上的重量
*
* @return 当前称上的重量,单位:g或mg。默认返回单位为g,如果后期业务需要非常精准的控制重量,可自定义返回单位为mg。在此方法加抛异常,供外部感知失败原
*/
int getWeight();
/**
* 重置零点
*
* @return true:重置指令发送成功;false:重置发送失败。在此方法加抛异常,供外部感知失败原因
*/
boolean resetZero();
/**
* 设置皮重为指定重量
*
* @param tare 皮重,单位默认为g;视业务而定可传入mg单位重量
* @return true:设置成功;false:设置失败。在此方法加抛异常,供外部感知失败原因
*/
boolean setTare(int tare);
/**
* 设置当前地区的重力加速度
*
* @param gravity 重力加速度,即重力除以质量(G/m)
* @return true:设置成功;false:设置失败。在此方法加抛异常,供外部感知失败原因
*/
boolean setGravity(double gravity);
/**
* 标定重量,设置称重硬件重量标准。在设备需初始化设置或者设备转移到异地的时候使用。
* 如将设备从上海标定后运送到新疆,因为两地的重力加速度是不一致的,所以需要重新做下标定。
* 一般来说,在称重台实际使用地区做好重量标定后无需再设置重力加速度。或者先做重量标定,转移称台地点后单独设置重力加速度。
* 标定的过程:执行零位标定,把当前状态标定为零点(无论当前秤盘上是否有物品,零位标定时都把当前状态标定为零点),
* 然后在秤盘上放一个15kg的砝码,执行重量标定为15kg(weight=15000),砝码的重量值为最大量程时标定后最准确
*
* @param weight 标准重量,默认单位g
* @return true:设置成功;false:设置失败。在此方法加抛异常,供外部感知失败原因
*/
boolean markWeight(int weight);
/**
* 获取当前称上的去皮重量,可能为负值,皮重数值由具体实现类维护,视业务情况调用。默认单位为g
*
* @return 去皮重量,默认单位为g
*/
int getWeightWithOutTare();
/**
* 设置重量回调
*
* @param weighingCallback 重量回调
*/
void setWeighingCallback(WeighingCallback weighingCallback);
/**
* 重量回调,用于持续提供当前重量的回调
*/
interface WeighingCallback {
/**
* 重量回调
*
* @param weight 当前称台上的重量,默认单位为g
* @param isStable 是否稳定标志,true==>已稳定
*/
void returnWeight(int weight, boolean isStable);
}
}
\ No newline at end of file
package com.miya.weighing;
import android.content.Context;
import android.support.annotation.NonNull;
import android.util.Log;
public class WeighingManager {
final static String TAG = WeighingManager.class.getSimpleName();
/**
* 设备类型枚举,用于轮询过程中的反射
*/
enum Type {
TYPE_HISENSE("hisense", HisenseWeighing.class.getName()),
TYPE_YINGTAI("yingtai", YingtaiWeighing.class.getName()),
TYPE_SUNMI("shangmi", SunmiWeighing.class.getName()),
TYPE_CHUANGJIE("chuangjie", ChuangjieWeighing.class.getName());
//这里添加扩展的驱动
/**
* 设备类型名称
*/
String typeName;
/**
* 设备驱动类全类名
*/
String clsName;
Type(String typeName, String clsName) {
this.typeName = typeName;
this.clsName = clsName;
}
@Override
public String toString() {
return "Type{" +
"typeName='" + typeName + '\'' +
", clsName='" + clsName + '\'' +
'}';
}
}
/**
* 标准称重接口
*/
Weighing weighing;
/**
* 单例
*/
private static WeighingManager instance;
/**
* 单例模式
*
* @return
*/
public static WeighingManager getInstance() {
synchronized (WeighingManager.class) {
if (instance == null) {
instance = new WeighingManager();
}
return instance;
}
}
private WeighingManager() {
}
/**
* 同步轮询初始化,外部无需关心重量管理者用的到底是哪个称重硬件
*
* @param context
* @return
*/
public boolean init(@NonNull Context context) {
boolean result = false;
//轮询所有的称重服务,注意是同步方法
for (Type type : Type.values()) {
//确保之前的称重实例已被销毁
if (weighing != null) {
weighing.release();
}
try {
//反射新建实例
Class weighingClass = Class.forName(type.clsName);
weighing = (Weighing) weighingClass.newInstance();
result = weighing.init(context);
if (result == true) {
//初始化成功
weighing.setWeighingName(type.typeName);
Log.i(TAG, "称重硬件初始化成功==>" + weighing.getWeighingName());
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (result == false) {
//没有找到称重硬件,先销毁,再返回false
if (weighing != null) {
weighing.release();
}
weighing = null;
Log.i(TAG, "称重硬件初始化失败,没有找到对应的硬件");
return false;
}
return false;
}
/**
* 获取当前称重硬件组件
*
* @return 当前正在使用的称重硬件
*/
public Weighing getWeighing() {
return weighing;
}
/**
* 供外部检测是否已经连接上对应的驱动
*
* @return true:正常工作中;false:没有对应的驱动
*/
public boolean isConnected() {
return weighing != null;
}
/**
* 保险起见提供指定硬件的初始化
* ps:谨慎调用
*
* @param context
* @param type 指定硬件类型
* @return
*/
public boolean init(Context context, Type type) {
if (type == null) {
return false;
}
//是否支持指定硬件
boolean isSupported = false;
for (Type tmpType : Type.values()) {
if (type.typeName.equals(tmpType.typeName)) {
isSupported = true;
}
}
if (isSupported == false) {
return false;
}
//反射新建实例
try {
Class weighingClass = Class.forName(type.clsName);
weighing = (Weighing) weighingClass.newInstance();
boolean result = weighing.init(context);
return result;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
}
package com.miya.weighing;
import android.content.Context;
import com.sdy.huihuaverify.core.utils.CpuUtils;
import com.sdy.huihuaverify.core.utils.D;
import java.util.Timer;
import java.util.TimerTask;
import cn.wintec.wtandroidjar.SCL;
/**
* 中科英泰称重驱动
*
* @author pupu
* @time 2018/10/19
*/
public class YingtaiWeighing extends BaseWeighing {
final static String TAG = YingtaiWeighing.class.getSimpleName();
/**
* 指令操作标志
*/
final static int OP_NONE = 0x000;
/**
* 重置零点
*/
final static int OP_ZERO = 0x001;
/**
* 最后一次指令操作记录
*/
int operate = OP_NONE;
/**
* 中科英泰称重
*/
SCL scl;
/**
* 用于源源不断提供重量数据
*/
Timer timer;
/**
* 重量数据数组
*/
byte[] buf;
@Override
public boolean init(Context context) {
if (CpuUtils.isArm()) {
this.context = context;
scl = new SCL("/dev/ttyS1");
buf = new byte[20];
return scl.isConnected();
} else {
return false;
}
}
@Override
public int getWeight() {
if (scl != null) {
scl.read_standard(buf);
}
return super.getWeight();
}
@Override
public int getWeightWithOutTare() {
return curWeight - tare;
}
@Override
public boolean markWeight(int weight) {
if (scl != null) {
return scl.markWeight(parseg2kg(weight));
}
return false;
}
@Override
public boolean setGravity(double gravity) {
if (scl != null) {
return scl.setGravity(gravity);
}
return false;
}
@Override
public boolean setTare(int tare) {
this.tare = tare;
return true;
//暂不用英泰提供的去皮方法,建议交给业务层维护皮重计算,可以调用getWeightWithoutTare获取
// if(scl!=null){
// return scl.setTare(parseg2kg(tare));
// }
// return false;
}
@Override
public boolean resetZero() {
if (scl != null) {
return scl.resetZero();
}
return false;
}
@Override
public void setWeighingCallback(WeighingCallback callback) {
this.weighingCallback = callback;
if (timer == null) {
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
//不断读取重量数据,每100ms一次
int ret = scl.read_standard(buf);
if (ret == 0) {
//读取正常
D.i(TAG, "当前重量为(kg):" + scl.ASCII2HexString(buf, 20).substring(1, 7));
curWeight = parseKg2g(scl.ASCII2HexString(buf, 20).substring(1, 7).trim());
//获取标志位
byte stateByte = buf[0];
//是否稳定标志
boolean isStable = Integer.toBinaryString((int) stateByte).substring(5, 6).equals("1");
//是否在零点
boolean isZero = Integer.toBinaryString((int) stateByte).substring(4, 5).equals("1");
if (isZero == false && curWeight < 0) {
//重置零点一次
resetZero();
}
//是否去皮
boolean isTared = Integer.toBinaryString((int) stateByte).substring(3, 4).equals("1");
D.i(TAG, "当前称状态:" + Integer.toBinaryString((int) stateByte) + "\n" + "去皮:" + isTared + ";零点:" + isZero + ";稳定:" + isStable);
if (weighingCallback != null) {
weighingCallback.returnWeight(curWeight, isStable);
}
} else if (ret == 1) {
//发送指令成功,暂不关心
D.i(TAG, "指令操作结果:" + scl.ASCII2HexString(buf, 20) + ";时间:" + System.currentTimeMillis());
} else if (ret == 2) {
//读取异常
curWeight = -2;
}
}
}, 0, 10);
}
}
@Override
public boolean release() {
if (scl != null) {
scl.SCL_close();
}
scl = null;
buf = null;
if (timer != null) {
timer.cancel();
}
return true;
}
}
<resources>
<string name="app_name">weighing</string>
</resources>
package com.miya.weighing;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment