<commit_before>package com.uxxu.konashi.lib;

import android.app.Activity;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;
import android.content.Context;

import com.uxxu.konashi.lib.action.AioAnalogReadAction;
import com.uxxu.konashi.lib.action.BatteryLevelReadAction;
import com.uxxu.konashi.lib.action.HardwareResetAction;
import com.uxxu.konashi.lib.action.I2cModeAction;
import com.uxxu.konashi.lib.action.I2cReadAction;
import com.uxxu.konashi.lib.action.I2cSendConditionAction;
import com.uxxu.konashi.lib.action.I2cSetReadParamAction;
import com.uxxu.konashi.lib.action.I2cWriteAction;
import com.uxxu.konashi.lib.action.PioDigitalWriteAction;
import com.uxxu.konashi.lib.action.PioPinModeAction;
import com.uxxu.konashi.lib.action.PioPinPullupAction;
import com.uxxu.konashi.lib.action.PwmDutyAction;
import com.uxxu.konashi.lib.action.PwmLedDriveAction;
import com.uxxu.konashi.lib.action.PwmPeriodAction;
import com.uxxu.konashi.lib.action.PwmPinModeAction;
import com.uxxu.konashi.lib.action.UartBaudrateAction;
import com.uxxu.konashi.lib.action.UartModeAction;
import com.uxxu.konashi.lib.action.UartWriteAction;
import com.uxxu.konashi.lib.dispatcher.AioStoreUpdater;
import com.uxxu.konashi.lib.dispatcher.CharacteristicDispatcher;
import com.uxxu.konashi.lib.dispatcher.DispatcherContainer;
import com.uxxu.konashi.lib.dispatcher.I2cStoreUpdater;
import com.uxxu.konashi.lib.dispatcher.PioStoreUpdater;
import com.uxxu.konashi.lib.dispatcher.PwmStoreUpdater;
import com.uxxu.konashi.lib.dispatcher.UartStoreUpdater;
import com.uxxu.konashi.lib.filter.AioAnalogReadFilter;
import com.uxxu.konashi.lib.filter.BatteryLevelReadFilter;
import com.uxxu.konashi.lib.filter.I2cReadFilter;
import com.uxxu.konashi.lib.store.AioStore;
import com.uxxu.konashi.lib.store.I2cStore;
import com.uxxu.konashi.lib.store.PioStore;
import com.uxxu.konashi.lib.store.PwmStore;
import com.uxxu.konashi.lib.store.UartStore;

import org.jdeferred.DoneCallback;
import org.jdeferred.DonePipe;
import org.jdeferred.Promise;
import org.jdeferred.android.AndroidDeferredManager;

import java.util.UUID;

import info.izumin.android.bletia.BleState;
import info.izumin.android.bletia.Bletia;
import info.izumin.android.bletia.BletiaException;
import info.izumin.android.bletia.action.Action;


/**
 * konashiを管理するメインクラス
 * 
 * @author monakaz, YUKAI Engineering
 * http://konashi.ux-xu.com
 * ========================================================================
 * Copyright 2014 Yukai Engineering Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
public class KonashiManager {
    // konashi members
    // PIO
    private PioStore mPioStore;
    private CharacteristicDispatcher<PioStore, PioStoreUpdater> mPioDispatcher;

    // PWM
    private PwmStore mPwmStore;
    private CharacteristicDispatcher<PwmStore, PwmStoreUpdater> mPwmDispatcher;

    // AIO
    private AioStore mAioStore;
    private CharacteristicDispatcher<AioStore, AioStoreUpdater> mAioDispatcher;

    // I2C
    private I2cStore mI2cStore;
    private CharacteristicDispatcher<I2cStore, I2cStoreUpdater> mI2cDispatcher;

    // UART
    private UartStore mUartStore;
    private CharacteristicDispatcher<UartStore, UartStoreUpdater> mUartDispatcher;

    private Bletia mBletia;
    private EventEmitter mEmitter;
    private CallbackHandler mCallbackHandler;
    private DispatcherContainer mDispacherContainer;

    private BluetoothDevice mDevice;
    private ConnectionHelper mConnectionHelper;

    ///////////////////////////
    // Initialization
    ///////////////////////////


    public KonashiManager() {
        mEmitter = new EventEmitter();
        mDispacherContainer = new DispatcherContainer();
        mCallbackHandler = new CallbackHandler(this, mEmitter, mDispacherContainer);
        // PIO
        mPioDispatcher = mDispacherContainer.getPioDispatcher();
        mPioStore = new PioStore(mPioDispatcher);

        // PWM
        mPwmDispatcher = mDispacherContainer.getPwmDispatcher();
        mPwmStore = new PwmStore(mPwmDispatcher);

        // AIO
        mAioDispatcher = mDispacherContainer.getAioDispatcher();
        mAioStore = new AioStore(mAioDispatcher);

        // I2C
        mI2cDispatcher = mDispacherContainer.getI2cDispatcher();
        mI2cStore = new I2cStore(mI2cDispatcher);

        // UART
        mUartDispatcher = mDispacherContainer.getUartDispatcher();
        mUartStore = new UartStore(mUartDispatcher);
    }

    public void initialize(Context context) {
        mBletia = new Bletia(context);
        mBletia.addListener(mCallbackHandler);
        mConnectionHelper = new ConnectionHelper(mConnectionHelperCallback, context);
    }

    /**
     * konashiを見つける(konashiのみBLEデバイスリストに表示する)
     * @param activity BLEデバイスリストを表示する先のActivity
     */
    public void find(Activity activity){
        mConnectionHelper.find(activity, true, null);
    }

    /**
     * konashiを見つける
     * @param activity BLEデバイスリストを表示する先のActivity
     * @param isShowKonashiOnly konashiだけを表示するか、すべてのBLEデバイスを表示するか
     */
    public void find(Activity activity, boolean isShowKonashiOnly){
        mConnectionHelper.find(activity, isShowKonashiOnly, null);
    }

    /**
     * 名前を指定してkonashiを探索。
     * @param activity BLEデバイスリストを表示する先のActivity
     * @param name konashiの緑色のチップに貼られているシールに書いている数字(例: konashi#0-1234)
     */
    public void findWithName(Activity activity, String name){
        mConnectionHelper.find(activity, true, name);
    }

    /**
     * 接続しているkonashiの名前を取得する
     * @return konashiの名前
     */
    public String getPeripheralName() {
        return (mDevice == null) ? "" : mDevice.getName();
    }

    /**
     * konashiとの接続を解除する
     */
    public void disconnect(){
        mBletia.disconenct();
    }

    /**
     * konashiと接続済みかどうか
     * @return konashiと接続済みだったらtrue
     */
    public boolean isConnected(){
        return mBletia.getState() == BleState.CONNECTED;
    }<commit_msg>Fix KonashiManager#isConnected()<commit_after>package com.uxxu.konashi.lib;

import android.app.Activity;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattService;
import android.content.Context;

import com.uxxu.konashi.lib.action.AioAnalogReadAction;
import com.uxxu.konashi.lib.action.BatteryLevelReadAction;
import com.uxxu.konashi.lib.action.HardwareResetAction;
import com.uxxu.konashi.lib.action.I2cModeAction;
import com.uxxu.konashi.lib.action.I2cReadAction;
import com.uxxu.konashi.lib.action.I2cSendConditionAction;
import com.uxxu.konashi.lib.action.I2cSetReadParamAction;
import com.uxxu.konashi.lib.action.I2cWriteAction;
import com.uxxu.konashi.lib.action.PioDigitalWriteAction;
import com.uxxu.konashi.lib.action.PioPinModeAction;
import com.uxxu.konashi.lib.action.PioPinPullupAction;
import com.uxxu.konashi.lib.action.PwmDutyAction;
import com.uxxu.konashi.lib.action.PwmLedDriveAction;
import com.uxxu.konashi.lib.action.PwmPeriodAction;
import com.uxxu.konashi.lib.action.PwmPinModeAction;
import com.uxxu.konashi.lib.action.UartBaudrateAction;
import com.uxxu.konashi.lib.action.UartModeAction;
import com.uxxu.konashi.lib.action.UartWriteAction;
import com.uxxu.konashi.lib.dispatcher.AioStoreUpdater;
import com.uxxu.konashi.lib.dispatcher.CharacteristicDispatcher;
import com.uxxu.konashi.lib.dispatcher.DispatcherContainer;
import com.uxxu.konashi.lib.dispatcher.I2cStoreUpdater;
import com.uxxu.konashi.lib.dispatcher.PioStoreUpdater;
import com.uxxu.konashi.lib.dispatcher.PwmStoreUpdater;
import com.uxxu.konashi.lib.dispatcher.UartStoreUpdater;
import com.uxxu.konashi.lib.filter.AioAnalogReadFilter;
import com.uxxu.konashi.lib.filter.BatteryLevelReadFilter;
import com.uxxu.konashi.lib.filter.I2cReadFilter;
import com.uxxu.konashi.lib.store.AioStore;
import com.uxxu.konashi.lib.store.I2cStore;
import com.uxxu.konashi.lib.store.PioStore;
import com.uxxu.konashi.lib.store.PwmStore;
import com.uxxu.konashi.lib.store.UartStore;

import org.jdeferred.DoneCallback;
import org.jdeferred.DonePipe;
import org.jdeferred.Promise;
import org.jdeferred.android.AndroidDeferredManager;

import java.util.UUID;

import info.izumin.android.bletia.BleState;
import info.izumin.android.bletia.Bletia;
import info.izumin.android.bletia.BletiaException;
import info.izumin.android.bletia.action.Action;


/**
 * konashiを管理するメインクラス
 * 
 * @author monakaz, YUKAI Engineering
 * http://konashi.ux-xu.com
 * ========================================================================
 * Copyright 2014 Yukai Engineering Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
public class KonashiManager {
    // konashi members
    // PIO
    private PioStore mPioStore;
    private CharacteristicDispatcher<PioStore, PioStoreUpdater> mPioDispatcher;

    // PWM
    private PwmStore mPwmStore;
    private CharacteristicDispatcher<PwmStore, PwmStoreUpdater> mPwmDispatcher;

    // AIO
    private AioStore mAioStore;
    private CharacteristicDispatcher<AioStore, AioStoreUpdater> mAioDispatcher;

    // I2C
    private I2cStore mI2cStore;
    private CharacteristicDispatcher<I2cStore, I2cStoreUpdater> mI2cDispatcher;

    // UART
    private UartStore mUartStore;
    private CharacteristicDispatcher<UartStore, UartStoreUpdater> mUartDispatcher;

    private Bletia mBletia;
    private EventEmitter mEmitter;
    private CallbackHandler mCallbackHandler;
    private DispatcherContainer mDispacherContainer;

    private BluetoothDevice mDevice;
    private ConnectionHelper mConnectionHelper;

    ///////////////////////////
    // Initialization
    ///////////////////////////


    public KonashiManager() {
        mEmitter = new EventEmitter();
        mDispacherContainer = new DispatcherContainer();
        mCallbackHandler = new CallbackHandler(this, mEmitter, mDispacherContainer);
        // PIO
        mPioDispatcher = mDispacherContainer.getPioDispatcher();
        mPioStore = new PioStore(mPioDispatcher);

        // PWM
        mPwmDispatcher = mDispacherContainer.getPwmDispatcher();
        mPwmStore = new PwmStore(mPwmDispatcher);

        // AIO
        mAioDispatcher = mDispacherContainer.getAioDispatcher();
        mAioStore = new AioStore(mAioDispatcher);

        // I2C
        mI2cDispatcher = mDispacherContainer.getI2cDispatcher();
        mI2cStore = new I2cStore(mI2cDispatcher);

        // UART
        mUartDispatcher = mDispacherContainer.getUartDispatcher();
        mUartStore = new UartStore(mUartDispatcher);
    }

    public void initialize(Context context) {
        mBletia = new Bletia(context);
        mBletia.addListener(mCallbackHandler);
        mConnectionHelper = new ConnectionHelper(mConnectionHelperCallback, context);
    }

    /**
     * konashiを見つける(konashiのみBLEデバイスリストに表示する)
     * @param activity BLEデバイスリストを表示する先のActivity
     */
    public void find(Activity activity){
        mConnectionHelper.find(activity, true, null);
    }

    /**
     * konashiを見つける
     * @param activity BLEデバイスリストを表示する先のActivity
     * @param isShowKonashiOnly konashiだけを表示するか、すべてのBLEデバイスを表示するか
     */
    public void find(Activity activity, boolean isShowKonashiOnly){
        mConnectionHelper.find(activity, isShowKonashiOnly, null);
    }

    /**
     * 名前を指定してkonashiを探索。
     * @param activity BLEデバイスリストを表示する先のActivity
     * @param name konashiの緑色のチップに貼られているシールに書いている数字(例: konashi#0-1234)
     */
    public void findWithName(Activity activity, String name){
        mConnectionHelper.find(activity, true, name);
    }

    /**
     * 接続しているkonashiの名前を取得する
     * @return konashiの名前
     */
    public String getPeripheralName() {
        return (mDevice == null) ? "" : mDevice.getName();
    }

    /**
     * konashiとの接続を解除する
     */
    public void disconnect(){
        mBletia.disconenct();
    }

    /**
     * konashiと接続済みかどうか
     * @return konashiと接続済みだったらtrue
     */
    public boolean isConnected(){
        return (mBletia.getState() == BleState.CONNECTED) || isReady();
    }
{'fraction_non_alphanumeric': 0.10791202077287307, 'fraction_numerical': 0.005040476554146938, 'mean_word_length': 3.8752792256142965, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '681272', 'n_tokens_mistral': 4530, 'n_tokens_neox': 4298, 'n_words': 746}