2013年11月2日 星期六

Amarino 密技 - isCorrectAddressFormat 函數

Amarino 有一個不為人知的函數  isCorrectAddressFormat,
你可以用它來判斷使用者所輸入的藍芽位址格式是否正確,
我發現這個還蠻好用的,
它的原始碼如下:

public static boolean isCorrectAddressFormat(String s)
{
        if(s.length() != 17)
            return false;
        else
            return Pattern.matches("[[A-F][0-9][:]]+", s.toUpperCase());
}

用法:

if(Amarino.isCorrectAddressFormat(strBluetoothAddress))
{
  Log.d("xxx", "Correct BT Format.");
} else {
  Log.d("xxx", "Uncorrect BT Format.");
}

反編譯 Android apk


你可以參考底下這一篇文章逐步將 .apk 檔反編譯成 .jar
網址 http://stackoverflow.com/questions/3593420/android-getting-source-code-from-an-apk-file

Procedure for decoding .apk files, step-by-step method:

Step 1:

Make a new folder and put .apk file in it (which you want to decode). Now rename the extension of this .apk file to .zip (eg.: rename from filename.apk to filename.apk.zip) and save it. Now you get classes.dex files, etc. At this stage you are able to see drawable but not xml and java files, so continue.

Step 2:

Now extract this zip apk file in the same folder (or NEW FOLDER). Now download dex2jar from this linkhttp://code.google.com/p/dex2jar/  and extract it to the same folder (or NEW FOLDER). Now open command prompt and change directory to that folder (or NEW FOLDER). Then write dex2jar classes.dex and press enter. Now you get classes.dex.dex2jar file in the same folder. Then download java decompiler from http://java.decompiler.free.fr/?q=jdgui  and now double click on jd-gui and click on open file. Then open classes.dex.dex2jar file from that folder. Now you get class files and save all these class files (click on file then click "save all sources" in jd-gui) by src name. At this stage you get java source but the xml files are still unreadable, so continue.

Step 3:

Now open another new folder and put these files
  1. put .apk file which you want to decode
  2. download apktool v1.x  AND apktool install window  (both can be downloaded at the same location) and put in the same folder
  3. download framework-res.apk  file and put in the same folder (Not all apk file need framework-res.apk file)
  4. Open a command window
  5. Navigate to the root directory of APKtool and type the following command: apktool if framework-res.apk
  6. apktool d "fname".apk ("fname" denotes filename which you want to decode)
now you get a file folder in that folder and now you can easily read xml files also.

Step 4:

It's not any step just copy contents of both folder(in this case both new folder)to the single one
and now enjoy with source code...






2013年10月6日 星期日

開始進入 Arduino 的殿堂

開始進入 Arduino 的殿堂

只要您依照下面的步驟做,就可以輕鬆地進入 Arduino 的奇幻世界。


1. 取得 Arduino 模組和 USB 連接線。


2. 下載 Arduino 軟體。
您可以到 Arduino 官網下再軟體,網址 http://arduino.cc/en/Main/Software
下載完畢後要解壓縮,並將 arduino.exe 傳送到桌面建立捷徑。


3. 用 USB 連接線將電腦和 Arduino 模組連接起來。


4. 安裝驅動程式。
電腦會要求安裝兩個驅動程式,USB Serial Port 驅動程式和 FT232 晶片驅動程式。
如果電腦找不到驅動程式,您可以改手動到 <Arduino>\drivers\ 資料夾裏尋找。


5. 啟動 Arduino 軟體。
快點兩下 arduino.exe 就可以啟動 Arduino。



6. 開啟範例程式。
您可以點選下拉功能表開啟範例程式 File > examples > 01.Basics > Blink。





7. 選擇 Arduino 模組型號。
您可以點選下拉功能表開啟範例程式 Tools > Board > Arduino Uno。
如果您的 Arduino 不是 Uno,請選擇您自己的 Arduino 型號。



8. 選擇連接埠。
您可以點選下拉功能表開啟範例程式 Tools > Serial Port > COM3。
如果您的 Arduino 不是接在 COM3,請選擇您自己的連接埠。



9. 上載程式到 Arduino 模組。
您可以點選下拉功能表下方的「Upload」工具鈕。


如果程式都沒有錯誤並且成功上載到 Arduino 板子,編輯區下方會提示「Done uploading.」。




相關連結:

1. Arduino 官網 http://arduino.cc/en/Guide/Windows

漸亮漸暗(Fading)

漸亮漸暗(Fading)

目的: 讓 LED 持續地逐漸變亮後再逐漸變暗。


材料清單: 
1. Arduino 模組 x1
2. 麵包板 x1
3. 線材若干
4. LED x1
5. 220R 電阻 x1


電路圖:



接線圖:




程式碼:

/*
 Fade.pde 
 使用 
 analogWrite()  讓插在 9 pin 上的 LED 逐漸變亮後又變暗。
 */

int led = 9;           // the pin that the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup()  { 
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
} 

// the loop routine runs over and over again forever:
void loop()  { 
  // set the brightness of pin 9:
  analogWrite(led, brightness);    

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade: 
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ; 
  }     
  // wait for 30 milliseconds to see the dimming effect    
  delay(30);                            
}


相關連結:

1. Arduino 官網 http://arduino.cc/en/Tutorial/Fade


魚菜共生(Aquaponics system)

近日推出,敬請期待。

















參考資料:

維基百科 http://zh.wikipedia.org/wiki/%E9%AD%9A%E8%8F%9C%E5%85%B1%E7%94%9F



安裝 Processing

Processing 是一套自由贊助的軟體,它有強大的處理圖形和數字的能力,有不少科學家和藝術家用它來創作,而 Arduino 的使用者更用它來製作互動裝置。另外,你也可以使用 Processing 編譯器將程式編譯成 Android APP,有了
這項功能更是讓 Android 和 Arduino 可以緊密結合在一起。

官網 http://www.processing.org/


下載

切換網頁到 https://www.processing.org/download/,先選擇贊助金額,如果不贊助請選擇 No Donation,接著點擊下方的 Download,然後再依照您的作業系統版本點擊合適的下載。
我選擇的是 Windows 32bit 版本。


安裝

將 processing-2.2.1-windows32.zip 解壓縮,然後把 processing.exe 做出桌面捷徑。


函式庫

Processing 有很多函式庫可以使用,有處理影像、聲音、網路和動畫...等等,詳 http://www.processing.org/reference/libraries/。
其中有一個 Serial 函式庫,可以用它來聯繫 Arduino,在稍後的貼文將會介紹。



您可能也會喜歡

1. Arduino and Processing http://playground.arduino.cc/interfacing/processing

2. Servo motor + Arduino + Processing http://forum.processing.org/two/discussion/2469/servo-motor-arduino-processing/p1

3. Processing and Android https://github.com/processing/processing-android/wiki





安裝 Amarino

近日推出,敬請期待。