[1]総務省 平成 26 年通信利用動向調査の結果
http://www.soumu.go.jp/johotsusintokei/statistics/data/150717_1.pdf [2]自転車 探険! サイクルコンピュータ
http://www.geocities.jp/jitensha_tanken/cyclecomputer.html
[3]Bluetoothのバージョンによる違いについて!プロファイル,Class
http://dokoblo.com/archives/24730297.html
[4]Bluetooth LE (5) Android 4.3 で Bluetooth LE 機器を使う (フェンリル | デベロッパーズブログ) http://blog.fenrir-inc.com/jp/2013/10/bluetooth-le-android.html
[5]Onion and garlic How to get Cadense and speed information using gattool http://onion-garlic.blogspot.jp/2015/06/how-to-get-cadense-and-speed.html [6]Bluetooth Developer Portal CSC Measurement
https://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?
u=org.bluetooth.characteristic.csc_measurement.xml [7]キャットアイ タイヤ周長ガイド
http
:// www . cateye . com / jp / tire _ guide /
[8][Java]byte型数値を符号なし数値として扱う
http://masao6739.blog89.fc2.com/blog-entry-21.html
8. 付録
本研究で作成,編集したソースコードを以下に記載する.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="jp.co.fenrir.blesample" >
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme" >
<activity android:name=".BleActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- ATTENTION: This was auto-generated to add Google Play services to your project for App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="background">#000000</color>
<color name="colorClock">#8effbb</color>
<color name="colorCase">#072100</color>
<color name="white">#fff</color>
<color name="speed">#94ffb7</color>
<color name="number">#fff</color>
<color name="textClock">#000</color>
</resources>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="background">#000000</color>
<color name="colorClock">#8effbb</color>
<color name="colorCase">#072100</color>
<color name="white">#fff</color>
<color name="speed">#94ffb7</color>
<color name="number">#fff</color>
<color name="textClock">#000</color>
</resources>
strings.xml
<resources>
<string name="app_name">BUTURI CYCLE METER</string>
<string name="kmph">km/h</string>
<string name="km">km</string>
<string name="textSpeed">SPEED</string>
<string name="textAvg">AVG</string>
<string name="textDst">DST</string>
<string name="textTime">TIME</string>
</resources>
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorCase</item>
<item name="colorPrimaryDark">#061503</item>
<item name="colorAccent">@color/colorClock</item>
</style>
</resources>
activity_ble.xml(スマートフォン用レイアウトを記載.タブレット用レイアウトは割愛する.)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/all"
android:orientation="vertical"
android:background="@color/colorCase"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bt_info"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/bt_btn"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="接続"
android:id="@+id/btn_connect"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="切断"
android:id="@+id/btn_disconnect"/>
</LinearLayout>
<View
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"></View>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/reset_btn"
android:orientation="horizontal">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="リセット"
android:id="@+id/btn_reset"
android:layout_gravity="right"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background"
android:paddingRight="5dp">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="bottom">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp"
android:text="@string/textSpeed"
android:textColor="@color/colorClock"
android:layout_weight="1"
android:gravity="center_horizontal|bottom"
android:id="@+id/textSPEED" />
</LinearLayout>
<LinearLayout
android:layout_width="420dp"
android:layout_height="match_parent"
android:id="@+id/bt_status"
android:orientation="horizontal"
android:layout_weight="1"
android:paddingBottom="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bt"
android:layout_alignParentLeft="true"
android:id="@+id/statusStrings"
android:textColor="@color/background"
android:padding="2dp"
android:background="@color/number"
android:textSize="12dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text_status"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:textColor="@color/number"
android:textSize="16dp"
android:text="---" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cycle"
android:orientation="horizontal"
android:layout_centerHorizontal="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/speedLayout"
android:layout_weight="11"
android:paddingRight="30dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|right|end">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/speedView"
android:text="0.0"
android:textColor="@color/number"
android:textIsSelectable="false"
android:textSize="54dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/speedView1"
android:textSize="16dp"
android:textColor="@color/number"
android:text="@string/kmph" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="9">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|bottom"
android:background="@color/speed">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/avarageLayout"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal|bottom"
android:layout_weight="6"
android:background="@color/background"
android:layout_marginLeft="1dp"
android:paddingTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/bt_btn"
android:textSize="16dp"
android:text="@string/textAvg"
android:id="@+id/textAVE"
android:textColor="@color/number"
android:gravity="center"
android:padding="5dp"
android:layout_marginBottom="5dp" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|bottom|end"
android:paddingTop="5dp"
android:paddingBottom="10dp"
android:paddingEnd="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24dp"
android:id="@+id/averageView"
android:text="0.0"
android:textColor="@color/number" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/averageView"
android:textSize="12dp"
android:text="@string/kmph"
android:textColor="@color/number" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/distanceLayout"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal|bottom"
android:layout_weight="5"
android:background="@color/background"
android:layout_marginLeft="1dp"
android:paddingTop="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/bt_btn"
android:textSize="16dp"
android:text="@string/textDst"
android:textColor="@color/number"
android:gravity="center"
android:padding="5dp"
android:layout_marginBottom="5dp"
android:id="@+id/textDST" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center|bottom|end"
android:paddingTop="5dp"
android:paddingBottom="10dp"
android:paddingEnd="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24dp"
android:layout_below="@+id/distanceString"
android:text="0.00"
android:id="@+id/distanceView"
android:textColor="@color/number" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView11"
android:textSize="12dp"
android:text="@string/kmph"
android:textColor="@color/number"
android:id="@+id/textView7" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|bottom"
android:layout_marginTop="5dp"
android:background="@color/colorClock">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/view_clock"
android:layout_weight="11"
android:nestedScrollingEnabled="true"
android:gravity="center_horizontal|bottom">
>
<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text_clock"
android:textColor="@color/textClock"
android:textSize="36dp"
android:format12Hour="h :mm."
android:format24Hour="h:mm."
android:paddingTop="5dp"
android:layout_gravity="bottom" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|top">
<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text_ampm_clock"
android:textColor="@color/textClock"
android:textSize="12dp"
android:format12Hour="A"
android:format24Hour=""
android:paddingTop="3dp" />
<TextClock
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text_clock_second12"
android:textColor="@color/textClock"
android:textSize="24dp"
android:format12Hour="ss"
android:format24Hour="ss"
android:textIsSelectable="false"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/view_time"
android:background="@color/background"
android:layout_weight="9"
android:paddingBottom="5dp"
android:gravity="center_vertical"
android:paddingTop="7dp"
android:paddingLeft="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/bt_btn"
android:textSize="16dp"
android:text="@string/textTime"
android:textColor="@color/number"
android:gravity="center|bottom" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="00:00:00"
android:id="@+id/runTimeView"
android:textSize="28dp"
android:textColor="@color/number"
android:layout_marginLeft="10dp"
android:gravity="bottom" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/cycle"
android:id="@+id/cycleMaps"
android:layout_marginTop="5dp" />
</LinearLayout>
BleActivity.java
package jp.co.fenrir.blesample;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothManager;
import android.bluetooth.BluetoothProfile;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
//WebView
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import java.math.*;
import java.text.DecimalFormat;
import java.util.UUID;
import jp.co.fenrir.blesample.R;
public class BleActivity extends Activity implements BluetoothAdapter.LeScanCallback { /** BLE 機器スキャンタイムアウト(ミリ秒) */
private static final long SCAN_PERIOD = 15000;
/** 検索機器の機器名"PanoBike BLE CSS" */
private static final String DEVICE_NAME = "PanoBike BLE CSS";
/** 対象のサービスUUID(サービスを指定):PanoBike BLE CSSのUUID */
private static final String DEVICE_BUTTON_SENSOR_SERVICE_UUID = "00001816-0000-1000-8000-00805f9b34fb";
/** 対象のキャラクタリスティックUUID(通知のキャラクタリスティックを指定) */
private static final String DEVICE_BUTTON_SENSOR_CHARACTERISTIC_UUID = "00002a5b-0000-1000-8000-00805f9b34fb";
/**キャラクタリスティック設定UUID(BluetoothLeGattプロジェク ト、SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIGより */
private static final String CLIENT_CHARACTERISTIC_CONFIG = "00002902-0000-1000-8000-00805f9b34fb";
private static final String TAG = "---BLESample";
private BleStatus mStatus = BleStatus.DISCONNECTED;
private Handler mHandler;
private BluetoothAdapter mBluetoothAdapter;
private BluetoothManager mBluetoothManager;
private BluetoothGatt mBluetoothGatt;
private TextView mStatusText;
private TextView speedText;
private TextView distanceText;
private TextView averageText;
private TextView runTimeText;
//サイコン
int countUp = 0; //通知毎のカウントアップ double distance = 0.0;
double speed1, speed2 = 0.0;
BigDecimal resSpeed1, resSpeed2;
BigDecimal resDistance;
BigDecimal resAverage;
int rotationNow = 0;
int intTimeNow1, intTimeNow2 = 0;
int intTimeNow = 0;
int rpc = 0; //rpc:rotation per count 1カウントごとののタイヤの回転 int intTimeDifference = 0;
double secondHour = 3600.0; //秒から時間へ変換
double tickHour = 1.0 / 1024.0 / secondHour; //タイムスタンプから時間へ変換 double milliKm = 1.0E-6; //=0.000001
double constant = milliKm / tickHour; //スピード算出に使用
double runTime = 0.0;
int timeCount = 0;
int runSecond, runMinute, runHour = 0;
double average = 0.0;
/** ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information. */
private GoogleApiClient client;
@Override
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ble);
speedText = (TextView) findViewById(R.id.speedView);
distanceText = (TextView) findViewById(R.id.distanceView);
averageText = (TextView) findViewById(R.id.averageView);
runTimeText = (TextView) findViewById(R.id.runTimeView);
//*********************WebViewによるGoogleMapsの表示 //レイアウトで指定したWebViewのIDを指定する.
WebView mapView = (WebView) findViewById(R.id.cycleMaps);
//リンクをタップしたときに標準ブラウザを起動させない mapView.setWebViewClient(new WebViewClient());
//最初のページを表示する
mapView.loadUrl("https://www.google.co.jp/maps/");
//JavaScriptの有効化
mapView.getSettings().setJavaScriptEnabled(true);
//*********************Bluetooth
mBluetoothManager = (BluetoothManager) getSystemService(BLUETOOTH_SERVICE);
mBluetoothAdapter = mBluetoothManager.getAdapter();
findViewById(R.id.btn_connect).setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) { connect();
} });
findViewById(R.id.btn_disconnect).setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) { disconnect();
} });
runOnUiThread(new Runnable() { @Override
public void run() {
DecimalFormat df = new DecimalFormat("00");
findViewById(R.id.btn_reset).setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
distance = 0.0;
average = 0.0;
countUp = 0;
runTime = 0.0;
runHour = 0;
runMinute = 0;
runSecond = 0;
BigDecimal bd1 = new BigDecimal(speed1);
resSpeed1 = bd1.setScale(1, BigDecimal.ROUND_HALF_UP);
BigDecimal bd2 = new BigDecimal(distance);
resDistance = bd2.setScale(2, BigDecimal.ROUND_HALF_UP);
BigDecimal bd3 = new BigDecimal(average);
resAverage = bd3.setScale(1, BigDecimal.ROUND_HALF_UP);
DecimalFormat df = new DecimalFormat("00");
speedText.setText("" + resSpeed1);
distanceText.setText("" + resDistance);
averageText.setText("" + resAverage);
runTimeText.setText(df.format(runHour) + ":" + df.format(runMinute) + ":" + df.format(runSecond));
} });
} });
mStatusText = (TextView) findViewById(R.id.text_status);
mHandler = new Handler() { @Override
public void handleMessage(Message msg) {
mStatusText.setText(((BleStatus) msg.obj).name());
} };
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
/** BLE機器を検索する */
private void connect() {
mHandler.postDelayed(new Runnable() { @Override
public void run() {
mBluetoothAdapter.stopLeScan(BleActivity.this);
if (BleStatus.SCANNING.equals(mStatus)) { setStatus(BleStatus.SCAN_FAILED);
} }
}, SCAN_PERIOD);
mBluetoothAdapter.stopLeScan(this);
mBluetoothAdapter.startLeScan(this);
setStatus(BleStatus.SCANNING);
}
/** BLE 機器との接続を解除する */
private void disconnect() { if (mBluetoothGatt != null) { mBluetoothGatt.close();
mBluetoothGatt = null;
setStatus(BleStatus.CLOSED);
} }
@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) { Log.d(TAG, "device found: " + device.getName());
if (DEVICE_NAME.equals(device.getName())) { setStatus(BleStatus.DEVICE_FOUND);
// 省電力のためスキャンを停止する mBluetoothAdapter.stopLeScan(this);
// GATT接続を試みる
mBluetoothGatt = device.connectGatt(this, false, mBluetoothGattCallback);
} }
private final BluetoothGattCallback mBluetoothGattCallback = new BluetoothGattCallback() { @Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { Log.d(TAG, "onConnectionStateChange: " + status + "->" + newState);
if (newState == BluetoothProfile.STATE_CONNECTED) { // GATTへ接続成功
// サービスを検索する gatt.discoverServices();
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) { // GATT通信から切断された
setStatus(BleStatus.DISCONNECTED);
mBluetoothGatt = null;
} }
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) { Log.d(TAG, "onServicesDiscovered received: " + status);
if (status == BluetoothGatt.GATT_SUCCESS) { BluetoothGattService service =
gatt.getService(UUID.fromString(DEVICE_BUTTON_SENSOR_SERVICE_UUID));
if (service == null) {
// サービスが見つからなかった
setStatus(BleStatus.SERVICE_NOT_FOUND);
} else {
// サービスを見つけた
setStatus(BleStatus.SERVICE_FOUND);
BluetoothGattCharacteristic characteristic =
service.getCharacteristic(UUID.fromString(DEVICE_BUTTON_SENSOR_CHARACTERISTI C_UUID));
if (characteristic == null) {
// キャラクタリスティックが見つからなかった
setStatus(BleStatus.CHARACTERISTIC_NOT_FOUND);
} else {
// キャラクタリスティックを見つけた
// Notification を要求する
boolean registered = gatt.setCharacteristicNotification(characteristic, true);
// Characteristic のNotification 有効化
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
UUID.fromString(CLIENT_CHARACTERISTIC_CONFIG));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
gatt.writeDescriptor(descriptor);
if (registered) {
// Characteristics通知設定完了
setStatus(BleStatus.NOTIFICATION_REGISTERED);
} else {
// Characteristics通知設定失敗
setStatus(BleStatus.NOTIFICATION_REGISTER_FAILED);
} } } } }
@Override
public void onCharacteristicRead(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic, int status) {
Log.d(TAG, "onCharacteristicRead: " + status);
if (status == BluetoothGatt.GATT_SUCCESS) { // READ成功
} }
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) { //キャラクタリスティックの値が変化後の処理(サイクルコンピュータとして機能するための処理) Log.d(TAG, "*************************onCharacteristicChanged**********************************");
// Characteristicの値更新通知
if (DEVICE_BUTTON_SENSOR_CHARACTERISTIC_UUID.equals(characteristic.getUuid().toString())) { Byte value = characteristic.getValue()[1]; //ホイールの累積回転数を参照
Byte time1 = characteristic.getValue()[5]; //タイムスタンプ1 Byte time2 = characteristic.getValue()[6]; //タイムスタンプ2
//byte型数値を符号なし数値として扱う int intValue = value & 0xFF;
int intTime1 = time1 & 0xFF;
int intTime2 = time2 & 0xFF;
intTimeNow1 = intTime1;
intTimeNow2 = intTime2;
int rotation = intValue;
if (countUp == 0) { //最初のカウントの場合 rotationNow = rotation;
intTimeNow = intTimeNow1 + 256 * intTimeNow2;
} else { //カウントが2 回目以降の場合
//タイムスタンプの値の差を算出 int intTimeBefore = intTimeNow;
intTimeNow = intTimeNow1 + 256 * intTimeNow2;
if (intTimeBefore != intTimeNow) { if (intTimeBefore <= intTimeNow)
intTimeDifference = intTimeNow - intTimeBefore;
else { //もしintTimeNowが上限(65535)に達したならば intTimeDifference = 65536 - intTimeBefore + intTimeNow;
} } else {
intTimeDifference = 0;
}
Log.d(TAG, "* count=" + countUp + " * intTime1,2= " + intTime1 + " : " + intTime2 + "
intTimeNow= " + intTimeNow + " * intTimeDifference=" + intTimeDifference);
//countUp,intTime1,2,intTimeNow,intTimeDifferenceを表示
int rotationBefore = rotationNow;
rotationNow = rotation;
//通知毎のタイヤ回転数(rpc:rotation per count)算出 if (rotationBefore < rotationNow) {
rpc = rotationNow - rotationBefore;
} else if (rotationNow == rotationBefore) { //intValueに変化が無かったら rpc = 0;
} else if (rotationNow < rotationBefore) { //intValueNowが上限(255)に達したならば rpc = rotationNow + (256 - rotationBefore);
}
//検証用ログ表示*****************************回転数とタイムスタンプ差)
Log.d(TAG, "通知毎の回転数=" + rpc + "(回/通知) * intTimeDifference=" + intTimeDifference);
double tirePerimeter = 2105.0; //タイヤ周長(2105mm)