Commit dc2dd681 authored by Giacomo Lavermicocca's avatar Giacomo Lavermicocca

brightness added and light controls

parent db9d2d63
...@@ -5,7 +5,7 @@ import it.lavermicocca.giacomo.beautifulnotification.mappers.Arguments ...@@ -5,7 +5,7 @@ import it.lavermicocca.giacomo.beautifulnotification.mappers.Arguments
class HelperMessages{ class HelperMessages{
enum class STATUS { UNKNOWN, TIMEOUT, GARAGE_OPEN, GARAGE_CLOSE } enum class STATUS { UNKNOWN, TIMEOUT, GARAGE_OPEN, GARAGE_CLOSE, BRIGHTNESS }
fun Do(messaggio: String) : STATUS{ fun Do(messaggio: String) : STATUS{
when(messaggio) when(messaggio)
...@@ -23,6 +23,12 @@ class HelperMessages{ ...@@ -23,6 +23,12 @@ class HelperMessages{
return STATUS.TIMEOUT return STATUS.TIMEOUT
} }
} }
if(messaggio.contains("L.C. : b "))
{
return STATUS.BRIGHTNESS
}
return STATUS.UNKNOWN return STATUS.UNKNOWN
} }
} }
\ No newline at end of file
...@@ -9,6 +9,7 @@ import android.widget.Toast ...@@ -9,6 +9,7 @@ import android.widget.Toast
import it.lavermicocca.giacomo.beautifulnotification.mappers.Arguments import it.lavermicocca.giacomo.beautifulnotification.mappers.Arguments
import it.lavermicocca.giacomo.beautifulnotification.services.Helper import it.lavermicocca.giacomo.beautifulnotification.services.Helper
import okhttp3.* import okhttp3.*
import unsigned.Ubyte
import java.io.IOException import java.io.IOException
class Sender(val context: Context) { class Sender(val context: Context) {
...@@ -100,13 +101,13 @@ class Sender(val context: Context) { ...@@ -100,13 +101,13 @@ class Sender(val context: Context) {
} }
//UNO //UNO
fun SendPinPortone() { fun SendBrightness(brightness: Int) {
Helper.StartForegroundServiceNotification(context, "PORTONE IN APERTURA...", Helper.FULL_ON) Helper.StartForegroundServiceNotification(context, "ACCENDO LUCE con INTENSITA : $brightness", Helper.FULL_ON)
val prf = context.getSharedPreferences("myPref", Context.MODE_PRIVATE) val prf = context.getSharedPreferences("myPref", Context.MODE_PRIVATE)
val ipServer = prf.getString("ip_server_portone", "192.168.43.176") val ipServer = prf.getString("ip_server", "192.168.43.176")
val url = "http://$ipServer/on" val url = "http://$ipServer/brightness/$brightness"
val request = okhttp3.Request.Builder() val request = okhttp3.Request.Builder()
.url(url) .url(url)
...@@ -116,8 +117,6 @@ class Sender(val context: Context) { ...@@ -116,8 +117,6 @@ class Sender(val context: Context) {
val client = OkHttpClient() val client = OkHttpClient()
Helper.StartForegroundServiceNotification(context, "PORTONE", Helper.FULL_ON)
client.newCall(request).enqueue(object : Callback { client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) { override fun onFailure(call: Call, e: IOException) {
e.printStackTrace() e.printStackTrace()
...@@ -126,30 +125,33 @@ class Sender(val context: Context) { ...@@ -126,30 +125,33 @@ class Sender(val context: Context) {
@Throws(IOException::class) @Throws(IOException::class)
override fun onResponse(call: Call, response: Response) { override fun onResponse(call: Call, response: Response) {
Helper.StartForegroundServiceNotification(context, "PORTONE APERTO", Helper.FULL_ON) val networkResp = response.body()!!.string()
// val networkResp = response.body()!!.string() var looper = Looper.getMainLooper()
// var looper = Looper.getMainLooper()
// Handler(looper).post(object :Runnable{
// Handler(looper).post(object :Runnable{ override fun run() {
// override fun run() { //TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
// //TODO("not implemented") //To change body of created functions use File | Settings | File Templates. Toast.makeText(context, networkResp, Toast.LENGTH_LONG).show()
// //Toast.makeText(context, networkResp, Toast.LENGTH_LONG).show() if(networkResp.contains(Arguments.PIN, true))
// {
// } Log.e("TTAG", "RICHIESTA PIN")
// }) SendCheck(false)
}
}
})
} }
}) })
} }
//UNO //UNO
fun SendGPIO(pin: Int) { fun SendPinPortone() {
Helper.StartForegroundServiceNotification(context, "PORTONE IN APERTURA...", Helper.FULL_ON) Helper.StartForegroundServiceNotification(context, "PORTONE IN APERTURA...", Helper.FULL_ON)
val prf = context.getSharedPreferences("myPref", Context.MODE_PRIVATE) val prf = context.getSharedPreferences("myPref", Context.MODE_PRIVATE)
val ipServer = prf.getString("ip_server", "192.168.43.176") val ipServer = prf.getString("ip_server_portone", "192.168.43.176")
val url = "http://$ipServer/gpio/$pin" val url = "http://$ipServer/on"
val request = okhttp3.Request.Builder() val request = okhttp3.Request.Builder()
.url(url) .url(url)
...@@ -159,6 +161,8 @@ class Sender(val context: Context) { ...@@ -159,6 +161,8 @@ class Sender(val context: Context) {
val client = OkHttpClient() val client = OkHttpClient()
Helper.StartForegroundServiceNotification(context, "PORTONE", Helper.FULL_ON)
client.newCall(request).enqueue(object : Callback { client.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) { override fun onFailure(call: Call, e: IOException) {
e.printStackTrace() e.printStackTrace()
...@@ -167,30 +171,25 @@ class Sender(val context: Context) { ...@@ -167,30 +171,25 @@ class Sender(val context: Context) {
@Throws(IOException::class) @Throws(IOException::class)
override fun onResponse(call: Call, response: Response) { override fun onResponse(call: Call, response: Response) {
val networkResp = response.body()!!.string() Helper.StartForegroundServiceNotification(context, "PORTONE APERTO", Helper.FULL_ON)
var looper = Looper.getMainLooper() // val networkResp = response.body()!!.string()
// var looper = Looper.getMainLooper()
//
// Handler(looper).post(object :Runnable{
// 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()
//
// }
// })
Handler(looper).post(object :Runnable{
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.GPIO, true))
{
Log.e("TTAG", "RICHIESTA GPIO")
Helper.StartForegroundServiceNotification(context, "PORTONE OPEN", Helper.FULL_ON)
}
else {
Helper.StartForegroundServiceNotification(context, "ERRORE NEI MESSAGGI RADIO", Helper.FULL_ON)
}
}
})
} }
}) })
} }
//DUE //DUE
fun SendCheck(oneShot:Boolean) { fun SendCheck(oneShot:Boolean) {
//Thread.sleep(1000); Thread.sleep(1000);
val prf = context.getSharedPreferences("myPref", Context.MODE_PRIVATE) val prf = context.getSharedPreferences("myPref", Context.MODE_PRIVATE)
val ipServer = prf.getString("ip_server", "192.168.43.176") val ipServer = prf.getString("ip_server", "192.168.43.176")
...@@ -216,7 +215,7 @@ class Sender(val context: Context) { ...@@ -216,7 +215,7 @@ class Sender(val context: Context) {
var status:HelperMessages.STATUS = HelperMessages().Do(networkResp) var status:HelperMessages.STATUS = HelperMessages().Do(networkResp)
if(status == HelperMessages.STATUS.TIMEOUT) { if(status == HelperMessages.STATUS.TIMEOUT) {
Helper.StartForegroundServiceNotification(context, "ERRORE DI TIMEOUT", Helper.FULL_ON_STOP_PROGRESS) Helper.StartForegroundServiceNotification(context, "TIMEOUT su CHECK", Helper.FULL_ON_STOP_PROGRESS)
} }
else if(status == HelperMessages.STATUS.GARAGE_CLOSE) { else if(status == HelperMessages.STATUS.GARAGE_CLOSE) {
Helper.StartForegroundServiceNotification(context, "GARAGE OPEN", Helper.FULL_ON_STOP_PROGRESS) Helper.StartForegroundServiceNotification(context, "GARAGE OPEN", Helper.FULL_ON_STOP_PROGRESS)
...@@ -224,14 +223,7 @@ class Sender(val context: Context) { ...@@ -224,14 +223,7 @@ class Sender(val context: Context) {
else if(status == HelperMessages.STATUS.GARAGE_OPEN) { else if(status == HelperMessages.STATUS.GARAGE_OPEN) {
Helper.StartForegroundServiceNotification(context, "GARAGE CLOSE", Helper.FULL_ON_STOP_PROGRESS) Helper.StartForegroundServiceNotification(context, "GARAGE CLOSE", Helper.FULL_ON_STOP_PROGRESS)
} else { } else {
Helper.StartForegroundServiceNotification(context, networkResp, Helper.FULL_OFF) Helper.StartForegroundServiceNotification(context, networkResp, Helper.FULL_ON_STOP_PROGRESS)
// if(networkResp.contains("L.C. : p : "))
//
// else
// {
// Helper.StartForegroundServiceNotification(context, "ERRORE NEI MESSAGGI RADIO", Helper.FULL_ON_STOP_PROGRESS)
// return
// }
} }
if(!oneShot) if(!oneShot)
......
...@@ -18,7 +18,7 @@ class GenericNotificationClass(val service: Service, val text : String, val stat ...@@ -18,7 +18,7 @@ class GenericNotificationClass(val service: Service, val text : String, val stat
private val notification:Notification private val notification:Notification
private val CHANNEL_ID = "media_playback_channel" private val CHANNEL_ID = "media_playback_channel"
enum class STATUS {none, garage, cancello, all, portone, lastCommand} enum class STATUS {none, garage, cancello, all, portone, brightness, lastCommand}
init { init {
val ns = Context.NOTIFICATION_SERVICE val ns = Context.NOTIFICATION_SERVICE
......
...@@ -5,8 +5,15 @@ import android.content.Context ...@@ -5,8 +5,15 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.util.Log import android.util.Log
import it.lavermicocca.giacomo.beautifulnotification.notifications.GenericNotificationClass import it.lavermicocca.giacomo.beautifulnotification.notifications.GenericNotificationClass
import unsigned.Ubyte
import unsigned.toUbyte
class SwitchButtonListener : BroadcastReceiver() { class SwitchButtonListener : BroadcastReceiver() {
companion object {
var previousBrightness: Int = 250;
}
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
var sender = Sender(context) var sender = Sender(context)
...@@ -24,6 +31,10 @@ class SwitchButtonListener : BroadcastReceiver() { ...@@ -24,6 +31,10 @@ class SwitchButtonListener : BroadcastReceiver() {
GenericNotificationClass.STATUS.portone -> sender.SendPinPortone() //17 GPIO pin locale GenericNotificationClass.STATUS.portone -> sender.SendPinPortone() //17 GPIO pin locale
GenericNotificationClass.STATUS.cancello -> sender.SendPin(17) GenericNotificationClass.STATUS.cancello -> sender.SendPin(17)
GenericNotificationClass.STATUS.garage -> sender.SendPin(21) GenericNotificationClass.STATUS.garage -> sender.SendPin(21)
GenericNotificationClass.STATUS.brightness -> sender.SendBrightness(previousBrightness)
} }
previousBrightness += 25
previousBrightness %= 250
} }
} }
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