当前位置: 首页 > news >正文

英文垃圾站wordpress外链网盘

英文垃圾站wordpress,外链网盘,国外 家具 网站模板,做废钢推广网站本文接Android程序运行分析——中等复杂程度的NTAG I2C Demo为例(二) 主要针对launchDemo继续进行分析 launchDemo的源代码已经在(二)中贴过了,(二)中只分析了开头的一点点认证代码&#xff0…

本文接Android程序运行分析——中等复杂程度的NTAG I2C Demo为例(二)

主要针对launchDemo继续进行分析

launchDemo的源代码已经在(二)中贴过了,(二)中只分析了开头的一点点认证代码,本文主要分析launchDemo的主体

launchDemo的源代码如下

private void launchDemo(String currTab) {if(mAuthStatus == AuthStatus.Authenticated.getValue()) {demo.Auth(mPassword, AuthStatus.Protected_RW.getValue());}// ===========================================================================// LED Test// ===========================================================================if (currTab.equalsIgnoreCase("leds")) {// This demo is available even if the product is protected // as long as the SRAM is unprotected  			if(mAuthStatus == AuthStatus.Disabled.getValue()|| mAuthStatus == AuthStatus.Unprotected.getValue()|| mAuthStatus == AuthStatus.Authenticated.getValue()|| mAuthStatus == AuthStatus.Protected_W.getValue()|| mAuthStatus == AuthStatus.Protected_RW.getValue() ) {try {// if (LedFragment.getChosen()) {demo.LED();} catch (Exception e) {e.printStackTrace();LedFragment.setAnswer(getString(R.string.Tag_lost));}} else {Toast.makeText(getApplicationContext(), "NTAG I2C Plus memory is protected", Toast.LENGTH_LONG).show();showAuthDialog();}}// ===========================================================================// NDEF Demo// ===========================================================================if (currTab.equalsIgnoreCase("ndef")) {// This demo is only available when the tag is not protected  if(mAuthStatus == AuthStatus.Disabled.getValue()|| mAuthStatus == AuthStatus.Unprotected.getValue()|| mAuthStatus == AuthStatus.Authenticated.getValue()) {try {demo.NDEF();} catch (Exception e) {// NdefFragment.setAnswer(getString(R.string.Tag_lost));}} else {Toast.makeText(getApplicationContext(), "NTAG I2C Plus memory is protected", Toast.LENGTH_LONG).show();showAuthDialog();}}// ===========================================================================// Config// ===========================================================================if (currTab.equalsIgnoreCase("config")) {}// ===========================================================================// Speedtest// ===========================================================================if (currTab.equalsIgnoreCase("ntag_rf")) {try {// SRAM Testif ((SpeedTestFragment.isSRamEnabled() == true)) {// This demo is available even if the product is protected // as long as the SRAM is unprotected  	if(mAuthStatus == AuthStatus.Disabled.getValue()|| mAuthStatus == AuthStatus.Unprotected.getValue()|| mAuthStatus == AuthStatus.Authenticated.getValue()|| mAuthStatus == AuthStatus.Protected_W.getValue()|| mAuthStatus == AuthStatus.Protected_RW.getValue()) {demo.SRAMSpeedtest();} else {Toast.makeText(getApplicationContext(), "NTAG I2C Plus memory is protected", Toast.LENGTH_LONG).show();showAuthDialog();}}// EEPROM Testif ((SpeedTestFragment.isSRamEnabled() == false)) {// This demo is only available when the tag is not protected  if(mAuthStatus == AuthStatus.Disabled.getValue()|| mAuthStatus == AuthStatus.Unprotected.getValue()|| mAuthStatus == AuthStatus.Authenticated.getValue()) {demo.EEPROMSpeedtest();} else {Toast.makeText(getApplicationContext(), "NTAG I2C Plus memory is protected", Toast.LENGTH_LONG).show();showAuthDialog();}} // end if eeprom test} catch (Exception e) {SpeedTestFragment.setAnswer(getString(R.string.Tag_lost));e.printStackTrace();}}		}

完成认证之后,也就是完成以下代码之后

看第一个Task

如果你的tab选择了这个,那么就进入if语句中,开始执行LED task

查看一下你的认证状态,如果你的认证状态可以(或者说mAuthStatus变量的值可以)那就进行LED demo的演示

如果你的认证状态不行,那就先告诉你不行,然后弹出一个Dialog让你重新选,也就是这句话


showAuthDialog

在showAuthDialogFlag为true且mAuthStatus这个变量不等于Disabled的前提下

跳转到 AuthActivity

关注一下这个函数体里的最后一个方法,StartActivityForResult,这个方法接受2个参数,第一个参数是intent,第二个参数是请求码,用于在之后的回调中判断数据的来源

简单的理解一下这个函数的作用,我在当前的Activity中调用StartActivityForResult方法,请求码只要是一个唯一的值即可

然后在第二个我们要去的Activity中,我们构建一个Intent,不过这个intent仅仅用于传递数据,我们把要传递的数据存放在intent中,然后调用setResult方法,这个方法用于向上一个Activity返回数据,setResult接受2个参数,第一个参数用于向上一个Activity返回处理结果,一般只要用RESULT_OK 或RESULT_CANCELED这两个值,第二个参数把带有数据的intent传递回去


demo.LED

    private class LedTask extends AsyncTask<Void, Byte[], Void> {private final byte deviceToTag = 1;private final byte tagToDevice = 2;private final byte noTransfer = 0;private final byte invalidTransfer = 4;private Boolean exit = false;@Overrideprotected Void doInBackground(Void... params) {byte[] dataTx = new byte[reader.getSRAMSize()];byte[] dataRx = new byte[reader.getSRAMSize()];byte[] Led;Byte[][] result;// We have to make sure that the Pass-Through mode is activatedlong RegTimeOutStart = System.currentTimeMillis();boolean RTest = false;try {do {if (reader.checkPTwritePossible()) {break;}long RegTimeOut = System.currentTimeMillis();RegTimeOut = RegTimeOut - RegTimeOutStart;RTest = (RegTimeOut < 5000);} while (RTest);// Do as long as no Exception is thrownwhile (true) {// Get the color to be transmittedLed = LedFragment.getOption().getBytes();// Write the color into the block to be transmitted to the// NTAG boarddataTx[reader.getSRAMSize() - 4] = Led[0];dataTx[reader.getSRAMSize() - 3] = Led[1];// Indicate whether Temperate and LCD are enabled or notif (LedFragment.isTempEnabled()) {dataTx[reader.getSRAMSize() - 9] = 'E';} else {dataTx[reader.getSRAMSize() - 9] = 0x00;}if (LedFragment.isLCDEnabled()) {dataTx[reader.getSRAMSize() - 10] = 'E';} else {dataTx[reader.getSRAMSize() - 10] = 0x00;}// NDEF Scrolling activationif (LedFragment.isScrollEnabled()) {dataTx[reader.getSRAMSize() - 11] = 'E';} else {dataTx[reader.getSRAMSize() - 11] = 0x00;}double tempC = LedFragment.getTemperatureC();double tempF = LedFragment.getTemperatureF();if (tempC > 0.0 && tempC < 75.0) {DecimalFormat df = new DecimalFormat("00.00");byte[] tempB = df.format(tempC).getBytes();// The '.' is omitteddataTx[reader.getSRAMSize() - 24] = tempB[0];dataTx[reader.getSRAMSize() - 23] = tempB[1];dataTx[reader.getSRAMSize() - 22] = tempB[3];dataTx[reader.getSRAMSize() - 21] = tempB[4];}if (tempF > 0.0 && tempF < 120.0) {DecimalFormat df = new DecimalFormat("000.00");byte[] tempB = df.format(tempF).getBytes();// The '.' is omitteddataTx[reader.getSRAMSize() - 19] = tempB[0];dataTx[reader.getSRAMSize() - 18] = tempB[1];dataTx[reader.getSRAMSize() - 17] = tempB[2];dataTx[reader.getSRAMSize() - 16] = tempB[4];dataTx[reader.getSRAMSize() - 15] = tempB[5];}double voltD = LedFragment.getVoltage();if (voltD > 0.0 && voltD < 5.0) {DecimalFormat df = new DecimalFormat("0.0");byte[] voltB = df.format(voltD).getBytes();// The '.' is omitteddataTx[reader.getSRAMSize() - 8] = voltB[0];dataTx[reader.getSRAMSize() - 7] = voltB[2];}displayTransferDir(deviceToTag);// wait to prevent that a RF communication is// at the same time as µC I2CThread.sleep(10);reader.waitforI2Cread(DELAY_TIME);reader.writeSRAMBlock(dataTx, null);displayTransferDir(tagToDevice);// wait to prevent that a RF communication is// at the same time as µC I2CThread.sleep(10);reader.waitforI2Cwrite(100);dataRx = reader.readSRAMBlock();if (exit) {// switch off the LED on the µC before terminatingdataTx[reader.getSRAMSize() - 4] = Led[0];dataTx[reader.getSRAMSize() - 3] = '0';// wait to prevent that a RF communication is// at the same time as µC I2CThread.sleep(10);reader.waitforI2Cread(100);reader.writeSRAMBlock(dataTx, null);// wait to prevent that a RF communication is// at the same time as µC I2CThread.sleep(10);reader.waitforI2Cwrite(100);dataRx = reader.readSRAMBlock();cancel(true);return null;}// Convert byte[] to Byte[]Byte[] bytes = new Byte[dataRx.length];for (int i = 0; i < dataRx.length; i++) {bytes[i] = Byte.valueOf(dataRx[i]);}result = new Byte[2][];result[0] = new Byte[1];result[0][0] = Byte.valueOf(invalidTransfer);result[1] = bytes;// Write the result to the UI threadpublishProgress(result);}} catch (FormatException e) {displayTransferDir(noTransfer);cancel(true);e.printStackTrace();} catch (IOException e) {displayTransferDir(noTransfer);cancel(true);e.printStackTrace();} catch (CommandNotSupportedException e) {showDemoNotSupportedAlert();displayTransferDir(noTransfer);cancel(true);e.printStackTrace();} catch (Exception e) {displayTransferDir(noTransfer);cancel(true);e.printStackTrace();}return null;}private void displayTransferDir(byte dir) {Byte[][] result;result = new Byte[2][];result[0] = new Byte[1];result[0][0] = Byte.valueOf(dir);publishProgress(result);}@Overrideprotected void onProgressUpdate(Byte[]... bytes) {if (bytes[0][0] == noTransfer) {LedFragment.setTransferDir("Transfer: non");} else if (bytes[0][0] == deviceToTag) {LedFragment.setTransferDir("Transfer: Device --> Tag");} else if (bytes[0][0] == tagToDevice) {LedFragment.setTransferDir("Transfer: Device <-- Tag");} else {LedFragment.setButton(bytes[1][reader.getSRAMSize() - 2]);int temp = 0;// Adding first "Byte"temp = ((bytes[1][reader.getSRAMSize() - 5] >> 5) & 0x00000007);// Adding second Bytetemp |= ((bytes[1][reader.getSRAMSize() - 6] << 3) & 0x000007F8);// Voltageint voltage = 0;voltage = ((bytes[1][reader.getSRAMSize() - 7] << 8) & 0xff00)+ (bytes[1][reader.getSRAMSize() - 8] & 0x00ff);// if Temp is 0 no Temp sensor is on the µCif (temp != 0) {// Set the values on the screenLedFragment.setAnswer("Temperature: "+ calcTempCelsius(temp) + " µC / "+ calcTempFarenheit(temp) + " °F"+ "\nEnergy Harvesting Voltage: "+ calcVoltage(voltage));} else {LedFragment.setAnswer("Temperature: " + "Not available"+ "\nEnergy Harvesting Voltage: "+ calcVoltage(voltage));LedFragment.setTemperatureC(0);LedFragment.setTemperatureF(0);}byte version = bytes[1][reader.getSRAMSize() - 1];if (version > 0) {int uppVersion = (version >> 4) & 0x0f;int lowVersion = version & 0x0f;MainActivity.setBoardFirmwareVersion(String.valueOf(uppVersion)+ "."+ String.valueOf(lowVersion));} else {MainActivity.setBoardFirmwareVersion("1.0");}}}}

 

http://www.lbrq.cn/news/2414521.html

相关文章:

  • 网站建设与管理教程 全套上海最近3天疫情情况
  • 用什么软件可以做网站动态千锋教育培训怎么样
  • 网站建设估价近期国内热点新闻事件
  • 哪个平台做网站比较好2345网址导航安装
  • 网站设计合同注意事项seo推广知识
  • 做网站不能有中文字符自媒体平台排名前十
  • 三五互联做的网站怎么样网络营销八大工具
  • 互动网络游戏公司网站建设廊坊关键词优化报价
  • wordpress 页面编辑失败aso优化公司
  • 把自己做的网页发布到网站百度怎么发布自己的信息
  • 点播视频网站怎么建设网络营销成功案例ppt免费
  • 企业中标信息查询网涟源网站seo
  • 网站说服力营销型网站策划 pdf网推平台
  • 旅游做攻略用什么网站好情感营销的十大案例
  • 网站域名管理中心企业互联网推广
  • 武汉市东西湖区建设局官方网站seo入门书籍
  • 电商网站开发日志网站推广渠道
  • 1997年做网站是什么语言厦门网站优化公司
  • dw自己做网站百度推广代理公司
  • 金华建设二建哪个网站报名百度引流免费推广怎么做
  • 网站建设xywlcn营销型网站建设步骤
  • 自适应网站建设需要注意什么企业网站推广方案策划
  • 网站网页怎么做长沙优化科技
  • 替别人做设计的网站多少钱网站权重怎么看
  • wordpress 移动到回收站发生错误怎样创建一个网站
  • html5做网站导航页潍坊seo建站
  • 青岛教育平台网站建设google怎么推广
  • 做视频上传可以赚钱的网站深圳优化公司哪家好
  • 开发电商网站多少钱开网店
  • 做兼职比较好的网站在线看seo网站
  • 【web自动化】-5- fixture集中管理和项目重构
  • 【Elasticsearch】IndexModule
  • 创建一个触发csrf的恶意html
  • `tidyverse` 中涉及的函数及其用法
  • Qwen3-8B 与 ChatGPT-4o Mini 的 TTFT 性能对比与底层原理详解
  • 二、Spark 开发环境搭建 IDEA + Maven 及 WordCount 案例实战