连接蓝牙,配网
This commit is contained in:
@@ -233,5 +233,7 @@ dependencies {
|
|||||||
implementation 'no.nordicsemi.android:ble:2.11.0'
|
implementation 'no.nordicsemi.android:ble:2.11.0'
|
||||||
//espressif官方sdk,用于esp固件的扫描,配网等。
|
//espressif官方sdk,用于esp固件的扫描,配网等。
|
||||||
implementation 'com.github.espressif:esp-idf-provisioning-android:lib-2.2.3'
|
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 animationDrawable = (AnimationDrawable) ivScanAnimation.getDrawable();
|
||||||
animationDrawable.start();
|
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();
|
initListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,6 +187,15 @@ public class AddDeviceActivity_copy extends BaseActivity<AddDeviceLayoutBinding,
|
|||||||
bleAdapter.notifyItemInserted(mDeviceList.size() - 1);
|
bleAdapter.notifyItemInserted(mDeviceList.size() - 1);
|
||||||
if(bleAdapter.getItemCount() != 0){
|
if(bleAdapter.getItemCount() != 0){
|
||||||
viewBinding.rvDevices.setVisibility(VISIBLE);
|
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
|
@Override
|
||||||
public void onProvisioning(int progress) {
|
public void onProvisioning(int progress) {
|
||||||
Log.i("TEST","WIFI连接进度 == " + progress);
|
Log.i("TEST","WIFI连接进度 == " + progress);
|
||||||
|
viewBinding.tvProgress.setText("进度:" + progress + "%");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(String deviceName, String deviceType) {
|
public void onSuccess(String deviceName, String deviceType) {
|
||||||
Log.i("TEST","deviceName:" + deviceName + "连接成功");
|
Log.i("TEST","deviceName:" + deviceName + "连接成功");
|
||||||
|
ToastUtil.showShort(mContext, deviceName + "连接成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ public class EspProvisionManager {
|
|||||||
private boolean provisioning;
|
private boolean provisioning;
|
||||||
private boolean eventBusRegistered;
|
private boolean eventBusRegistered;
|
||||||
private boolean ignoreNextDisconnectEvent;
|
private boolean ignoreNextDisconnectEvent;
|
||||||
|
private boolean expectDisconnected; // 标记是否预期断开(配网成功后)
|
||||||
private String currentDeviceName;
|
private String currentDeviceName;
|
||||||
private String currentDeviceType = ProvisionConfig.TRANSPORT_BLE;
|
private String currentDeviceType = ProvisionConfig.TRANSPORT_BLE;
|
||||||
|
|
||||||
@@ -328,8 +329,13 @@ public class EspProvisionManager {
|
|||||||
boolean shouldNotify = connected || connecting || provisioning;
|
boolean shouldNotify = connected || connecting || provisioning;
|
||||||
resetState();
|
resetState();
|
||||||
if (shouldNotify) {
|
if (shouldNotify) {
|
||||||
|
// 如果是配网成功后的预期断开,不发送断开回调
|
||||||
|
// 因为 onSuccess 已经通知过了
|
||||||
|
if (!expectDisconnected) {
|
||||||
notifyDisconnected();
|
notifyDisconnected();
|
||||||
}
|
}
|
||||||
|
expectDisconnected = false; // 重置标志
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -364,6 +370,7 @@ public class EspProvisionManager {
|
|||||||
connected = false;
|
connected = false;
|
||||||
provisioning = false;
|
provisioning = false;
|
||||||
ignoreNextDisconnectEvent = false;
|
ignoreNextDisconnectEvent = false;
|
||||||
|
// expectDisconnected 保持不变,用于断开回调判断
|
||||||
}
|
}
|
||||||
|
|
||||||
private ESPConstants.SecurityType parseSecurityType(int securityType) {
|
private ESPConstants.SecurityType parseSecurityType(int securityType) {
|
||||||
@@ -379,6 +386,7 @@ public class EspProvisionManager {
|
|||||||
private void finishProvisionSuccess() {
|
private void finishProvisionSuccess() {
|
||||||
mainHandler.removeCallbacks(provisionTimeoutTask);
|
mainHandler.removeCallbacks(provisionTimeoutTask);
|
||||||
provisioning = false;
|
provisioning = false;
|
||||||
|
expectDisconnected = true; // 标记为预期断开
|
||||||
notifyProvisioning(100);
|
notifyProvisioning(100);
|
||||||
notifySuccess();
|
notifySuccess();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,16 @@ public class ProvisionConfig {
|
|||||||
*/
|
*/
|
||||||
public static final int DEFAULT_SECURITY = SECURITY_1;
|
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:paddingVertical="@dimen/dp_10"
|
||||||
android:layout_marginHorizontal="@dimen/dp_20"
|
android:layout_marginHorizontal="@dimen/dp_20"
|
||||||
android:layout_marginTop="@dimen/dp_40"
|
android:layout_marginTop="@dimen/dp_40"
|
||||||
android:gravity="center"/>
|
android:gravity="center"
|
||||||
|
android:visibility="gone"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -95,6 +95,16 @@
|
|||||||
android:hint="@string/input_wifi_psd_tip"/>
|
android:hint="@string/input_wifi_psd_tip"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</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
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/rv_wifi_list"
|
android:id="@+id/rv_wifi_list"
|
||||||
@@ -117,4 +127,5 @@
|
|||||||
android:layout_marginTop="@dimen/dp_40"
|
android:layout_marginTop="@dimen/dp_40"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:visibility="gone"/>
|
android:visibility="gone"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user