Skip to content

Commit

Permalink
supercommit
Browse files Browse the repository at this point in the history
  • Loading branch information
diegocardoso93 committed Jun 30, 2017
1 parent 80d2cce commit ab75bed
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ class DeviceControl {
val unknownServiceString = ""
val unknownCharaString = ""
val gattServiceData = ArrayList<HashMap<String, String>>()
val gattCharacteristicData = ArrayList<ArrayList<HashMap<String, String>>>()
mGattCharacteristics = ArrayList<ArrayList<BluetoothGattCharacteristic>>()
// Loops through available GATT Services.
for (gattService in gattServices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ class MainActivity : AppCompatActivity() {
var mScannerView: ScannerView? = null
var packSend: ByteArray = byteArrayOf(0)

// Sub-activities result values
companion object {
val RESULT_BLE_OK = 1;
val RESULT_SETTINGS_SELECTED = 2;
val RESULT_BLE_OK = 1
val RESULT_SETTINGS_SELECTED = 2
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -38,16 +39,19 @@ class MainActivity : AppCompatActivity() {
unbindService(deviceControl.mServiceConnection)
deviceControl.mBluetoothLeService = null
}
var tvStatus: TextView = findViewById(R.id.tvStatus) as TextView
tvStatus.text = "parado"
val deviceScanIntent = Intent(this, DeviceScanActivity::class.java)
startActivityForResult(deviceScanIntent, RESULT_BLE_OK)
var tvStatus: TextView = findViewById(R.id.tvStatus) as TextView
tvStatus.setText("parado")
}

val fabSettings = findViewById(R.id.config) as FloatingActionButton
fabSettings.setOnClickListener { view ->
val settingsIntent = Intent(this, SettingsActivity::class.java)
startActivityForResult(settingsIntent, RESULT_SETTINGS_SELECTED)
packSend = byteArrayOf(0)
}

mScannerView = findViewById(R.id.scannerView) as ScannerView

registerReceiver(broadcastReceiver, IntentFilter("PACKAGE_RECEIVED"))
Expand All @@ -66,7 +70,7 @@ class MainActivity : AppCompatActivity() {
registerReceiver(deviceControl.mGattUpdateReceiver, deviceControl.makeGattUpdateIntentFilter())
if (deviceControl.mBluetoothLeService != null) {
val result = deviceControl.mBluetoothLeService!!.connect(deviceControl.mDeviceAddress)
Log.d("rds", "Connect request result=" + result)
Log.d("MainActivity", "Connect request result = " + result)
}
} else if (resultCode == RESULT_SETTINGS_SELECTED) {
if (data!!.hasExtra("REFRESH_RATE_SELECTED")) {
Expand Down Expand Up @@ -101,6 +105,12 @@ class MainActivity : AppCompatActivity() {
unregisterReceiver(broadcastReceiver)
}

override fun onPause() {
super.onPause()
var tvStatus: TextView = findViewById(R.id.tvStatus) as TextView
tvStatus.text = "parado"
}

override fun onBackPressed() {
super.onBackPressed()
moveTaskToBack(true)
Expand All @@ -120,7 +130,7 @@ class MainActivity : AppCompatActivity() {
mScannerView?.distance = distance
mScannerView?.insertGraphPoint(distance)
mScannerView?.invalidate()
packSend = MessageTemplates().REQ_READ_SCANNER_SENSOR_PACKAGE_TEMPLATE
packSend = if (packSend.size == 1) MessageTemplates().REQ_READ_SCANNER_SENSOR_PACKAGE_TEMPLATE else packSend
updateLabels(arrayPackInt, "recebendo")

val tvConfiguredRefreshRate = findViewById(R.id.tvConfiguredRefreshRate) as TextView
Expand All @@ -144,15 +154,15 @@ class MainActivity : AppCompatActivity() {

internal fun updateLabels(arrayPackInt: IntArray, status: String) {
var tvSended: TextView = findViewById(R.id.tvSended) as TextView
val pacoteEnviado: String = "UPE\n" + getPackAsFormattedString(byteArrayToIntArray(packSend))
tvSended.setText(pacoteEnviado)
val pacoteEnviado: String = "E\n" + getPackAsFormattedString(byteArrayToIntArray(packSend))
tvSended.text = pacoteEnviado

var tvReceived: TextView = findViewById(R.id.tvReceived) as TextView
val pacoteRecebido: String = "UPR\n" + getPackAsFormattedString(arrayPackInt)
tvReceived.setText(pacoteRecebido)
val pacoteRecebido: String = "R\n" + getPackAsFormattedString(arrayPackInt)
tvReceived.text = pacoteRecebido

var tvStatus: TextView = findViewById(R.id.tvStatus) as TextView
tvStatus.setText(status)
tvStatus.text = status
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@ import java.util.*
* Created by dieg0 on 16/06/2017.
*/
class ScannerView(context: Context, attrs: AttributeSet) : View(context, attrs) {
private val paint:Paint = Paint()
private val paint: Paint = Paint()

var centerX = 0f
var centerY = 0f
var MAX_DISTANCE = 250f
var lineDensity = 0.4f
var offsetY = 20f
val offsetX = 80f
var angle = 270f
var distance = 0f
val offsetX = 80f
var graphPoints = arrayListOf<Float>()

init {
var i : Int
val rand = Random()
for (i in 0..360){
var x = 30f
Expand All @@ -40,7 +39,7 @@ class ScannerView(context: Context, attrs: AttributeSet) : View(context, attrs)
}

override fun onDraw(canvas: Canvas) {
blank(canvas)
background(canvas)

val width = 300f
offsetY = 0f
Expand Down Expand Up @@ -82,6 +81,7 @@ class ScannerView(context: Context, attrs: AttributeSet) : View(context, attrs)
canvas.drawText("dx", 10f, 318f, paint)
canvas.drawText("cm", 10f, 330f, paint)

// update graph
for (i in 0..359) {
paint.setARGB(255, 0, 0, 0)
paint.strokeWidth = 3f
Expand All @@ -94,13 +94,16 @@ class ScannerView(context: Context, attrs: AttributeSet) : View(context, attrs)
}
}

fun blank(canvas: Canvas) {
fun background(canvas: Canvas) {
paint.setARGB(25, 255, 255, 1)
canvas.drawRect(0f, 0f, canvas.width.toFloat(), canvas.height.toFloat(), paint)
}

/*
*
/* \ | /
* \ | /
*____\|/_____
* / \
* / \
*/
fun drawGuideLines(canvas: Canvas) {
val angles = floatArrayOf(0f, 45f, 135f, 180f, 225f, 270f, 315f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@
android:layout_marginTop="8dp"
android:text=""
app:layout_constraintTop_toTopOf="parent"
android:layout_marginRight="20dp"
android:layout_marginRight="25dp"
app:layout_constraintRight_toRightOf="parent" />

<TextView
android:id="@+id/tvSended"
android:layout_width="14dp"
android:layout_width="24dp"
android:layout_height="412dp"
android:layout_marginTop="8dp"
android:text=""
Expand Down
33 changes: 17 additions & 16 deletions DuinoUltrasonicScanner/DuinoUltrasonicScanner.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@
#define FAKE_SECURITY_KEY {0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00}
#define IOT 0x02
#define EOT 0x04

NewPing scanner(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

BLEPeripheral blePeripheral;
BLEService bleService("19B10010-E8F2-537E-4F6C-D104768A1214");
BLECharacteristic bleCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite | BLENotify, MAX_PACKAGE_SIZE);

typedef struct PackageTemplate {
byte iot; // init of transmission
byte sk[8]; // security key
byte pl; // payload length
byte payload[8];
byte crc; //crc
byte eot; // end of transmission
byte iot; // init of transmission
byte sk[8]; // security key
byte pl; // payload length
byte payload[8]; // data
byte crc; // cyclic redundancy check
byte eot; // end of transmission
} Package;

Package blePack;

/* Instructions */
enum {
NOP,
REQ_READ_SCANNER_SENSOR,
Expand All @@ -49,12 +51,10 @@ enum {
RESP_SET_SCANNER_MAX_DISTANCE
};

long previousMillis = 0;

void setup() {
Serial.begin(9600);

blePeripheral.setLocalName("ARDUINO 101");
blePeripheral.setLocalName("ARDUINO UTRASONIC SCANNER");
blePeripheral.setAdvertisedServiceUuid(bleService.uuid());

blePeripheral.addAttribute(bleService);
Expand All @@ -63,13 +63,14 @@ void setup() {
blePeripheral.begin();
}

unsigned int analogVal = 0;
unsigned long pingVal = 0;
byte bleByteArray[MAX_PACKAGE_SIZE];
int refreshRate = 6; // samples per second
int delayRate = 1000/refreshRate;
boolean stopped = true;
unsigned int maxDistance = 250;
unsigned int analogVal = 0; // for save read angle
unsigned long pingVal = 0; // for save read distance
byte bleByteArray[MAX_PACKAGE_SIZE]; // final package to send
int refreshRate = 6; // samples per second
int delayRate = 1000/refreshRate; // in ms
long previousMillis = 0; // non-blocking time control
boolean stopped = true; // stopp notify control
unsigned int maxDistance = MAX_DISTANCE; // max distance control

void loop() {

Expand Down

0 comments on commit ab75bed

Please sign in to comment.