Skip to content

Glasses

Overview

The SDK exposes information about the glasses via the M2GlassesService (accessed from Evs.glassesService).

Examples of the information that can be received from the glasses interface:

  • Battery level
  • Charging state
  • Serial number
  • Firmware version

The interface also enables turning off the glasses and registering to glasses event callbacks.

Connection Events

Register for connection lifecycle events to monitor the glasses state:

Evs.glassesService.registerConnectionListener(object : IM2GlassesConnectionEvents {
    override fun onConnectionStatusChanged(status: ConnectionStatus) {
        when (status) {
            ConnectionStatus.Ready -> { /* glasses connected and ready */ }
            ConnectionStatus.Disconnected -> { /* glasses disconnected */ }
            ConnectionStatus.Connecting -> { /* connection in progress */ }
            else -> { }
        }
    }
})

Battery Monitoring

Evs.glassesService.registerBatteryListener(object : IM2GlassesBatteryEvents {
    override fun onBatteryLevel(level: Int) {
        // level: 0–100
    }
    override fun onChargingStateChanged(isCharging: Boolean) {
        // charger connected or disconnected
    }
})

Touch Events

Touch events can be received in 2 ways:

  1. Register to the glasses events via Evs.glassesService
  2. Override M2Screen.onTouch()

The following example uses M2Screen.onTouch to listen to touch events:

override fun onTouch(touch: Touch) {
    if (touch == Touch.Tap) {
        val t = M2Text()
        t.setFont(M2FontResource.fontMedium)
            .setAlign(Align.CenterHorizontal)
            .setText("Nice Tap!!")
            .setBackgroundColor(M2Color.Red)
    }
}
override func onTouch(touch: Touch) {
    if touch == .tap {
        let t = M2Text(text: "Nice Tap!!", tag: nil)
        _ = t.setFont(fontResource: M2FontResource.companion.fontMedium)
        _ = t.setAlign(align: Align.centerHorizontal)
        _ = t.setBackgroundColor(evsColor: M2Color.red)
    }
}

When enabled, the following discrete touch events are available:

Touch Gesture Description
Touch.Backward Backward swipe
Touch.Forward Forward swipe
Touch.Tap Tapping the touch pad
Touch.LongTap Long pressing the touch pad

Proximity

The proximity sensor detects whether the glasses are on or off the face.

Event Description
Off face Indicates the glasses are off face
On face Indicates the glasses are on face (proximity sensor is triggered)

Ambient Light

The ambient sensor measures daylight in lux.

When enabled, the ambient callback will be triggered with the ambient sensor reading. This value is also used by the auto brightness mechanism.

Power Button Events

Evs.glassesService.registerSystemListener(object : IM2GlassesSystemEvents {
    override fun onPowerButtonPressed(event: PowerButton) {
        when (event) {
            PowerButton.Click -> { /* single press */ }
            PowerButton.LongClick -> { /* long press */ }
            PowerButton.BeforeShutdown -> { /* glasses shutting down - a stock shutdown HUD is displayed */ }
            else -> { }
        }
    }
})

Device Information

val serial = Evs.glassesService.serial()
val description = Evs.glassesService.description()
val fwVersions = Evs.glassesService.fwVersions() // firmware versions list

See Also