SwitchButtonListener.kt 2.15 KB
Newer Older
1 2 3 4 5 6
package it.lavermicocca.giacomo.beautifulnotification

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
7
import it.lavermicocca.giacomo.beautifulnotification.mappers.Arguments
8
import it.lavermicocca.giacomo.beautifulnotification.notifications.GenericNotificationClass
9
import it.lavermicocca.giacomo.beautifulnotification.services.Helper
10 11
import unsigned.Ubyte
import unsigned.toUbyte
12 13

class SwitchButtonListener : BroadcastReceiver() {
14 15 16 17 18

    companion object {
        var previousBrightness: Int = 250;
    }

19 20 21 22
    override fun onReceive(context: Context, intent: Intent) {

        var sender = Sender(context)

23
        Log.d("TTAG", "SwitchButtonListener -> click button on notification trought BroadcastReceiver")
24 25
        val requestCode = intent;

26 27
        var status = GenericNotificationClass.STATUS.values()[
                requestCode.getIntExtra(GenericNotificationClass.COMMAND, GenericNotificationClass.STATUS.none.ordinal
28 29 30
                )]

        when(status){
31 32 33 34
            GenericNotificationClass.STATUS.lastCommand -> {
                Helper.StartForegroundServiceNotification(context, "VERIFICA SE GARAGE è APERTO", Helper.FULL_OFF)
                sender.SendRead(37)
            }
35
            GenericNotificationClass.STATUS.portone -> sender.SendPinPortone() //17 GPIO pin locale
36 37 38 39 40 41 42 43 44 45 46 47
            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)
            }
48
            GenericNotificationClass.STATUS.brightness -> sender.SendBrightness(previousBrightness)
49
        }
50 51 52

        previousBrightness += 25
        previousBrightness %= 250
53 54
    }
}