Dana options activity fix

This commit is contained in:
Milos Kozak 2020-08-24 21:39:14 +02:00
parent 1e7a7a40bc
commit 7e2e5be6bb
7 changed files with 38 additions and 38 deletions

View file

@ -27,6 +27,7 @@ import info.nightscout.androidaps.utils.T
import info.nightscout.androidaps.utils.WarnColors
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
import info.nightscout.androidaps.utils.extensions.plusAssign
import info.nightscout.androidaps.utils.extensions.toVisibility
import info.nightscout.androidaps.utils.resources.ResourceHelper
import info.nightscout.androidaps.utils.sharedPreferences.SP
import io.reactivex.android.schedulers.AndroidSchedulers
@ -35,6 +36,7 @@ import kotlinx.android.synthetic.main.danar_fragment.*
import javax.inject.Inject
class DanaFragment : DaggerFragment() {
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var fabricPrivacy: FabricPrivacy
@ -95,6 +97,7 @@ class DanaFragment : DaggerFragment() {
danar_btconnection.setOnLongClickListener {
activity?.let {
OKDialog.showConfirmation(it, resourceHelper.gs(R.string.resetpairing), Runnable {
aapsLogger.error("USER ENTRY: Clearing pairing keys !!!")
(activePlugin.activePump as DanaPumpInterface).clearPairing()
})
}
@ -212,9 +215,6 @@ class DanaFragment : DaggerFragment() {
}
//hide user options button if not an RS pump or old firmware
// also excludes pump with model 03 because of untested error
val isKorean = activePlugin.activePump.pumpDescription.pumpType == PumpType.DanaRKorean
if (isKorean || pump.hwModel == 0 || pump.hwModel == 3) {
danar_user_options?.visibility = View.GONE
}
danar_user_options?.visibility = (pump.hwModel != 1 && pump.protocol != 0x00).toVisibility()
}
}

View file

@ -159,8 +159,8 @@ class DanaPump @Inject constructor(
var v3RSPump = false;
// User settings
var timeDisplayType = 0
var buttonScrollOnOff = 0
var timeDisplayType24 = false
var buttonScrollOnOff = false
var beepAndAlarm = 0
var lcdOnTimeSec = 0
var backlightOnTimeSec = 0

View file

@ -28,6 +28,7 @@ import kotlin.math.max
import kotlin.math.min
class DanaUserOptionsActivity : NoSplashAppCompatActivity() {
@Inject lateinit var aapsLogger: AAPSLogger
@Inject lateinit var rxBus: RxBusWrapper
@Inject lateinit var fabricPrivacy: FabricPrivacy
@ -71,9 +72,9 @@ class DanaUserOptionsActivity : NoSplashAppCompatActivity() {
aapsLogger.debug(LTag.PUMP,
"UserOptionsLoaded:" + (System.currentTimeMillis() - danaPump.lastConnection) / 1000 + " s ago"
+ "\ntimeDisplayType:" + danaPump.timeDisplayType
+ "\ntimeDisplayType24:" + danaPump.timeDisplayType24
+ "\nbuttonScroll:" + danaPump.buttonScrollOnOff
+ "\ntimeDisplayType:" + danaPump.timeDisplayType
+ "\nbeepAndAlarm:" + danaPump.beepAndAlarm
+ "\nlcdOnTimeSec:" + danaPump.lcdOnTimeSec
+ "\nbackLight:" + danaPump.backlightOnTimeSec
+ "\npumpUnits:" + danaPump.units
@ -84,33 +85,35 @@ class DanaUserOptionsActivity : NoSplashAppCompatActivity() {
danar_shutdown.setParams(danaPump.shutdownHour.toDouble(), 0.0, 24.0, 1.0, DecimalFormat("1"), true, save_user_options)
danar_lowreservoir.setParams(danaPump.lowReservoirRate.toDouble(), 10.0, 50.0, 10.0, DecimalFormat("10"), false, save_user_options)
when (danaPump.beepAndAlarm) {
0x01 -> danar_pumpalarm_sound.isChecked = true
0x02 -> danar_pumpalarm_vibrate.isChecked = true
0x11 -> danar_pumpalarm_both.isChecked = true
0b01 -> danar_pumpalarm_sound.isChecked = true
0b10 -> danar_pumpalarm_vibrate.isChecked = true
0b11 -> danar_pumpalarm_both.isChecked = true
0x101 -> {
0b101 -> {
danar_pumpalarm_sound.isChecked = true
danar_beep.isChecked = true
}
0x110 -> {
0b110 -> {
danar_pumpalarm_vibrate.isChecked = true
danar_beep.isChecked = true
}
0x111 -> {
0b111 -> {
danar_pumpalarm_both.isChecked = true
danar_beep.isChecked = true
}
}
if (danaPump.lastSettingsRead == 0L)
aapsLogger.error(LTag.PUMP, "No settings loaded from pump!") else setData()
if (danaPump.lastSettingsRead == 0L && danaPump.hwModel < 0x05) // RS+ doesn't use lastSettingsRead
aapsLogger.error(LTag.PUMP, "No settings loaded from pump!")
else
setData()
}
fun setData() {
// in DanaRS timeDisplay values are reversed
danar_timeformat.isChecked = !isRS() && danaPump.timeDisplayType != 0 || isRS() && danaPump.timeDisplayType == 0
danar_buttonscroll.isChecked = danaPump.buttonScrollOnOff != 0
danar_timeformat.isChecked = danaPump.timeDisplayType24
danar_buttonscroll.isChecked = danaPump.buttonScrollOnOff
danar_beep.isChecked = danaPump.beepAndAlarm > 4
danar_screentimeout.value = danaPump.lcdOnTimeSec.toDouble()
danar_backlight.value = danaPump.backlightOnTimeSec.toDouble()
@ -123,12 +126,9 @@ class DanaUserOptionsActivity : NoSplashAppCompatActivity() {
//exit if pump is not DanaRS, DanaR, or DanaR with upgraded firmware
if (!isRS() && !isDanaR() && !isDanaRv2()) return
if (isRS()) // displayTime on RS is reversed
danaPump.timeDisplayType = if (danar_timeformat.isChecked) 0 else 1
else
danaPump.timeDisplayType = if (danar_timeformat.isChecked) 1 else 0
danaPump.timeDisplayType24 = danar_timeformat.isChecked
danaPump.buttonScrollOnOff = if (danar_buttonscroll.isChecked) 1 else 0
danaPump.buttonScrollOnOff = danar_buttonscroll.isChecked
danaPump.beepAndAlarm = when {
danar_pumpalarm_sound.isChecked -> 1
danar_pumpalarm_vibrate.isChecked -> 2

View file

@ -13,8 +13,8 @@ class MsgSetUserOptions(
// No options set -> Exiting
aapsLogger.debug(LTag.PUMPCOMM, "NO USER OPTIONS LOADED EXITING!")
} else {
danaPump.userOptionsFrompump!![0] = (if (danaPump.timeDisplayType == 1) 0 else 1).toByte()
danaPump.userOptionsFrompump!![1] = danaPump.buttonScrollOnOff.toByte()
danaPump.userOptionsFrompump!![0] = if( danaPump.timeDisplayType24) 0.toByte() else 1.toByte()
danaPump.userOptionsFrompump!![1] = if (danaPump.buttonScrollOnOff) 1.toByte() else 0.toByte()
danaPump.userOptionsFrompump!![2] = danaPump.beepAndAlarm.toByte()
danaPump.userOptionsFrompump!![3] = danaPump.lcdOnTimeSec.toByte()
danaPump.userOptionsFrompump!![4] = danaPump.backlightOnTimeSec.toByte()

View file

@ -20,22 +20,22 @@ class MsgSettingUserOptions(
for (pos in bytes.indices) {
aapsLogger.debug(LTag.PUMPCOMM, "[" + pos + "]" + bytes[pos])
}
danaPump.timeDisplayType = if (bytes[0] == 1.toByte()) 0 else 1 // 1 -> 24h 0 -> 12h
danaPump.buttonScrollOnOff = if (bytes[1] == 1.toByte()) 1 else 0 // 1 -> ON, 0-> OFF
danaPump.timeDisplayType24 = bytes[0].toInt() == 0 // 0 -> 24h 1 -> 12h
danaPump.buttonScrollOnOff = bytes[1] == 1.toByte() // 1 -> ON, 0-> OFF
danaPump.beepAndAlarm = bytes[2].toInt() // 1 -> Sound on alarm 2-> Vibrate on alarm 3-> Both on alarm 5-> Sound + beep 6-> vibrate + beep 7-> both + beep Beep adds 4
danaPump.lcdOnTimeSec = bytes[3].toInt() and 255
danaPump.backlightOnTimeSec = bytes[4].toInt() and 255
danaPump.lcdOnTimeSec = bytes[3].toInt()
danaPump.backlightOnTimeSec = bytes[4].toInt()
danaPump.selectedLanguage = bytes[5].toInt() // on DanaRv2 is that needed ?
danaPump.units = bytes[8].toInt()
danaPump.shutdownHour = bytes[9].toInt()
danaPump.lowReservoirRate = bytes[32].toInt() and 255
danaPump.lowReservoirRate = bytes[32].toInt()
/* int selectableLanguage1 = bytes[10];
int selectableLanguage2 = bytes[11];
int selectableLanguage3 = bytes[12];
int selectableLanguage4 = bytes[13];
int selectableLanguage5 = bytes[14];
*/
aapsLogger.debug(LTag.PUMPCOMM, "timeDisplayType: " + danaPump.timeDisplayType)
aapsLogger.debug(LTag.PUMPCOMM, "timeDisplayType24: " + danaPump.timeDisplayType24)
aapsLogger.debug(LTag.PUMPCOMM, "Button scroll: " + danaPump.buttonScrollOnOff)
aapsLogger.debug(LTag.PUMPCOMM, "BeepAndAlarm: " + danaPump.beepAndAlarm)
aapsLogger.debug(LTag.PUMPCOMM, "screen timeout: " + danaPump.lcdOnTimeSec)

View file

@ -20,10 +20,10 @@ class DanaRS_Packet_Option_Get_User_Option(
override fun handleMessage(data: ByteArray) {
var dataIndex = DATA_START
var dataSize = 1
danaPump.timeDisplayType = byteArrayToInt(getBytes(data, dataIndex, dataSize))
danaPump.timeDisplayType24 = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 0
dataIndex += dataSize
dataSize = 1
danaPump.buttonScrollOnOff = byteArrayToInt(getBytes(data, dataIndex, dataSize))
danaPump.buttonScrollOnOff = byteArrayToInt(getBytes(data, dataIndex, dataSize)) == 1
dataIndex += dataSize
dataSize = 1
danaPump.beepAndAlarm = byteArrayToInt(getBytes(data, dataIndex, dataSize))
@ -68,7 +68,7 @@ class DanaRS_Packet_Option_Get_User_Option(
val selectableLanguage5 = byteArrayToInt(getBytes(data, dataIndex, dataSize))
// Pump's screen on time can't be less than 5
failed = if (danaPump.lcdOnTimeSec < 5) true else false
aapsLogger.debug(LTag.PUMPCOMM, "timeDisplayType: " + danaPump.timeDisplayType)
aapsLogger.debug(LTag.PUMPCOMM, "timeDisplayType24: " + danaPump.timeDisplayType24)
aapsLogger.debug(LTag.PUMPCOMM, "buttonScrollOnOff: " + danaPump.buttonScrollOnOff)
aapsLogger.debug(LTag.PUMPCOMM, "beepAndAlarm: " + danaPump.beepAndAlarm)
aapsLogger.debug(LTag.PUMPCOMM, "lcdOnTimeSec: " + danaPump.lcdOnTimeSec)

View file

@ -20,16 +20,16 @@ class DanaRS_Packet_Option_Set_User_Option(
override fun getRequestParams(): ByteArray {
aapsLogger.debug(LTag.PUMPCOMM,
"UserOptions:" + (System.currentTimeMillis() - danaPump.lastConnection) / 1000 + " s ago"
+ "\ntimeDisplayType:" + danaPump.timeDisplayType
+ "\ntimeDisplayType24:" + danaPump.timeDisplayType24
+ "\nbuttonScroll:" + danaPump.buttonScrollOnOff
+ "\ntimeDisplayType:" + danaPump.timeDisplayType
+ "\nbeepAndAlarm:" + danaPump.beepAndAlarm
+ "\nlcdOnTimeSec:" + danaPump.lcdOnTimeSec
+ "\nbacklight:" + danaPump.backlightOnTimeSec
+ "\ndanaRPumpUnits:" + danaPump.units
+ "\nlowReservoir:" + danaPump.lowReservoirRate)
val request = ByteArray(13)
request[0] = (danaPump.timeDisplayType and 0xff).toByte()
request[1] = (danaPump.buttonScrollOnOff and 0xff).toByte()
request[0] = if (danaPump.timeDisplayType24) 0.toByte() else 1.toByte()
request[1] = if (danaPump.buttonScrollOnOff) 1.toByte() else 0.toByte()
request[2] = (danaPump.beepAndAlarm and 0xff).toByte()
request[3] = (danaPump.lcdOnTimeSec and 0xff).toByte()
request[4] = (danaPump.backlightOnTimeSec and 0xff).toByte()