Commit b09f413a authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca

Fix delay too short - change feedback logic

parent dc2dd681
package it.lavermicocca.giacomo.beautifulnotification
import android.util.Log
import it.lavermicocca.giacomo.beautifulnotification.mappers.Arguments
class HelperMessages{
enum class STATUS { UNKNOWN, TIMEOUT, GARAGE_OPEN, GARAGE_CLOSE, BRIGHTNESS }
enum class STATUS { UNKNOWN, TIMEOUT, GARAGE_OPENED, GARAGE_CLOSED, BRIGHTNESS, CANCELLO_OPEN_RESPONSE, GARAGE_OPEN_RESPONSE, LED_ACCESO }
fun Do(messaggio: String) : STATUS{
when(messaggio)
{
"L.C. : r : 37 1"-> {
Log.e("TTAG", "UNO")
return STATUS.GARAGE_OPEN
}
"L.C. : r : 37 0"-> {
Log.e("TTAG", "ZERO")
return STATUS.GARAGE_CLOSE
}
"Timeout command" -> {
Log.e("TTAG", "Timeout")
return STATUS.TIMEOUT
}
}
if(messaggio.contains("L.C. : b "))
if(messaggio.contains("L.C. : p : 21", true)){
return STATUS.GARAGE_OPEN_RESPONSE
} else if(messaggio.contains("L.C. : p : 17", true)){
return STATUS.CANCELLO_OPEN_RESPONSE
} else if(messaggio.contains("L.C. : p : 13", true)){
return STATUS.LED_ACCESO
} else if(messaggio.contains("L.C. : r : 37 1", true)){
Log.e("TTAG", "UNO")
return STATUS.GARAGE_OPENED
} else if (messaggio.contains("L.C. : r : 37 0", true)){
Log.e("TTAG", "ZERO")
return STATUS.GARAGE_CLOSED
} else if(messaggio.contains("Timeout command", true)){
Log.e("TTAG", "Timeout")
return STATUS.TIMEOUT
} else if(messaggio.contains("L.C. : b "))
{
return STATUS.BRIGHTNESS
}
......
......@@ -9,7 +9,6 @@ import android.widget.Toast
import it.lavermicocca.giacomo.beautifulnotification.mappers.Arguments
import it.lavermicocca.giacomo.beautifulnotification.services.Helper
import okhttp3.*
import unsigned.Ubyte
import java.io.IOException
class Sender(val context: Context) {
......@@ -56,7 +55,6 @@ class Sender(val context: Context) {
//UNO
fun SendPin(pin: Int) {
Helper.StartForegroundServiceNotification(context, "CANCELLO/GARAGE IN APERTURA...", Helper.FULL_ON)
val prf = context.getSharedPreferences("myPref", Context.MODE_PRIVATE)
......@@ -71,8 +69,6 @@ class Sender(val context: Context) {
val client = OkHttpClient()
Helper.StartForegroundServiceNotification(context, "${Arguments.PIN} $pin", Helper.FULL_ON)
client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
e.printStackTrace()
......@@ -132,10 +128,13 @@ class Sender(val context: Context) {
override fun run() {
//TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
Toast.makeText(context, networkResp, Toast.LENGTH_LONG).show()
if(networkResp.contains(Arguments.PIN, true))
//Helper.StartForegroundServiceNotification(context, networkResp, Helper.FULL_ON)
if(networkResp.contains(Arguments.BRIGHTNESS, true))
{
Log.e("TTAG", "RICHIESTA PIN")
SendCheck(false)
//SendCheck(false)
}
}
})
......@@ -189,7 +188,7 @@ class Sender(val context: Context) {
//DUE
fun SendCheck(oneShot:Boolean) {
Thread.sleep(1000);
Thread.sleep(3000);
val prf = context.getSharedPreferences("myPref", Context.MODE_PRIVATE)
val ipServer = prf.getString("ip_server", "192.168.43.176")
......@@ -216,26 +215,31 @@ class Sender(val context: Context) {
if(status == HelperMessages.STATUS.TIMEOUT) {
Helper.StartForegroundServiceNotification(context, "TIMEOUT su CHECK", Helper.FULL_ON_STOP_PROGRESS)
} else if(status == HelperMessages.STATUS.GARAGE_CLOSED) {
Helper.StartForegroundServiceNotification(context, "IL GARAGE É APERTO!", Helper.FULL_ON_STOP_PROGRESS)
} else if(status == HelperMessages.STATUS.GARAGE_OPENED) {
Helper.StartForegroundServiceNotification(context, "IL GARAGE É CHIUSO!", Helper.FULL_ON_STOP_PROGRESS)
} else if(status == HelperMessages.STATUS.GARAGE_OPEN_RESPONSE) {
Helper.StartForegroundServiceNotification(context, "GARAGE IN APERTURA...", Helper.FULL_ON_STOP_PROGRESS)
} else if(status == HelperMessages.STATUS.CANCELLO_OPEN_RESPONSE) {
Helper.StartForegroundServiceNotification(context, "CANCELLO IN APERTURA...", Helper.FULL_ON_STOP_PROGRESS)
}else if(status == HelperMessages.STATUS.LED_ACCESO) {
Helper.StartForegroundServiceNotification(context, "LUCE ACCESA!", Helper.FULL_ON_STOP_PROGRESS)
}
else if(status == HelperMessages.STATUS.GARAGE_CLOSE) {
Helper.StartForegroundServiceNotification(context, "GARAGE OPEN", Helper.FULL_ON_STOP_PROGRESS)
}
else if(status == HelperMessages.STATUS.GARAGE_OPEN) {
Helper.StartForegroundServiceNotification(context, "GARAGE CLOSE", Helper.FULL_ON_STOP_PROGRESS)
} else {
else {
Helper.StartForegroundServiceNotification(context, networkResp, Helper.FULL_ON_STOP_PROGRESS)
}
if(!oneShot)
{
var looper = Looper.getMainLooper()
Handler(looper).post(object :Runnable{
override fun run() {
CountD(networkResp)
}
})
}
// if(!oneShot)
// {
// var looper = Looper.getMainLooper()
//
// Handler(looper).post(object :Runnable{
// override fun run() {
// CountD(networkResp)
// }
// })
// }
}
})
}
......
......@@ -6,5 +6,6 @@ class Arguments{
var PIN = "pin"
var GPIO = "gpio"
var CHECK = "check"
var BRIGHTNESS = "brightness"
}
}
......@@ -16,9 +16,9 @@ class GenericNotificationClass(val service: Service, val text : String, val stat
private val builder:NotificationCompat.Builder
private val notificationManager:NotificationManager
private val notification:Notification
private val CHANNEL_ID = "media_playback_channel"
private val CHANNEL_ID = "my_channel"
enum class STATUS {none, garage, cancello, all, portone, brightness, lastCommand}
enum class STATUS {none, garage, cancello, all, portone, brightness, led, lastCommand}
init {
val ns = Context.NOTIFICATION_SERVICE
......@@ -122,10 +122,14 @@ class GenericNotificationClass(val service: Service, val text : String, val stat
prepareData(switchIntent, STATUS.portone)
val openClosePortone = PendingIntent.getBroadcast(service, STATUS.portone.ordinal, switchIntent, PendingIntent.FLAG_UPDATE_CURRENT)
prepareData(switchIntent, STATUS.led)
val brightness = PendingIntent.getBroadcast(service, STATUS.led.ordinal, switchIntent, PendingIntent.FLAG_UPDATE_CURRENT)
notificationView.setOnClickPendingIntent(R.id.last_command, lastCommand)
notificationView.setOnClickPendingIntent(R.id.open_close_garage, openCloseGarage)
notificationView.setOnClickPendingIntent(R.id.open_close_cancello, openCloseCancello)
notificationView.setOnClickPendingIntent(R.id.open_close_portone, openClosePortone)
notificationView.setOnClickPendingIntent(R.id.brightness, brightness)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(CHANNEL_ID, "Channel beauty notification", NotificationManager.IMPORTANCE_HIGH)
......
......@@ -4,7 +4,9 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import it.lavermicocca.giacomo.beautifulnotification.mappers.Arguments
import it.lavermicocca.giacomo.beautifulnotification.notifications.GenericNotificationClass
import it.lavermicocca.giacomo.beautifulnotification.services.Helper
import unsigned.Ubyte
import unsigned.toUbyte
......@@ -26,11 +28,23 @@ class SwitchButtonListener : BroadcastReceiver() {
)]
when(status){
GenericNotificationClass.STATUS.lastCommand -> sender.SendRead(37)
GenericNotificationClass.STATUS.lastCommand -> {
Helper.StartForegroundServiceNotification(context, "VERIFICA SE GARAGE è APERTO", Helper.FULL_OFF)
sender.SendRead(37)
}
GenericNotificationClass.STATUS.portone -> sender.SendPinPortone() //17 GPIO pin locale
GenericNotificationClass.STATUS.cancello -> sender.SendPin(17)
GenericNotificationClass.STATUS.garage -> sender.SendPin(21)
GenericNotificationClass.STATUS.cancello -> {
Helper.StartForegroundServiceNotification(context, "CANCELLO IN APERTURA...", Helper.FULL_OFF)
sender.SendPin(17)
}
GenericNotificationClass.STATUS.garage -> {
Helper.StartForegroundServiceNotification(context, "GARAGE IN APERTURA...", Helper.FULL_OFF)
sender.SendPin(21)
}
GenericNotificationClass.STATUS.led -> {
Helper.StartForegroundServiceNotification(context, "LUCE ACCESA...", Helper.FULL_OFF)
sender.SendPin(13)
}
GenericNotificationClass.STATUS.brightness -> sender.SendBrightness(previousBrightness)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment