I want to find...

Search

Shares

Table of Content

86HMI::Switch

[Control widgets]

Object Functions

Switch object.

Switch-1

Switch Properties.

Switch-2

Identifier:

  • ID: Unique number that identifies the object.
  • Name: User-definable name for the object. It can be used with 86HMI API.

Content:

  • Checked: Default Switch state.

Geometry:

  • X: Object X coordinate.
  • Y: Object Y coordinate.
  • Width: Object width.
  • Height: Object height.

Options:

  • ObjColor: Choose from 4 themed colors. For font configuration instructions, please refer to Theme Management.
  • Enable: Select the default state of the object, enable or disable.
  • Order: Object order. It can adjust the object order by up/down, which can be viewed on the Object List.

API Functions

setSwitchState()

Description

Set Switch state.

Syntax

void setSwitchState(lv_obj_t* id, bool checked);
void setSwitchState(char* name, bool checked);

Parameters

  • [in] id
    Object ID.
  • [in] name
    Object Name.
  • [in] checked
    Bool. Switch state, Checked or Unchecked.

Return

None.

Example

#include "myhmi.h"

void setup() {
  Hmi.begin();
  // put your setup code here, to run once:
  Hmi.setSwitchState(p1sw1, true);
}

void loop() {
  // ...
}

getSwitchState()

Description

Get Switch state.

Syntax

bool getSwitchState(lv_obj_t* id);
bool getSwitchState(char* name);

Parameters

  • [in] id
    Object ID.
  • [in] name
    Object Name.

Return

Switch state.

Example

#include "myhmi.h"

void setup() {
  Hmi.begin();
  // put your setup code here, to run once:
}

void loop() {
  if (Hmi.getSwitchState(p1sw1)) {
    // do something.
  }
}

switchOn()

The following Event Functions are written between BEGIN_HMI_EVENT_PROC and END_HMI_EVENT_PROC.

Description

Determine Switch is on.

Syntax

bool switchOn(lv_obj_t* id);
bool switchOn(char* name);

Parameters

  • [in] id
    Object ID.
  • [in] name
    Object Name.

Return

Bool. Determine Switch is on.

Example

#include "myhmi.h"

void setup() {
  Hmi.begin();
  // put your setup code here, to run once:
}

void loop() {
  BEGIN_HMI_EVENT_PROC
  {
    if (Hmi.switchOn(p1sw1))
    {
      // do something.
    }
    if (Hmi.switchOff(p1sw1))
    {
      // do something.
    }
  }
  END_HMI_EVENT_PROC
}

switchOff()

The following Event Functions are written between BEGIN_HMI_EVENT_PROC and END_HMI_EVENT_PROC.

Description

Determine Switch is off.

Syntax

bool switchOff(lv_obj_t* id);
bool switchOff(char* name);

Parameters

  • [in] id
    Object ID.
  • [in] name
    Object Name.

Return

Bool. Determine Switch is off.

Example

#include "myhmi.h"

void setup() {
  Hmi.begin();
  // put your setup code here, to run once:
}

void loop() {
  BEGIN_HMI_EVENT_PROC
  {
    if (Hmi.switchOn(p1sw1))
    {
      // do something.
    }
    if (Hmi.switchOff(p1sw1))
    {
      // do something.
    }
  }
  END_HMI_EVENT_PROC
}

Please see the 86HMI Editor User Manual for more instructions on 86HMI widgets and API usage.

Scroll to Top