NFC Jar
来自Waveshare Wiki
NFC SDK JAR
20200717 JAR
函数
public int a(NfcA paramNfcA);
初始化 参数: paramNfcA NFC实例NfcA 返回: 1: 初始化成功 -1: 初始化失败
public int a() ;
获取当前进度 返回: -1: 出现错误。或者异常 0-99: 进度败 100: 刷新成功
public int a(int paramInt, Bitmap paramBitmap);
图片发送函数 参数: paramInt:选择对应的墨水屏编号 paramBitmap: 需要刷新的图片 返回: -1: IO错误 0: 失败 1: 成功 2: 图片尺寸错误
编号 | 型号 | 宽 | 高 |
1 | 2.13 | 250 | 128 |
2 | 2.9 | 296 | 128 |
3 | 4.2 | 400 | 300 |
4 | 7.5 | 800 | 480 |
5 | 7.5HD | 880 | 528 |
6 | 2.7 | 264 | 176 |
7 | 2.9B | 296 | 128 |
public int a(byte[] paramArrayOfbyte) ;
密码验证 参数: paramArrayOfbyte : 验证的密码 返回: -1: IO错误 0: 未设置密码 1: 密码正确 2: 密码错误 3: 无密码固件 或者 未知设备
public int a(byte[] paramArrayOfbyte1, byte[] paramArrayOfbyte2);
密码修改 参数: paramArrayOfbyte1 : 旧密码 paramArrayOfbyte2:新密码 返回: -1: IO错误 1: 密码正确 密码修改成功 2: 密码错误 密码修改失败 3: 无密码固件 或者 未知设备
public int b(byte[] paramArrayOfbyte) ;
开启密码验证 参数: paramArrayOfbyte : 验证的密码 返回: -1: IO错误 1: 密码正确 开启密码功能成功 2: 密码错误 开启密码功能失败 3: 无密码固件 或者 未知设备
public int c(byte[] paramArrayOfbyte) ;
关闭密码验证 参数: paramArrayOfbyte : 验证的密码 返回: -1: IO错误 1: 密码正确 关闭密码功能成功 2: 密码错误 关闭密码功能失败 3: 无密码固件 或者 未知设备
示例
刷图与密码验证示例
protected void onNewIntent(Intent intent) { // Tag writing mode final int[] EPD_total_progress = {-1};// 当前进度 -1 上次没有终止的需要终止 final int[] Password_validation = {0}; final byte[] Password_s = new byte[15]; for(int i=0;i<Password_len;i++) { Password_s[i]=(byte) Password[i];//得到密码 } final int[] whether_succeed = {1}; //1 发送函数调用成功 0发送函数调用失败 if (mWriteMode && NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) { detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); String[] tech = detectedTag.getTechList();//得到描述符 if(tech[0].equals("android.nfc.tech.NfcA")) {//如果描述符正确则发送函数 Thread t = new Thread() { @Override public void run() { Boolean success = false; NfcA tntag; tntag = NfcA.get(detectedTag); final a EPD_send = new a(); EPD_send.a(tntag);//初始化 final String UID; UID = EPD_send.a(detectedTag); log.e(" UID"," "+UID); if(false) { Thread thread2 = new Thread(new Runnable() { public void run() { Looper.prepare(); // Toast.makeText(MainActivity.this, UID, Toast.LENGTH_LONG).show(); Toast toast=Toast.makeText(MainActivity.this, UID, Toast.LENGTH_LONG); toast.setGravity(Gravity.TOP| Gravity.CENTER, 0, 100); toast.show(); Looper.loop(); } }); thread2.start(); } Password_validation[0] = EPD_send.a(Password_s); if(Password_validation[0] == -1){//IO错误 Looper.prepare(); Toast.makeText(MainActivity.this, R.string.IO_error,Toast.LENGTH_LONG).show(); Looper.loop(); }else if(Password_validation[0] == 1 || Password_validation[0] == 0 || Password_validation[0] == 3) { //验证密码通过 或 者没有设置密码 if(Password_validation[0] == 0 || Password_validation[0] == 3) {//0 没有设置密码 3无密码固件 Thread thread1 = new Thread(new Runnable() {//无密码提示 public void run() { Looper.prepare(); Toast.makeText(MainActivity.this, R.string.nopassword, Toast.LENGTH_SHORT).show(); Looper.loop(); } }); thread1.start(); } Thread thread = new Thread(new Runnable() {//进度显示进程 @Override public void run() { EPD_total_progress[0] = 0; while(true){ EPD_total_progress[0] = EPD_send.a(); if(EPD_total_progress[0] == -1 || whether_succeed[0] == 0){//如果返回-1 或者 break; } setStatusBody(getString(R.string.txing) + EPD_total_progress[0] +"%");//显示当前进度 if(EPD_total_progress[0] == 100 ){ //发送成功 break; } SystemClock.sleep(10); } if(EPD_total_progress[0] == -1 || whether_succeed[0] != 1){ setStatusBody(getString(R.string.txfail)); //显示 失败 字符串 }else { setStatusBody(getString(R.string.txsuccess));//显示 成功 字符串 } } });//进度显示进程 END thread.start();//进度显示进程 开启线程 try {//NFC异常中断 whether_succeed[0] = EPD_send.a(Size_Flag, bmp_send);//发送函数 if(whether_succeed[0] == 1){//发送成功 success = true; runOnUiThread(new Runnable() { @Override public void run() { checkNFCpopwindow.dismiss(); } }); Success_Sound_Effects(); }else{//发送失败 Looper.prepare(); Toast.makeText(MainActivity.this, R.string.txfail,Toast.LENGTH_LONG).show(); Looper.loop(); } } finally { try { if (success == false) { runOnUiThread(new Runnable() { @Override public void run() { checkNFCpopwindow.dismiss(); } }); } tntag.close(); } catch (IOException e) { e.printStackTrace(); } }//NFC异常中断END // 验证密码通过 或 者没有设置密码END } else if(Password_validation[0] == 2){//密码错误 Looper.prepare(); Toast.makeText(MainActivity.this, R.string.password_error,Toast.LENGTH_LONG).show(); Looper.loop(); log.e(" NFC"," 密码错误"); } } }; t.start(); } } }
密码验证开启/关闭示例
protected void onNewIntent(final Intent intent) { super.onNewIntent(intent); detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); SwitchPass(); } private void SwitchPass() { final a EPD_send = new a(); String password_str=((EditText)findViewById(R.id.password_edit)).getText().toString(); if(!"".equals(password_str)&&password_str.length()>=4) { int password_lenght = password_str.length(); char[] password_char = password_str.toCharArray(); if(detectedTag != null) { byte[] password = new byte[password_lenght]; for(int i=0;i<password_lenght;i++) { password[i]=(byte) password_char[i]; } String[] tech = detectedTag.getTechList(); if (tech[0].equals("android.nfc.tech.NfcA")) { tntag = NfcA.get(detectedTag); EPD_send.a(tntag);//初始化 if (Switch_flag == 1) { // System.arraycopy(new byte[]{(byte) 0xff, (byte) 0xfe, (byte) 0xfc, (byte) password_lenght}, 0, cmd, 0, 4); //开启加密 switch (EPD_send.b(password)) { case 1: Toast.makeText(SwitchPasswordActivity.this, R.string.encryption_on, Toast.LENGTH_LONG).show(); break; case 2: Toast.makeText(SwitchPasswordActivity.this, R.string.old_password_error_prompt, Toast.LENGTH_LONG).show(); break; case 3: Toast.makeText(SwitchPasswordActivity.this, R.string.Passwordless_firmware, Toast.LENGTH_LONG).show(); log.e("prompt", " 无密码版本"); break; case -1: log.e("NFC ", " IO错误"); break; case 0: Toast.makeText(SwitchPasswordActivity.this, R.string.encryption_on, Toast.LENGTH_LONG).show(); log.e("prompt ", " 未设置密码"); break; } } else if (Switch_flag == 0) { //System.arraycopy(new byte[]{(byte) 0xff, (byte) 0xfe, (byte) 0xfd, (byte) password_lenght}, 0, cmd, 0, 4); //关闭加密 switch (EPD_send.c(password)) { case 1: Toast.makeText(SwitchPasswordActivity.this, R.string.encryption_off, Toast.LENGTH_LONG).show(); break; case 2: Toast.makeText(SwitchPasswordActivity.this, R.string.old_password_error_prompt, Toast.LENGTH_LONG).show(); break; case 3: Toast.makeText(SwitchPasswordActivity.this, R.string.Passwordless_firmware, Toast.LENGTH_LONG).show(); log.e("prompt", " 无密码版本"); break; case -1: log.e("NFC ", " IO错误"); break; case 0: Toast.makeText(SwitchPasswordActivity.this, R.string.encryption_on, Toast.LENGTH_LONG).show(); log.e("prompt ", " 未设置密码"); break; } } } } } else { Toast.makeText(SwitchPasswordActivity.this, R.string.password_check,Toast.LENGTH_LONG).show(); } }
密码修改示例
protected void onNewIntent(final Intent intent) { super.onNewIntent(intent); detectedTag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG); ChangePass(); } private void ChangePass() { String password_str_old=((EditText)findViewById(R.id.password_old_edit)).getText().toString(); String password_str_new=((EditText)findViewById(R.id.password_new_edit)).getText().toString(); String password_str_match=((EditText)findViewById(R.id.password_new_again_edit)).getText().toString(); if(!"".equals(password_str_old)&&!"".equals(password_str_new)&&!"".equals(password_str_match)&&password_str_old.length()>=4&&password_str_new.length()>=4&&password_str_match.length()>=4) { if(password_str_new.equals(password_str_match)) { int password_old_lenght = password_str_old.length(); int password_new_lenght = password_str_new.length(); char[] password_old_char = password_str_old.toCharArray(); char[] password_new_char = password_str_new.toCharArray(); byte[] password_old_byte = new byte[password_old_lenght]; byte[] password_new_byte = new byte[password_new_lenght]; for(int i=0;i<password_old_lenght;i++) { password_old_byte[i] = (byte) password_old_char[i]; } for(int i=0;i<password_new_lenght;i++) { password_new_byte[i] = (byte) password_new_char[i]; } if (detectedTag != null) { String[] tech = detectedTag.getTechList(); if (tech[0].equals("android.nfc.tech.NfcA")) { tntag = NfcA.get(detectedTag); final a EPD_send = new a(); EPD_send.a(tntag);//初始化 switch (EPD_send.a(password_old_byte,password_new_byte)){ case 1: Toast.makeText(ChangePasswordActivity.this, R.string.change_success,Toast.LENGTH_LONG).show(); break; case 2: Toast.makeText(ChangePasswordActivity.this, R.string.old_password_error,Toast.LENGTH_LONG).show();break; case 3: Toast.makeText(ChangePasswordActivity.this, R.string.Passwordless_firmware,Toast.LENGTH_LONG).show();break; case -1: log.e("NFC "," IO错误"); break; } } } } else { Toast.makeText(ChangePasswordActivity.this, R.string.password_no_match,Toast.LENGTH_LONG).show(); } } else { Toast.makeText(ChangePasswordActivity.this, R.string.password_check,Toast.LENGTH_LONG).show(); } } }