1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
rem ButtonsFullControl.bas
rem
rem last revision on 05 Feb 2003
rem

rem  Extended example on how to use the front panel
rem  buttons in a macro.

Customer_ID_Macro:
write "      Buttons Full Control      "
END

CONST PROG_BUTTON_TIMEOUT = 20
CONST BUTTON_TIMEOUT = 5

// bit masks for &SWITCHES (see also Register Supplement, register 151)
CONST PROG = 0x01
CONST DOWN = 0x02
CONST UP = 0x04
CONST BUTTON_REMOTE = 0x8000

// Meter may be setup to react to 'button events',
// for example entering view mode on UP/DOWN.
//
// distinguish between different operation modes

CONST OFF_MODE = 0  // buttons work as setup with configuration utility
CONST MACRO_MODE = 1  // macro controls buttons completely

Reset_Macro:
#mode = OFF_MODE
#buttons = 0
&TIMER1 = 0
&SWITCHES = 0
&DATA_SOURCE_DISPLAY1 = addr(&DISPLAY)  // usually set with Texmate Meter Utility
END

prog_button_pressed:
write ""
if #mode = OFF_MODE then
        write "      OFF_MODE      "
else
        write "      MACRO_MODE      "
endif
return

up_button_pressed:
&DISPLAY = &DISPLAY + 1
return

down_button_pressed:
&DISPLAY = &DISPLAY - 1
return

Main_Macro:

// do nothing if we are already in view or edit mode
if &VIEW_POINTER <> 0 OR &EDIT_STATE <> 0 then
        &TIMER1 = 0
        END
endif

select #mode

case OFF_MODE:
        if |PROG_BUTTON = on then
                if &TIMER1 > PROG_BUTTON_TIMEOUT then
                        &SWITCHES = BUTTON_REMOTE
                        #mode = MACRO_MODE
                        &TIMER1 = 0
                        gosub prog_button_pressed
                endif
        else
                &TIMER1 = 0
        endif

case MACRO_MODE:
        if &SWITCHES = BUTTON_REMOTE then
                // we want to trigger button pressed event as soon as possible
                &TIMER1 = BUTTON_TIMEOUT

        elsif &TIMER1 >= BUTTON_TIMEOUT then

                if &TIMER1 >= PROG_BUTTON_TIMEOUT AND \
                   &SWITCHES = BUTTON_REMOTE + PROG then
                        &TIMER1 = 0
                        &SWITCHES = 0
                        #mode = OFF_MODE
                        gosub prog_button_pressed

                else
                        if &SWITCHES = BUTTON_REMOTE + UP then
                                gosub up_button_pressed
                                &TIMER1 = 0
                        elsif &SWITCHES = BUTTON_REMOTE + DOWN then
                                gosub down_button_pressed
                                &TIMER1 = 0
                        endif
                endif

        endif

endsel
END

Download ButtonsFullControl.bas
(2.6 KB , Aug. 26, 2008)