连接蓝牙,配网
This commit is contained in:
@@ -233,5 +233,7 @@ dependencies {
|
||||
implementation 'no.nordicsemi.android:ble:2.11.0'
|
||||
//espressif官方sdk,用于esp固件的扫描,配网等。
|
||||
implementation 'com.github.espressif:esp-idf-provisioning-android:lib-2.2.3'
|
||||
//自定义progressBar
|
||||
implementation 'com.timqi.sectorprogressview:library:2.0.1'
|
||||
}
|
||||
|
||||
|
||||
@@ -121,20 +121,6 @@ public class AddDeviceActivity_copy extends BaseActivity<AddDeviceLayoutBinding,
|
||||
AnimationDrawable animationDrawable = (AnimationDrawable) ivScanAnimation.getDrawable();
|
||||
animationDrawable.start();
|
||||
}
|
||||
new Handler().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// 停止帧动画
|
||||
ImageView ivScanAnimation = viewBinding.ivScanAnimation;
|
||||
if (ivScanAnimation.getDrawable() instanceof AnimationDrawable) {
|
||||
AnimationDrawable animationDrawable = (AnimationDrawable) ivScanAnimation.getDrawable();
|
||||
if (animationDrawable.isRunning()) {
|
||||
animationDrawable.stop();
|
||||
viewBinding.ivScanAnimation.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
},3000);
|
||||
initListener();
|
||||
}
|
||||
|
||||
@@ -201,6 +187,15 @@ public class AddDeviceActivity_copy extends BaseActivity<AddDeviceLayoutBinding,
|
||||
bleAdapter.notifyItemInserted(mDeviceList.size() - 1);
|
||||
if(bleAdapter.getItemCount() != 0){
|
||||
viewBinding.rvDevices.setVisibility(VISIBLE);
|
||||
// 停止帧动画
|
||||
ImageView ivScanAnimation = viewBinding.ivScanAnimation;
|
||||
if (ivScanAnimation.getDrawable() instanceof AnimationDrawable) {
|
||||
AnimationDrawable animationDrawable = (AnimationDrawable) ivScanAnimation.getDrawable();
|
||||
if (animationDrawable.isRunning()) {
|
||||
animationDrawable.stop();
|
||||
viewBinding.ivScanAnimation.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -217,11 +217,13 @@ public class SelectWifiActivity extends BaseActivity<DeviceResetWifiBinding, Dev
|
||||
@Override
|
||||
public void onProvisioning(int progress) {
|
||||
Log.i("TEST","WIFI连接进度 == " + progress);
|
||||
viewBinding.tvProgress.setText("进度:" + progress + "%");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(String deviceName, String deviceType) {
|
||||
Log.i("TEST","deviceName:" + deviceName + "连接成功");
|
||||
ToastUtil.showShort(mContext, deviceName + "连接成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -44,6 +44,7 @@ public class EspProvisionManager {
|
||||
private boolean provisioning;
|
||||
private boolean eventBusRegistered;
|
||||
private boolean ignoreNextDisconnectEvent;
|
||||
private boolean expectDisconnected; // 标记是否预期断开(配网成功后)
|
||||
private String currentDeviceName;
|
||||
private String currentDeviceType = ProvisionConfig.TRANSPORT_BLE;
|
||||
|
||||
@@ -328,8 +329,13 @@ public class EspProvisionManager {
|
||||
boolean shouldNotify = connected || connecting || provisioning;
|
||||
resetState();
|
||||
if (shouldNotify) {
|
||||
// 如果是配网成功后的预期断开,不发送断开回调
|
||||
// 因为 onSuccess 已经通知过了
|
||||
if (!expectDisconnected) {
|
||||
notifyDisconnected();
|
||||
}
|
||||
expectDisconnected = false; // 重置标志
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -364,6 +370,7 @@ public class EspProvisionManager {
|
||||
connected = false;
|
||||
provisioning = false;
|
||||
ignoreNextDisconnectEvent = false;
|
||||
// expectDisconnected 保持不变,用于断开回调判断
|
||||
}
|
||||
|
||||
private ESPConstants.SecurityType parseSecurityType(int securityType) {
|
||||
@@ -379,6 +386,7 @@ public class EspProvisionManager {
|
||||
private void finishProvisionSuccess() {
|
||||
mainHandler.removeCallbacks(provisionTimeoutTask);
|
||||
provisioning = false;
|
||||
expectDisconnected = true; // 标记为预期断开
|
||||
notifyProvisioning(100);
|
||||
notifySuccess();
|
||||
}
|
||||
|
||||
@@ -54,6 +54,16 @@ public class ProvisionConfig {
|
||||
*/
|
||||
public static final int DEFAULT_SECURITY = SECURITY_1;
|
||||
|
||||
/**
|
||||
* 默认 PoP,需和 ESP 固件保持一致
|
||||
*/
|
||||
public static final String DEFAULT_PROOF_OF_POSSESSION = "abcd1234";
|
||||
|
||||
/**
|
||||
* Security2 使用的默认用户名
|
||||
*/
|
||||
public static final String DEFAULT_USER_NAME = "";
|
||||
|
||||
/**
|
||||
* 连接超时时间 (毫秒)
|
||||
*/
|
||||
|
||||
@@ -95,5 +95,6 @@
|
||||
android:paddingVertical="@dimen/dp_10"
|
||||
android:layout_marginHorizontal="@dimen/dp_20"
|
||||
android:layout_marginTop="@dimen/dp_40"
|
||||
android:gravity="center"/>
|
||||
android:gravity="center"
|
||||
android:visibility="gone"/>
|
||||
</LinearLayout>
|
||||
@@ -95,6 +95,16 @@
|
||||
android:hint="@string/input_wifi_psd_tip"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/tv_progress"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/dp_20"
|
||||
android:layout_marginTop="@dimen/dp_10"
|
||||
android:textSize="20sp"
|
||||
android:textColor="@color/textPrimaryColor"
|
||||
android:text="进度"
|
||||
android:textStyle="bold"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_wifi_list"
|
||||
@@ -117,4 +127,5 @@
|
||||
android:layout_marginTop="@dimen/dp_40"
|
||||
android:gravity="center"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user