Changes 20110824

This minor improvement iteration is to:

Hardware:

  • Connect a buzzer & SSR to the PIC18F4610 breakout, for notifying when a cycle is complete and for automated on/off of the vacuum pump
    • PIC18F4610 Pins RA4 & RA5 were unused, so RA4 will drive the buzzer & RA5 the SSR
    - Update PIC18F4610 firmware to drive the RA4 & 5 hardware per above
    • I have always been able to do a M90001 Pn where n is 0-15 to select a head, but we only have eight heads, so 7-15 was spare
    • This change updates the firmware on the PIC18F4610 such that if a toggle command is received and the address is > 7 then instead of toggling a vacuum for a head a canned function will run:
      • Head select = 8: Buzzer off
      • Head select = 9: Buzzer on
      • Head select = 10: Vacuum SSR off
      • Head select = 11: Vacuum SSR = on
    • I'd been kinda reserving these remaining addresses for PCB rotation but we still have 12-15 left over...Additionally, for PCB rotation driving in the future we stillhave RA0-3 unused & I can repurpose the PIC18F4610 RE0-3 pins (heartbeat leds are nice but not necessary) if morepins are needed
  • Connected an XBOX 360 controller for jog control

Software:

Mach 3 VB dialogs

  • Took this opportunity to also update each screen to show the last button hit
    • Sometimes when checking feeder calibration, it is easy to forget which head the camera is positioned over before doing the 'Set here'
    • Added it to all buttons on all screens for consistency

Excel GCode generator

  • Start rotation turns of buzzer
  • End rotation turns on buzzer

Mach 3 dialog:

Option Explicit

'20110728

Const G59BaseAddrX = 5221
Const G59BaseAddrY = 5222
Const G59AddrIncrement = 20
Const G59Rot0PCB1 = 50
Const G59Rot90PCB1 = 100
Const G59Rot180PCB1 = 150
Const G59Rot270PCB1 = 200

Const FeederGCodeBaseVarComponentsRequired = 100
Const FeederGCodeBaseVarComponentsMax = 200

Const FeederGCodeBaseVarX = 300
Const FeederGCodeBaseVarY = 400

Const HeadGCodeBaseVarX = 1000
Const HeadGCodeBaseVarY = 1020

Const HeadGCodeBaseVarSmallBumpLeftX = 1100
Const HeadGCodeBaseVarSmallBumpRightX = 1120
Const HeadGCodeBaseVarSmallBumpTopY = 1140
Const HeadGCodeBaseVarSmallBumpBottomY = 1160

Const HeadGCodeBaseVarLargeBumpLeftX = 1200
Const HeadGCodeBaseVarLargeBumpRightX = 1220
Const HeadGCodeBaseVarLargeBumpTopY = 1240
Const HeadGCodeBaseVarLargeBumpBottomY = 1260

'Dialog return values
Dim returnMain
Dim returnCalibrateFeeders
Dim returnCalibrateHeads

Dim lastAction
Dim strTemp

'State machine as can't get nested dialogs to work
Dim currentDialog
Const currentDialogIsMain = 1
Const currentDialogIsCalibrateFeeders = 2
Const currentDialogIsCalibrateHeads = 3
Const currentDialogIsNone = 10

Sub Main

    Begin Dialog dlgCalibrateFeeders 510, 400, "Feeder calibration", .dialogCalibrateFeeders

        Text 10, 20, 35, 10, "FL25"
        Text 10, 30, 35, 10, "FL24"
        Text 10, 40, 35, 10, "FL23"
        Text 10, 50, 35, 10, "FL22"
        Text 10, 60, 35, 10, "FL21"
        Text 10, 70, 35, 10, "FL20"
        Text 10, 80, 35, 10, "FL19"
        Text 10, 90, 35, 10, "FL18"
        Text 10, 100, 35, 10, "FL17"
        Text 10, 110, 35, 10, "FL16"
        Text 10, 120, 35, 10, "FL15"
        Text 10, 130, 35, 10, "FL14"
        Text 10, 140, 35, 10, "FL13"
        Text 10, 150, 35, 10, "FL12"
        Text 10, 160, 35, 10, "FL11"
        Text 10, 170, 35, 10, "FL10"
        Text 10, 180, 35, 10, "FL9"
        Text 10, 190, 35, 10, "FL8"
        Text 10, 200, 35, 10, "FL7"
        Text 10, 210, 35, 10, "FL6"
        Text 10, 220, 35, 10, "FL5"
        Text 10, 230, 35, 10, "FL4"
        Text 10, 240, 35, 10, "FL3"
        Text 10, 250, 35, 10, "FL2"
        Text 10, 260, 35, 10, "FL1"
        
        Text 260, 20, 35, 10, "FR25"
        Text 260, 30, 35, 10, "FR24"
        Text 260, 40, 35, 10, "FR23"
        Text 260, 50, 35, 10, "FR22"
        Text 260, 60, 35, 10, "FR21"
        Text 260, 70, 35, 10, "FR20"
        Text 260, 80, 35, 10, "FR19"
        Text 260, 90, 35, 10, "FR18"
        Text 260, 100, 35, 10, "FR17"
        Text 260, 110, 35, 10, "FR16"
        Text 260, 120, 35, 10, "FR15"
        Text 260, 130, 35, 10, "FR14"
        Text 260, 140, 35, 10, "FR13"
        Text 260, 150, 35, 10, "FR12"
        Text 260, 160, 35, 10, "FR11"
        Text 260, 170, 35, 10, "FR10"
        Text 260, 180, 35, 10, "FR9"
        Text 260, 190, 35, 10, "FR8"
        Text 260, 200, 35, 10, "FR7"
        Text 260, 210, 35, 10, "FR6"
        Text 260, 220, 35, 10, "FR5"
        Text 260, 230, 35, 10, "FR4"
        Text 260, 240, 35, 10, "FR3"
        Text 260, 250, 35, 10, "FR2"
        Text 260, 260, 35, 10, "FR1"

        Text 40, 10, 20, 10, "Goto?"
        PushButton 40, 20, 150, 10, "Goto", .btnGotoFeeder25
        PushButton 40, 30, 150, 10, "Goto", .btnGotoFeeder24
        PushButton 40, 40, 150, 10, "Goto", .btnGotoFeeder23
        PushButton 40, 50, 150, 10, "Goto", .btnGotoFeeder22
        PushButton 40, 60, 150, 10, "Goto", .btnGotoFeeder21
        PushButton 40, 70, 150, 10, "Goto", .btnGotoFeeder20
        PushButton 40, 80, 150, 10, "Goto", .btnGotoFeeder19
        PushButton 40, 90, 150, 10, "Goto", .btnGotoFeeder18
        PushButton 40, 100, 150, 10, "Goto", .btnGotoFeeder17
        PushButton 40, 110, 150, 10, "Goto", .btnGotoFeeder16
        PushButton 40, 120, 150, 10, "Goto", .btnGotoFeeder15
        PushButton 40, 130, 150, 10, "Goto", .btnGotoFeeder14
        PushButton 40, 140, 150, 10, "Goto", .btnGotoFeeder13
        PushButton 40, 150, 150, 10, "Goto", .btnGotoFeeder12
        PushButton 40, 160, 150, 10, "Goto", .btnGotoFeeder11
        PushButton 40, 170, 150, 10, "Goto", .btnGotoFeeder10
        PushButton 40, 180, 150, 10, "Goto", .btnGotoFeeder9
        PushButton 40, 190, 150, 10, "Goto", .btnGotoFeeder8
        PushButton 40, 200, 150, 10, "Goto", .btnGotoFeeder7
        PushButton 40, 210, 150, 10, "Goto", .btnGotoFeeder6
        PushButton 40, 220, 150, 10, "Goto", .btnGotoFeeder5
        PushButton 40, 230, 150, 10, "Goto", .btnGotoFeeder4
        PushButton 40, 240, 150, 10, "Goto", .btnGotoFeeder3
        PushButton 40, 250, 150, 10, "Goto", .btnGotoFeeder2
        PushButton 40, 260, 150, 10, "Goto", .btnGotoFeeder1
        
        Text 290, 10, 20, 10, "Goto?"
        PushButton 290, 20, 150, 10, "Goto", .btnGotoFeeder50
        PushButton 290, 30, 150, 10, "Goto", .btnGotoFeeder49
        PushButton 290, 40, 150, 10, "Goto", .btnGotoFeeder48
        PushButton 290, 50, 150, 10, "Goto", .btnGotoFeeder47
        PushButton 290, 60, 150, 10, "Goto", .btnGotoFeeder46
        PushButton 290, 70, 150, 10, "Goto", .btnGotoFeeder45
        PushButton 290, 80, 150, 10, "Goto", .btnGotoFeeder44
        PushButton 290, 90, 150, 10, "Goto", .btnGotoFeeder43
        PushButton 290, 100, 150, 10, "Goto", .btnGotoFeeder42
        PushButton 290, 110, 150, 10, "Goto", .btnGotoFeeder41
        PushButton 290, 120, 150, 10, "Goto", .btnGotoFeeder40
        PushButton 290, 130, 150, 10, "Goto", .btnGotoFeeder39
        PushButton 290, 140, 150, 10, "Goto", .btnGotoFeeder38
        PushButton 290, 150, 150, 10, "Goto", .btnGotoFeeder37
        PushButton 290, 160, 150, 10, "Goto", .btnGotoFeeder36
        PushButton 290, 170, 150, 10, "Goto", .btnGotoFeeder35
        PushButton 290, 180, 150, 10, "Goto", .btnGotoFeeder34
        PushButton 290, 190, 150, 10, "Goto", .btnGotoFeeder33
        PushButton 290, 200, 150, 10, "Goto", .btnGotoFeeder32
        PushButton 290, 210, 150, 10, "Goto", .btnGotoFeeder31
        PushButton 290, 220, 150, 10, "Goto", .btnGotoFeeder30
        PushButton 290, 230, 150, 10, "Goto", .btnGotoFeeder29
        PushButton 290, 240, 150, 10, "Goto", .btnGotoFeeder28
        PushButton 290, 250, 150, 10, "Goto", .btnGotoFeeder27
        PushButton 290, 260, 150, 10, "Goto", .btnGotoFeeder26

        Text 200, 10, 20, 15, "Origin?"
        PushButton 200, 20, 30, 10, "Set", .btnSetFeeder25
        PushButton 200, 30, 30, 10, "Set", .btnSetFeeder24
        PushButton 200, 40, 30, 10, "Set", .btnSetFeeder23
        PushButton 200, 50, 30, 10, "Set", .btnSetFeeder22
        PushButton 200, 60, 30, 10, "Set", .btnSetFeeder21
        PushButton 200, 70, 30, 10, "Set", .btnSetFeeder20
        PushButton 200, 80, 30, 10, "Set", .btnSetFeeder19
        PushButton 200, 90, 30, 10, "Set", .btnSetFeeder18
        PushButton 200, 100, 30, 10, "Set", .btnSetFeeder17
        PushButton 200, 110, 30, 10, "Set", .btnSetFeeder16
        PushButton 200, 120, 30, 10, "Set", .btnSetFeeder15
        PushButton 200, 130, 30, 10, "Set", .btnSetFeeder14
        PushButton 200, 140, 30, 10, "Set", .btnSetFeeder13
        PushButton 200, 150, 30, 10, "Set", .btnSetFeeder12
        PushButton 200, 160, 30, 10, "Set", .btnSetFeeder11
        PushButton 200, 170, 30, 10, "Set", .btnSetFeeder10
        PushButton 200, 180, 30, 10, "Set", .btnSetFeeder9
        PushButton 200, 190, 30, 10, "Set", .btnSetFeeder8
        PushButton 200, 200, 30, 10, "Set", .btnSetFeeder7
        PushButton 200, 210, 30, 10, "Set", .btnSetFeeder6
        PushButton 200, 220, 30, 10, "Set", .btnSetFeeder5
        PushButton 200, 230, 30, 10, "Set", .btnSetFeeder4
        PushButton 200, 240, 30, 10, "Set", .btnSetFeeder3
        PushButton 200, 250, 30, 10, "Set", .btnSetFeeder2
        PushButton 200, 260, 30, 10, "Set", .btnSetFeeder1
        
        Text 450, 10, 20, 15, "Origin?"
        PushButton 450, 20, 30, 10, "Set", .btnSetFeeder50
        PushButton 450, 30, 30, 10, "Set", .btnSetFeeder49
        PushButton 450, 40, 30, 10, "Set", .btnSetFeeder48
        PushButton 450, 50, 30, 10, "Set", .btnSetFeeder47
        PushButton 450, 60, 30, 10, "Set", .btnSetFeeder46
        PushButton 450, 70, 30, 10, "Set", .btnSetFeeder45
        PushButton 450, 80, 30, 10, "Set", .btnSetFeeder44
        PushButton 450, 90, 30, 10, "Set", .btnSetFeeder43
        PushButton 450, 100, 30, 10, "Set", .btnSetFeeder42
        PushButton 450, 110, 30, 10, "Set", .btnSetFeeder41
        PushButton 450, 120, 30, 10, "Set", .btnSetFeeder40
        PushButton 450, 130, 30, 10, "Set", .btnSetFeeder39
        PushButton 450, 140, 30, 10, "Set", .btnSetFeeder38
        PushButton 450, 150, 30, 10, "Set", .btnSetFeeder37
        PushButton 450, 160, 30, 10, "Set", .btnSetFeeder36
        PushButton 450, 170, 30, 10, "Set", .btnSetFeeder35
        PushButton 450, 180, 30, 10, "Set", .btnSetFeeder34
        PushButton 450, 190, 30, 10, "Set", .btnSetFeeder33
        PushButton 450, 200, 30, 10, "Set", .btnSetFeeder32
        PushButton 450, 210, 30, 10, "Set", .btnSetFeeder31
        PushButton 450, 220, 30, 10, "Set", .btnSetFeeder30
        PushButton 450, 230, 30, 10, "Set", .btnSetFeeder29
        PushButton 450, 240, 30, 10, "Set", .btnSetFeeder28
        PushButton 450, 250, 30, 10, "Set", .btnSetFeeder27
        PushButton 450, 260, 30, 10, "Set", .btnSetFeeder26

        Text    10, 290, 150, 10, .lastAction
        OkButton 410, 290, 70, 10

    End Dialog

    Begin Dialog dlgCalibrateHeads 510, 420, "Head calibration", .dialogCalibrateHeads

        Text 10, 20, 200, 10,  "HL3", .HL3
        PushButton 10, 30, 30, 10, "Go G55", .btnGotoG55HL3
        PushButton 10, 40, 30, 10, "Go G56", .btnGotoG56HL3
        PushButton 40, 30, 20, 10, "Set", .btnSetG55HL3
        PushButton 40, 40, 20, 10, "Set", .btnSetG56HL3
        Text 80, 30, 50, 10,  "Small bump"
        PushButton 130, 30, 30, 10, "Go G58", .btnHL3GoSmallBumpTOP
        PushButton 160, 30, 20, 10, "Set", .btnHL3SetSmallBumpTOP
        PushButton 180, 40, 30, 10, "Go G58", .btnHL3GoSmallBumpRIGHT
        PushButton 210, 40, 20, 10, "Set", .btnHL3SetSmallBumpRIGHT
        PushButton 80, 40, 30, 10, "Go G58", .btnHL3GoSmallBumpLEFT
        PushButton 110, 40, 20, 10, "Set", .btnHL3SetSmallBumpLEFT
        PushButton 130, 50, 30, 10, "Go G58", .btnHL3GoSmallBumpBOTTOM
        PushButton 160, 50, 20, 10, "Set", .btnHL3SetSmallBumpBOTTOM
        Text 80, 70, 50, 10,  "Large bump"
        PushButton 130, 70, 30, 10, "Go G58", .btnHL3GoLargeBumpTOP
        PushButton 160, 70, 20, 10, "Set", .btnHL3SetLargeBumpTOP
        PushButton 180, 80, 30, 10, "Go G58", .btnHL3GoLargeBumpRIGHT
        PushButton 210, 80, 20, 10, "Set", .btnHL3SetLargeBumpRIGHT
        PushButton 80, 80, 30, 10, "Go G58", .btnHL3GoLargeBumpLEFT
        PushButton 110, 80, 20, 10, "Set", .btnHL3SetLargeBumpLEFT
        PushButton 130, 90, 30, 10, "Go G58", .btnHL3GoLargeBumpBOTTOM
        PushButton 160, 90, 20, 10, "Set", .btnHL3SetLargeBumpBOTTOM
        
        Text 270, 20, 200, 10,  "HR3", .HR3
        PushButton 270, 30, 30, 10, "Go G55", .btnGotoG55HR3
        PushButton 270, 40, 30, 10, "Go G57", .btnGotoG57HR3
        PushButton 300, 30, 20, 10, "Set", .btnSetG55HR3
        PushButton 300, 40, 20, 10, "Set", .btnSetG57HR3
        Text 340, 30, 50, 10,  "Small bump"
        PushButton 390, 30, 30, 10, "Go G58", .btnHR3GoSmallBumpTOP
        PushButton 420, 30, 20, 10, "Set", .btnHR3SetSmallBumpTOP
        PushButton 440, 40, 30, 10, "Go G58", .btnHR3GoSmallBumpRIGHT
        PushButton 470, 40, 20, 10, "Set", .btnHR3SetSmallBumpRIGHT
        PushButton 340, 40, 30, 10, "Go G58", .btnHR3GoSmallBumpLEFT
        PushButton 370, 40, 20, 10, "Set", .btnHR3SetSmallBumpLEFT
        PushButton 390, 50, 30, 10, "Go G58", .btnHR3GoSmallBumpBOTTOM
        PushButton 420, 50, 20, 10, "Set", .btnHR3SetSmallBumpBOTTOM
        Text 340, 70, 50, 10,  "Large bump"
        PushButton 390, 70, 30, 10, "Go G58", .btnHR3GoLargeBumpTOP
        PushButton 420, 70, 20, 10, "Set", .btnHR3SetLargeBumpTOP
        PushButton 440, 80, 30, 10, "Go G58", .btnHR3GoLargeBumpRIGHT
        PushButton 470, 80, 20, 10, "Set", .btnHR3SetLargeBumpRIGHT
        PushButton 340, 80, 30, 10, "Go G58", .btnHR3GoLargeBumpLEFT
        PushButton 370, 80, 20, 10, "Set", .btnHR3SetLargeBumpLEFT
        PushButton 390, 90, 30, 10, "Go G58", .btnHR3GoLargeBumpBOTTOM
        PushButton 420, 90, 20, 10, "Set", .btnHR3SetLargeBumpBOTTOM
        
        Text 10, 110, 200, 10,  "HL2", .HL2
        PushButton 10, 120, 30, 10, "Go G55", .btnGotoG55HL2
        PushButton 10, 130, 30, 10, "Go G56", .btnGotoG56HL2
        PushButton 40, 120, 20, 10, "Set", .btnSetG55HL2
        PushButton 40, 130, 20, 10, "Set", .btnSetG56HL2
        Text 80, 120, 50, 10,  "Small bump"
        PushButton 130, 120, 30, 10, "Go G58", .btnHL2GoSmallBumpTOP
        PushButton 160, 120, 20, 10, "Set", .btnHL2SetSmallBumpTOP
        PushButton 180, 130, 30, 10, "Go G58", .btnHL2GoSmallBumpRIGHT
        PushButton 210, 130, 20, 10, "Set", .btnHL2SetSmallBumpRIGHT
        PushButton 80, 130, 30, 10, "Go G58", .btnHL2GoSmallBumpLEFT
        PushButton 110, 130, 20, 10, "Set", .btnHL2SetSmallBumpLEFT
        PushButton 130, 140, 30, 10, "Go G58", .btnHL2GoSmallBumpBOTTOM
        PushButton 160, 140, 20, 10, "Set", .btnHL2SetSmallBumpBOTTOM
        Text 80, 160, 50, 10,  "Large bump"
        PushButton 130, 160, 30, 10, "Go G58", .btnHL2GoLargeBumpTOP
        PushButton 160, 160, 20, 10, "Set", .btnHL2SetLargeBumpTOP
        PushButton 180, 170, 30, 10, "Go G58", .btnHL2GoLargeBumpRIGHT
        PushButton 210, 170, 20, 10, "Set", .btnHL2SetLargeBumpRIGHT
        PushButton 80, 170, 30, 10, "Go G58", .btnHL2GoLargeBumpLEFT
        PushButton 110, 170, 20, 10, "Set", .btnHL2SetLargeBumpLEFT
        PushButton 130, 180, 30, 10, "Go G58", .btnHL2GoLargeBumpBOTTOM
        PushButton 160, 180, 20, 10, "Set", .btnHL2SetLargeBumpBOTTOM
        
        Text 270, 110, 200, 10,  "HR2", .HR2
        PushButton 270, 120, 30, 10, "Go G55", .btnGotoG55HR2
        PushButton 270, 130, 30, 10, "Go G57", .btnGotoG57HR2
        PushButton 300, 120, 20, 10, "Set", .btnSetG55HR2
        PushButton 300, 130, 20, 10, "Set", .btnSetG57HR2
        Text 340, 120, 50, 10,  "Small bump"
        PushButton 390, 120, 30, 10, "Go G58", .btnHR2GoSmallBumpTOP
        PushButton 420, 120, 20, 10, "Set", .btnHR2SetSmallBumpTOP
        PushButton 440, 130, 30, 10, "Go G58", .btnHR2GoSmallBumpRIGHT
        PushButton 470, 130, 20, 10, "Set", .btnHR2SetSmallBumpRIGHT
        PushButton 340, 130, 30, 10, "Go G58", .btnHR2GoSmallBumpLEFT
        PushButton 370, 130, 20, 10, "Set", .btnHR2SetSmallBumpLEFT
        PushButton 390, 140, 30, 10, "Go G58", .btnHR2GoSmallBumpBOTTOM
        PushButton 420, 140, 20, 10, "Set", .btnHR2SetSmallBumpBOTTOM
        Text 340, 160, 140, 10,  "Large bump"
        PushButton 390, 160, 30, 10, "Go G58", .btnHR2GoLargeBumpTOP
        PushButton 420, 160, 20, 10, "Set", .btnHR2SetLargeBumpTOP
        PushButton 440, 170, 30, 10, "Go G58", .btnHR2GoLargeBumpRIGHT
        PushButton 470, 170, 20, 10, "Set", .btnHR2SetLargeBumpRIGHT
        PushButton 340, 170, 30, 10, "Go G58", .btnHR2GoLargeBumpLEFT
        PushButton 370, 170, 20, 10, "Set", .btnHR2SetLargeBumpLEFT
        PushButton 390, 180, 30, 10, "Go G58", .btnHR2GoLargeBumpBOTTOM
        PushButton 420, 180, 20, 10, "Set", .btnHR2SetLargeBumpBOTTOM
        
        Text 10, 200, 200, 10,  "HL1", .HL1
        PushButton 10, 210, 30, 10, "Go G55", .btnGotoG55HL1
        PushButton 10, 220, 30, 10, "Go G56", .btnGotoG56HL1
        PushButton 40, 210, 20, 10, "Set", .btnSetG55HL1
        PushButton 40, 220, 20, 10, "Set", .btnSetG56HL1
        Text 80, 210, 50, 10,  "Small bump"
        PushButton 130, 210, 30, 10, "Go G58", .btnHL1GoSmallBumpTOP
        PushButton 160, 210, 20, 10, "Set", .btnHL1SetSmallBumpTOP
        PushButton 180, 220, 30, 10, "Go G58", .btnHL1GoSmallBumpRIGHT
        PushButton 210, 220, 20, 10, "Set", .btnHL1SetSmallBumpRIGHT
        PushButton 80, 220, 30, 10, "Go G58", .btnHL1GoSmallBumpLEFT
        PushButton 110, 220, 20, 10, "Set", .btnHL1SetSmallBumpLEFT
        PushButton 130, 230, 30, 10, "Go G58", .btnHL1GoSmallBumpBOTTOM
        PushButton 160, 230, 20, 10, "Set", .btnHL1SetSmallBumpBOTTOM
        Text 80, 250, 50, 10,  "Large bump"
        PushButton 130, 250, 30, 10, "Go G58", .btnHL1GoLargeBumpTOP
        PushButton 160, 250, 20, 10, "Set", .btnHL1SetLargeBumpTOP
        PushButton 180, 260, 30, 10, "Go G58", .btnHL1GoLargeBumpRIGHT
        PushButton 210, 260, 20, 10, "Set", .btnHL1SetLargeBumpRIGHT
        PushButton 80, 260, 30, 10, "Go G58", .btnHL1GoLargeBumpLEFT
        PushButton 110, 260, 20, 10, "Set", .btnHL1SetLargeBumpLEFT
        PushButton 130, 270, 30, 10, "Go G58", .btnHL1GoLargeBumpBOTTOM
        PushButton 160, 270, 20, 10, "Set", .btnHL1SetLargeBumpBOTTOM
        
        Text 270, 200, 200, 10,  "HR1", .HR1
        PushButton 270, 210, 30, 10, "Go G55", .btnGotoG55HR1
        PushButton 270, 220, 30, 10, "Go G57", .btnGotoG57HR1
        PushButton 300, 210, 20, 10, "Set", .btnSetG55HR1
        PushButton 300, 220, 20, 10, "Set", .btnSetG57HR1
        Text 340, 210, 50, 10,  "Small bump"
        PushButton 390, 210, 30, 10, "Go G58", .btnHR1GoSmallBumpTOP
        PushButton 420, 210, 20, 10, "Set", .btnHR1SetSmallBumpTOP
        PushButton 440, 220, 30, 10, "Go G58", .btnHR1GoSmallBumpRIGHT
        PushButton 470, 220, 20, 10, "Set", .btnHR1SetSmallBumpRIGHT
        PushButton 340, 220, 30, 10, "Go G58", .btnHR1GoSmallBumpLEFT
        PushButton 370, 220, 20, 10, "Set", .btnHR1SetSmallBumpLEFT
        PushButton 390, 230, 30, 10, "Go G58", .btnHR1GoSmallBumpBOTTOM
        PushButton 420, 230, 20, 10, "Set", .btnHR1SetSmallBumpBOTTOM
        Text 340, 250, 140, 10,  "Large bump"
        PushButton 390, 250, 30, 10, "Go G58", .btnHR1GoLargeBumpTOP
        PushButton 420, 250, 20, 10, "Set", .btnHR1SetLargeBumpTOP
        PushButton 440, 260, 30, 10, "Go G58", .btnHR1GoLargeBumpRIGHT
        PushButton 470, 260, 20, 10, "Set", .btnHR1SetLargeBumpRIGHT
        PushButton 340, 260, 30, 10, "Go G58", .btnHR1GoLargeBumpLEFT
        PushButton 370, 260, 20, 10, "Set", .btnHR1SetLargeBumpLEFT
        PushButton 390, 270, 30, 10, "Go G58", .btnHR1GoLargeBumpBOTTOM
        PushButton 420, 270, 20, 10, "Set", .btnHR1SetLargeBumpBOTTOM
        
            Text 10, 290, 200, 10,  "HL0", .HL0
        PushButton 10, 300, 30, 10, "Go G55", .btnGotoG55HL0
        PushButton 10, 310, 30, 10, "Go G56", .btnGotoG56HL0
        PushButton 40, 300, 20, 10, "Set", .btnSetG55HL0
        PushButton 40, 310, 20, 10, "Set", .btnSetG56HL0
        Text 80, 300, 50, 10,  "Small bump"
        PushButton 130, 300, 30, 10, "Go G58", .btnHL0GoSmallBumpTOP
        PushButton 160, 300, 20, 10, "Set", .btnHL0SetSmallBumpTOP
        PushButton 180, 310, 30, 10, "Go G58", .btnHL0GoSmallBumpRIGHT
        PushButton 210, 310, 20, 10, "Set", .btnHL0SetSmallBumpRIGHT
        PushButton 80, 310, 30, 10, "Go G58", .btnHL0GoSmallBumpLEFT
        PushButton 110, 310, 20, 10, "Set", .btnHL0SetSmallBumpLEFT
        PushButton 130, 320, 30, 10, "Go G58", .btnHL0GoSmallBumpBOTTOM
        PushButton 160, 320, 20, 10, "Set", .btnHL0SetSmallBumpBOTTOM
        Text 80, 340, 50, 10,  "Large bump"
        PushButton 130, 340, 30, 10, "Go G58", .btnHL0GoLargeBumpTOP
        PushButton 160, 340, 20, 10, "Set", .btnHL0SetLargeBumpTOP
        PushButton 180, 350, 30, 10, "Go G58", .btnHL0GoLargeBumpRIGHT
        PushButton 210, 350, 20, 10, "Set", .btnHL0SetLargeBumpRIGHT
        PushButton 80, 350, 30, 10, "Go G58", .btnHL0GoLargeBumpLEFT
        PushButton 110, 350, 20, 10, "Set", .btnHL0SetLargeBumpLEFT
        PushButton 130, 360, 30, 10, "Go G58", .btnHL0GoLargeBumpBOTTOM
        PushButton 160, 360, 20, 10, "Set", .btnHL0SetLargeBumpBOTTOM
        
        Text 270, 290, 200, 10,  "HR0", .HR0
        PushButton 270, 300, 30, 10, "Go G55", .btnGotoG55HR0
        PushButton 270, 310, 30, 10, "Go G57", .btnGotoG57HR0
        PushButton 300, 300, 20, 10, "Set", .btnSetG55HR0
        PushButton 300, 310, 20, 10, "Set", .btnSetG57HR0
        Text 340, 300, 50, 10,  "Small bump"
        PushButton 390, 300, 30, 10, "Go G58", .btnHR0GoSmallBumpTOP
        PushButton 420, 300, 20, 10, "Set", .btnHR0SetSmallBumpTOP
        PushButton 440, 310, 30, 10, "Go G58", .btnHR0GoSmallBumpRIGHT
        PushButton 470, 310, 20, 10, "Set", .btnHR0SetSmallBumpRIGHT
        PushButton 340, 310, 30, 10, "Go G58", .btnHR0GoSmallBumpLEFT
        PushButton 370, 310, 20, 10, "Set", .btnHR0SetSmallBumpLEFT
        PushButton 390, 320, 30, 10, "Go G58", .btnHR0GoSmallBumpBOTTOM
        PushButton 420, 320, 20, 10, "Set", .btnHR0SetSmallBumpBOTTOM
        Text 340, 340, 140, 10,  "Large bump"
        PushButton 390, 340, 30, 10, "Go G58", .btnHR0GoLargeBumpTOP
        PushButton 420, 340, 20, 10, "Set", .btnHR0SetLargeBumpTOP
        PushButton 440, 350, 30, 10, "Go G58", .btnHR0GoLargeBumpRIGHT
        PushButton 470, 350, 20, 10, "Set", .btnHR0SetLargeBumpRIGHT
        PushButton 340, 350, 30, 10, "Go G58", .btnHR0GoLargeBumpLEFT
        PushButton 370, 350, 20, 10, "Set", .btnHR0SetLargeBumpLEFT
        PushButton 390, 360, 30, 10, "Go G58", .btnHR0GoLargeBumpBOTTOM
        PushButton 420, 360, 20, 10, "Set", .btnHR0SetLargeBumpBOTTOM
        
        Text 10, 390, 350, 10,  .Message
        
        Text    10, 400, 150, 10, .lastAction
        OkButton 380, 400, 70, 10

    End Dialog

    Begin Dialog dlgMain 510, 420, "Main", .dialogMain

        Text 210, 20, 35, 10, "FL25"
        Text 210, 30, 35, 10, "FL24"
        Text 210, 40, 35, 10, "FL23"
        Text 210, 50, 35, 10, "FL22"
        Text 210, 60, 35, 10, "FL21"
        Text 210, 70, 35, 10, "FL20"
        Text 210, 80, 35, 10, "FL19"
        Text 210, 90, 35, 10, "FL18"
        Text 210, 100, 35, 10, "FL17"
        Text 210, 110, 35, 10, "FL16"
        Text 210, 120, 35, 10, "FL15"
        Text 210, 130, 35, 10, "FL14"
        Text 210, 140, 35, 10, "FL13"
        Text 210, 150, 35, 10, "FL12"
        Text 210, 160, 35, 10, "FL11"
        Text 210, 170, 35, 10, "FL10"
        Text 210, 180, 35, 10, "FL9"
        Text 210, 190, 35, 10, "FL8"
        Text 210, 200, 35, 10, "FL7"
        Text 210, 210, 35, 10, "FL6"
        Text 210, 220, 35, 10, "FL5"
        Text 210, 230, 35, 10, "FL4"
        Text 210, 240, 35, 10, "FL3"
        Text 210, 250, 35, 10, "FL2"
        Text 210, 260, 35, 10, "FL1"
        
        Text 360, 20, 35, 10, "FR25"
        Text 360, 30, 35, 10, "FR24"
        Text 360, 40, 35, 10, "FR23"
        Text 360, 50, 35, 10, "FR22"
        Text 360, 60, 35, 10, "FR21"
        Text 360, 70, 35, 10, "FR20"
        Text 360, 80, 35, 10, "FR19"
        Text 360, 90, 35, 10, "FR18"
        Text 360, 100, 35, 10, "FR17"
        Text 360, 110, 35, 10, "FR16"
        Text 360, 120, 35, 10, "FR15"
        Text 360, 130, 35, 10, "FR14"
        Text 360, 140, 35, 10, "FR13"
        Text 360, 150, 35, 10, "FR12"
        Text 360, 160, 35, 10, "FR11"
        Text 360, 170, 35, 10, "FR10"
        Text 360, 180, 35, 10, "FR9"
        Text 360, 190, 35, 10, "FR8"
        Text 360, 200, 35, 10, "FR7"
        Text 360, 210, 35, 10, "FR6"
        Text 360, 220, 35, 10, "FR5"
        Text 360, 230, 35, 10, "FR4"
        Text 360, 240, 35, 10, "FR3"
        Text 360, 250, 35, 10, "FR2"
        Text 360, 260, 35, 10, "FR1"
        
        Text 240, 10, 50, 10, "Status"
        Text 240, 20, 50, 10,  .StatusFeeder25
        Text 240, 30, 50, 10,  .StatusFeeder24
        Text 240, 40, 50, 10,  .StatusFeeder23
        Text 240, 50, 50, 10,  .StatusFeeder22
        Text 240, 60, 50, 10,  .StatusFeeder21
        Text 240, 70, 50, 10,  .StatusFeeder20
        Text 240, 80, 50, 10,  .StatusFeeder19
        Text 240, 90, 50, 10,  .StatusFeeder18
        Text 240, 100, 50, 10,  .StatusFeeder17
        Text 240, 110, 50, 10,  .StatusFeeder16
        Text 240, 120, 50, 10,  .StatusFeeder15
        Text 240, 130, 50, 10,  .StatusFeeder14
        Text 240, 140, 50, 10,  .StatusFeeder13
        Text 240, 150, 50, 10,  .StatusFeeder12
        Text 240, 160, 50, 10,  .StatusFeeder11
        Text 240, 170, 50, 10,  .StatusFeeder10
        Text 240, 180, 50, 10,  .StatusFeeder9
        Text 240, 190, 50, 10,  .StatusFeeder8
        Text 240, 200, 50, 10,  .StatusFeeder7
        Text 240, 210, 50, 10,  .StatusFeeder6
        Text 240, 220, 50, 10,  .StatusFeeder5
        Text 240, 230, 50, 10,  .StatusFeeder4
        Text 240, 240, 50, 10,  .StatusFeeder3
        Text 240, 250, 50, 10,  .StatusFeeder2
        Text 240, 260, 50, 10,  .StatusFeeder1
        
        Text 390, 10, 50, 10, "Status"
        Text 390, 20, 50, 10,  .StatusFeeder50
        Text 390, 30, 50, 10,  .StatusFeeder49
        Text 390, 40, 50, 10,  .StatusFeeder48
        Text 390, 50, 50, 10,  .StatusFeeder47
        Text 390, 60, 50, 10,  .StatusFeeder46
        Text 390, 70, 50, 10,  .StatusFeeder45
        Text 390, 80, 50, 10,  .StatusFeeder44
        Text 390, 90, 50, 10,  .StatusFeeder43
        Text 390, 100, 50, 10,  .StatusFeeder42
        Text 390, 110, 50, 10,  .StatusFeeder41
        Text 390, 120, 50, 10,  .StatusFeeder40
        Text 390, 130, 50, 10,  .StatusFeeder39
        Text 390, 140, 50, 10,  .StatusFeeder38
        Text 390, 150, 50, 10,  .StatusFeeder37
        Text 390, 160, 50, 10,  .StatusFeeder36
        Text 390, 170, 50, 10,  .StatusFeeder35
        Text 390, 180, 50, 10,  .StatusFeeder34
        Text 390, 190, 50, 10,  .StatusFeeder33
        Text 390, 200, 50, 10,  .StatusFeeder32
        Text 390, 210, 50, 10,  .StatusFeeder31
        Text 390, 220, 50, 10,  .StatusFeeder30
        Text 390, 230, 50, 10,  .StatusFeeder29
        Text 390, 240, 50, 10,  .StatusFeeder28
        Text 390, 250, 50, 10,  .StatusFeeder27
        Text 390, 260, 50, 10,  .StatusFeeder26
        
        TextBox 305, 10, 20, 10, .flnewcount
        PushButton 305, 20, 40, 10, "Reset", .btnResetCountFeeder25
        PushButton 305, 30, 40, 10, "Reset", .btnResetCountFeeder24
        PushButton 305, 40, 40, 10, "Reset", .btnResetCountFeeder23
        PushButton 305, 50, 40, 10, "Reset", .btnResetCountFeeder22
        PushButton 305, 60, 40, 10, "Reset", .btnResetCountFeeder21
        PushButton 305, 70, 40, 10, "Reset", .btnResetCountFeeder20
        PushButton 305, 80, 40, 10, "Reset", .btnResetCountFeeder19
        PushButton 305, 90, 40, 10, "Reset", .btnResetCountFeeder18
        PushButton 305, 100, 40, 10, "Reset", .btnResetCountFeeder17
        PushButton 305, 110, 40, 10, "Reset", .btnResetCountFeeder16
        PushButton 305, 120, 40, 10, "Reset", .btnResetCountFeeder15
        PushButton 305, 130, 40, 10, "Reset", .btnResetCountFeeder14
        PushButton 305, 140, 40, 10, "Reset", .btnResetCountFeeder13
        PushButton 305, 150, 40, 10, "Reset", .btnResetCountFeeder12
        PushButton 305, 160, 40, 10, "Reset", .btnResetCountFeeder11
        PushButton 305, 170, 40, 10, "Reset", .btnResetCountFeeder10
        PushButton 305, 180, 40, 10, "Reset", .btnResetCountFeeder9
        PushButton 305, 190, 40, 10, "Reset", .btnResetCountFeeder8
        PushButton 305, 200, 40, 10, "Reset", .btnResetCountFeeder7
        PushButton 305, 210, 40, 10, "Reset", .btnResetCountFeeder6
        PushButton 305, 220, 40, 10, "Reset", .btnResetCountFeeder5
        PushButton 305, 230, 40, 10, "Reset", .btnResetCountFeeder4
        PushButton 305, 240, 40, 10, "Reset", .btnResetCountFeeder3
        PushButton 305, 250, 40, 10, "Reset", .btnResetCountFeeder2
        PushButton 305, 260, 40, 10, "Reset", .btnResetCountFeeder1
        
        TextBox 455, 10, 20, 10, .frnewcount
        PushButton 455, 20, 40, 10, "Reset", .btnResetCountFeeder50
        PushButton 455, 30, 40, 10, "Reset", .btnResetCountFeeder49
        PushButton 455, 40, 40, 10, "Reset", .btnResetCountFeeder48
        PushButton 455, 50, 40, 10, "Reset", .btnResetCountFeeder47
        PushButton 455, 60, 40, 10, "Reset", .btnResetCountFeeder46
        PushButton 455, 70, 40, 10, "Reset", .btnResetCountFeeder45
        PushButton 455, 80, 40, 10, "Reset", .btnResetCountFeeder44
        PushButton 455, 90, 40, 10, "Reset", .btnResetCountFeeder43
        PushButton 455, 100, 40, 10, "Reset", .btnResetCountFeeder42
        PushButton 455, 110, 40, 10, "Reset", .btnResetCountFeeder41
        PushButton 455, 120, 40, 10, "Reset", .btnResetCountFeeder40
        PushButton 455, 130, 40, 10, "Reset", .btnResetCountFeeder39
        PushButton 455, 140, 40, 10, "Reset", .btnResetCountFeeder38
        PushButton 455, 150, 40, 10, "Reset", .btnResetCountFeeder37
        PushButton 455, 160, 40, 10, "Reset", .btnResetCountFeeder36
        PushButton 455, 170, 40, 10, "Reset", .btnResetCountFeeder35
        PushButton 455, 180, 40, 10, "Reset", .btnResetCountFeeder34
        PushButton 455, 190, 40, 10, "Reset", .btnResetCountFeeder33
        PushButton 455, 200, 40, 10, "Reset", .btnResetCountFeeder32
        PushButton 455, 210, 40, 10, "Reset", .btnResetCountFeeder31
        PushButton 455, 220, 40, 10, "Reset", .btnResetCountFeeder30
        PushButton 455, 230, 40, 10, "Reset", .btnResetCountFeeder29
        PushButton 455, 240, 40, 10, "Reset", .btnResetCountFeeder28
        PushButton 455, 250, 40, 10, "Reset", .btnResetCountFeeder27
        PushButton 455, 260, 40, 10, "Reset", .btnResetCountFeeder26
        
        PushButton 10, 20, 90, 10, "Init Head Vars", .btnInitHeadVars
        PushButton 10, 30, 90, 10, "Init Feeder Vars", .btnInitFeederVars
        PushButton 100, 20, 90, 10, "Zero feeder counters", .btnzerofeeders ' not implemented yet
        
        Text         10, 50, 200, 10, " G55 Up looking camera origin"
        PushButton 10, 60, 90, 10, "Go Origin", .btnGoG55Origin
        PushButton 100, 60, 90, 10, "Set here", .btnSetG55Origin
        PushButton 10, 70, 90, 10, "Go X70 Y275 Y0", .btnGoG55High
        
        Text         10, 90, 200, 10, " G58 Bump centering origin"
        PushButton 10, 100, 90, 10, "Go Origin", .btnGoG58Origin
        PushButton 100, 100, 90, 10, "Set here", .btnSetG58Origin

        Text 10, 120, 200, 10, " G56 Left / G57 right feeder bank origins"
        PushButton 10, 130, 90, 10, "Go G56 Origin", .btnGoG56Origin
        PushButton 100, 130, 90, 10, "Set G56 here", .btnSetG56Origin
        PushButton 10, 140, 90, 10, "Go G57 Origin", .btnGoG57Origin
        PushButton 100, 140, 90, 10, "Set G57 here", .btnSetG57Origin
        
        Text        10, 170, 200, 10, "0 Rotation"
        PushButton 10, 180, 90, 10, "Go Origin", .btnGo0
        PushButton 100, 180, 90, 10, "Go Origin move 4mm", .btngGo04mm
        PushButton 10, 190, 90, 10, "Set origin here", .btnSet0
        PushButton 100, 190, 90, 10, "Set origin + 4mm offset", .btnSet04mm
        PushButton 10, 200, 90, 10, "Run Pick Place", .btnRun0
        
        Text        10, 230, 200, 10, "90 Rotation"
        PushButton 10, 240, 90, 10, "Go Origin", .btnGo90
        PushButton 100, 240, 90, 10, "Go Origin move 4mm", .btnGo904mm
        PushButton 10, 250, 90, 10, "Set origin here", .btnSet90
        PushButton 100, 250, 90, 10, "Set origin + 4mm offset", .btnSet904mm
        PushButton 10, 260, 90, 10, "Run Pick Place", .btnRun90

        Text        10, 290, 200, 10, "180 Rotation"
        PushButton 10, 300, 90, 10, "Go Origin", .btnGo180
        PushButton 100, 300, 90, 10, "Go Origin move 4mm", .btnGo1804mm
        PushButton 10, 310, 90, 10, "Set origin here", .btnSet180
        PushButton 100, 310, 90, 10, "Set origin + 4mm offset", .btnsSet1804mm
        PushButton 10, 320, 90, 10, "Run Pick Place", .btnRun180
    
        Text        10, 350,200, 10, "270 Rotation"
        PushButton 10, 360, 90, 10, "Go Origin", .btnGo270
        PushButton 100, 360, 90, 10, "Go Origin move 4mm", .btnGo2704mm
        PushButton 10, 370, 90, 10, "Set origin here", .btnSet270
        PushButton 100, 370, 90, 10, "Set origin + 4mm offset", .btnSet2704mm
        PushButton 10, 380, 90, 10, "Run Pick Place", .btnRun270
        
        PushButton 200, 390, 70, 10, "Calibrate Feeders", .btnCalibrateFeeders
        PushButton 200, 400, 70, 10, "Calibrate Heads", .btnCalibrateHeads
        
        PushButton 280, 390, 70, 10, "Buzzer Off", .btnBuzzerOff
        PushButton 280, 400, 70, 10, "Buzzer On", .btnBuzzerOn
        
        PushButton 360, 390, 70, 10, "Vacuum Off", .btnVacuumOff
        PushButton 360, 400, 70, 10, "Vacuum On", .btnVacuumOn
        
            
        PushButton 455, 390, 40, 10, "Refresh", .btnrefresh    ' no specific handler needed
        OkButton 455, 400, 40, 10
        
        Text    10, 400, 150, 10, .lastAction

    End Dialog

    ' MAIN
    currentDialog = currentDialogIsMain

    Do While currentDialog <> currentDialogIsNone
        Select Case currentDialog
            Case currentDialogIsMain
                returnMain = Dialog(dlgMain)
            Case currentDialogIsCalibrateFeeders
                returnCalibrateFeeders = Dialog(dlgCalibrateFeeders)
            Case currentDialogIsCalibrateHeads
                returnCalibrateHeads = Dialog(dlgCalibrateHeads)
            
        End Select
    Loop

End Sub


Function dialogCalibrateFeeders( ControlID$, Action%, SuppValue%)

    lastAction = "Welcome"
    
    dialogCalibrateFeeders = 1
    If Action = 2 Then
        If ControlID$ = "Ok" Or ControlID$ = "Cancel" Then
            dialogCalibrateFeeders = 0
            currentDialog = currentDialogIsMain
            
        Else
            'MsgBox(ControlID$)
            Select Case ControlID$
            
                Case "btnGotoFeeder50"
                    GotoFeeder(50)
                    lastAction = "btnGotoFeeder50 FR25"
                Case "btnGotoFeeder49"
                    GotoFeeder(49)
                    lastAction = "btnGotoFeeder49 FR24"
                Case "btnGotoFeeder48"
                    GotoFeeder(48)
                    lastAction = "btnGotoFeeder48 FR23"
                Case "btnGotoFeeder47"
                    GotoFeeder(47)
                    lastAction = "btnGotoFeeder47 FR22"
                Case "btnGotoFeeder46"
                    GotoFeeder(46)
                    lastAction = "btnGotoFeeder46 FR21"
                Case "btnGotoFeeder45"
                    GotoFeeder(45)
                    lastAction = "btnGotoFeeder45 FR20"
                Case "btnGotoFeeder44"
                    GotoFeeder(44)
                    lastAction = "btnGotoFeeder44 FR21"
                Case "btnGotoFeeder43"
                    GotoFeeder(43)
                    lastAction = "btnGotoFeeder43 FR18"
                Case "btnGotoFeeder42"
                    GotoFeeder(42)
                    lastAction = "btnGotoFeeder42 FR17"
                Case "btnGotoFeeder41"
                    GotoFeeder(41)
                    lastAction = "btnGotoFeeder41 FR16"
                Case "btnGotoFeeder40"
                    GotoFeeder(40)
                    lastAction = "btnGotoFeeder40 FR15"
                Case "btnGotoFeeder39"
                    GotoFeeder(39)
                    lastAction = "btnGotoFeeder39 FR14"
                Case "btnGotoFeeder38"
                    GotoFeeder(38)
                    lastAction = "btnGotoFeeder38 FR13"
                Case "btnGotoFeeder37"
                    GotoFeeder(37)
                    lastAction = "btnGotoFeeder37 FR12"
                Case "btnGotoFeeder36"
                    GotoFeeder(36)
                    lastAction = "btnGotoFeeder36 FR11"
                Case "btnGotoFeeder35"
                    GotoFeeder(35)
                    lastAction = "btnGotoFeeder35 FR10"
                Case "btnGotoFeeder34"
                    GotoFeeder(34)
                    lastAction = "btnGotoFeeder34 FR09"
                Case "btnGotoFeeder33"
                    GotoFeeder(33)
                    lastAction = "btnGotoFeeder33 FR08"
                Case "btnGotoFeeder32"
                    GotoFeeder(32)
                    lastAction = "btnGotoFeeder32 FR07"
                Case "btnGotoFeeder31"
                    GotoFeeder(31)
                    lastAction = "btnGotoFeeder31 FR06"
                Case "btnGotoFeeder30"
                    GotoFeeder(30)
                    lastAction = "btnGotoFeeder30 FR05"
                Case "btnGotoFeeder29"
                    GotoFeeder(29)
                    lastAction = "btnGotoFeeder29 FR04"
                Case "btnGotoFeeder28"
                    GotoFeeder(28)
                    lastAction = "btnGotoFeeder28 FR03"
                Case "btnGotoFeeder27"
                    GotoFeeder(27)
                    lastAction = "btnGotoFeeder27 FR02"
                Case "btnGotoFeeder26"
                    GotoFeeder(26)
                    lastAction = "btnGotoFeeder26 FR01"
                    
                Case "btnGotoFeeder25"
                    GotoFeeder(25)
                    lastAction = "btnGotoFeeder25 FL25"
                Case "btnGotoFeeder24"
                    GotoFeeder(24)
                    lastAction = "btnGotoFeeder24 FL24"
                Case "btnGotoFeeder23"
                    GotoFeeder(23)
                    lastAction = "btnGotoFeeder23 FL23"
                Case "btnGotoFeeder22"
                    GotoFeeder(22)
                    lastAction = "btnGotoFeeder22 FL22"
                Case "btnGotoFeeder21"
                    GotoFeeder(21)
                    lastAction = "btnGotoFeeder21 FL21"
                Case "btnGotoFeeder20"
                    GotoFeeder(20)
                    lastAction = "btnGotoFeeder20 FL20"
                Case "btnGotoFeeder19"
                    GotoFeeder(19)
                    lastAction = "btnGotoFeeder19 FL19"
                Case "btnGotoFeeder18"
                    GotoFeeder(18)
                    lastAction = "btnGotoFeeder18 FL18"
                Case "btnGotoFeeder17"
                    GotoFeeder(17)
                    lastAction = "btnGotoFeeder17 FL17"
                Case "btnGotoFeeder16"
                    GotoFeeder(16)
                    lastAction = "btnGotoFeeder16 FL16"
                Case "btnGotoFeeder15"
                    GotoFeeder(15)
                    lastAction = "btnGotoFeeder15 FL15"
                Case "btnGotoFeeder14"
                    GotoFeeder(14)
                    lastAction = "btnGotoFeeder14 FL14"
                Case "btnGotoFeeder13"
                    GotoFeeder(13)
                    lastAction = "btnGotoFeeder13 FL13"
                Case "btnGotoFeeder12"
                    GotoFeeder(12)
                    lastAction = "btnGotoFeeder12 FL12"
                Case "btnGotoFeeder11"
                    GotoFeeder(11)
                    lastAction = "btnGotoFeeder11 FL11"
                Case "btnGotoFeeder10"
                    GotoFeeder(10)
                    lastAction = "btnGotoFeeder10 FL10"
                Case "btnGotoFeeder9"
                    GotoFeeder(9)
                    lastAction = "btnGotoFeeder09 FL09"
                Case "btnGotoFeeder8"
                    GotoFeeder(8)
                    lastAction = "btnGotoFeeder08 FL08"
                Case "btnGotoFeeder7"
                    GotoFeeder(7)
                    lastAction = "btnGotoFeeder07 FL07"
                Case "btnGotoFeeder6"
                    GotoFeeder(6)
                    lastAction = "btnGotoFeeder06 FL06"
                Case "btnGotoFeeder5"
                    GotoFeeder(5)
                    lastAction = "btnGotoFeeder05 FL05"
                Case "btnGotoFeeder4"
                    GotoFeeder(4)
                    lastAction = "btnGotoFeeder04 FL04"
                Case "btnGotoFeeder3"
                    GotoFeeder(3)
                    lastAction = "btnGotoFeeder03 FL03"
                Case "btnGotoFeeder2"
                    GotoFeeder(2)
                    lastAction = "btnGotoFeeder02 FL02"
                Case "btnGotoFeeder1"
                    GotoFeeder(1)
                    lastAction = "btnGotoFeeder01 FL01"
    
                Case "btnSetFeeder50"
                    SetFeeder(50)
                    lastAction = "btnSetFeeder50 FR25"
                Case "btnSetFeeder49"
                    SetFeeder(49)
                    lastAction = "btnSetFeeder49 FR24"
                Case "btnSetFeeder48"
                    SetFeeder(48)
                    lastAction = "btnSetFeeder48 FR23"
                Case "btnSetFeeder47"
                    SetFeeder(47)
                    lastAction = "btnSetFeeder47 FR22"
                Case "btnSetFeeder46"
                    SetFeeder(46)
                    lastAction = "btnSetFeeder46 FR21"
                Case "btnSetFeeder45"
                    SetFeeder(45)
                    lastAction = "btnSetFeeder45 FR20"
                Case "btnSetFeeder44"
                    SetFeeder(44)
                    lastAction = "btnSetFeeder44 FR19"
                Case "btnSetFeeder43"
                    SetFeeder(43)
                    lastAction = "btnSetFeeder43 FR18"
                Case "btnSetFeeder42"
                    SetFeeder(42)
                    lastAction = "btnSetFeeder42 FR17"
                Case "btnSetFeeder41"
                    SetFeeder(41)
                    lastAction = "btnSetFeeder41 FR16"
                Case "btnSetFeeder40"
                    SetFeeder(40)
                    lastAction = "btnSetFeeder40 FR15"
                Case "btnSetFeeder39"
                    SetFeeder(39)
                    lastAction = "btnSetFeeder39 FR14"
                Case "btnSetFeeder38"
                    SetFeeder(38)
                    lastAction = "btnSetFeeder38 FR13"
                Case "btnSetFeeder37"
                    SetFeeder(37)
                    lastAction = "btnSetFeeder37 FR12"
                Case "btnSetFeeder36"
                    SetFeeder(36)
                    lastAction = "btnSetFeeder36 FR11"
                Case "btnSetFeeder35"
                    SetFeeder(35)
                    lastAction = "btnSetFeeder35 FR10"
                Case "btnSetFeeder34"
                    SetFeeder(34)
                    lastAction = "btnSetFeeder34 FR09"
                Case "btnSetFeeder33"
                    SetFeeder(33)
                    lastAction = "btnSetFeeder33 FR08"
                Case "btnSetFeeder32"
                    SetFeeder(32)
                    lastAction = "btnSetFeeder32 FR07"
                Case "btnSetFeeder31"
                    SetFeeder(31)
                    lastAction = "btnSetFeeder31 FR06"
                Case "btnSetFeeder30"
                    SetFeeder(30)
                    lastAction = "btnSetFeeder30 FR05"
                Case "btnSetFeeder29"
                    SetFeeder(29)
                    lastAction = "btnSetFeeder29 FR04"
                Case "btnSetFeeder28"
                    SetFeeder(28)
                    lastAction = "btnSetFeeder28 FR03"
                Case "btnSetFeeder27"
                    SetFeeder(27)
                    lastAction = "btnSetFeeder27 FR02"
                Case "btnSetFeeder26"
                    SetFeeder(26)
                    lastAction = "btnSetFeeder26 FR01"
    
                Case "btnSetFeeder25"
                    SetFeeder(25)
                    lastAction = "btnSetFeeder25 FL25"
                Case "btnSetFeeder24"
                    SetFeeder(24)
                    lastAction = "btnSetFeeder24 FL24"
                Case "btnSetFeeder23"
                    SetFeeder(23)
                    lastAction = "btnSetFeeder23 FL23"
                Case "btnSetFeeder22"
                    SetFeeder(22)
                    lastAction = "btnSetFeeder22 FL22"
                Case "btnSetFeeder21"
                    SetFeeder(21)
                    lastAction = "btnSetFeeder21 FL21"
                Case "btnSetFeeder20"
                    SetFeeder(20)
                    lastAction = "btnSetFeeder20 FL20"
                Case "btnSetFeeder19"
                    SetFeeder(19)
                    lastAction = "btnSetFeeder19 FL19"
                Case "btnSetFeeder18"
                    SetFeeder(18)
                    lastAction = "btnSetFeeder18 FL18"
                Case "btnSetFeeder17"
                    SetFeeder(17)
                    lastAction = "btnSetFeeder17 FL17"
                Case "btnSetFeeder16"
                    SetFeeder(16)
                    lastAction = "btnSetFeeder16 FL16"
                Case "btnSetFeeder15"
                    SetFeeder(15)
                    lastAction = "btnSetFeeder15 FL15"
                Case "btnSetFeeder14"
                    SetFeeder(14)
                    lastAction = "btnSetFeeder14 FL14"
                Case "btnSetFeeder13"
                    SetFeeder(13)
                    lastAction = "btnSetFeeder13 FL13"
                Case "btnSetFeeder12"
                    SetFeeder(12)
                    lastAction = "btnSetFeeder12 FL12"
                Case "btnSetFeeder11"
                    SetFeeder(11)
                    lastAction = "btnSetFeeder11 FL11"
                Case "btnSetFeeder10"
                    SetFeeder(10)
                    lastAction = "btnSetFeeder10 FL10"
                Case "btnSetFeeder9"
                    SetFeeder(09)
                    lastAction = "btnSetFeeder09 FL09"
                Case "btnSetFeeder8"
                    SetFeeder(08)
                    lastAction = "btnSetFeeder08 FL08"
                Case "btnSetFeeder7"
                    SetFeeder(07)
                    lastAction = "btnSetFeeder07 FL07"
                Case "btnSetFeeder6"
                    SetFeeder(06)
                    lastAction = "btnSetFeeder06 FL06"
                Case "btnSetFeeder5"
                    SetFeeder(05)
                    lastAction = "btnSetFeeder05 FL05"
                Case "btnSetFeeder4"
                    SetFeeder(04)
                    lastAction = "btnSetFeeder04 FL04"
                Case "btnSetFeeder3"
                    SetFeeder(03)
                    lastAction = "btnSetFeeder03 FL03"
                Case "btnSetFeeder2"
                    SetFeeder(02)
                    lastAction = "btnSetFeeder02 FL02"
                Case "btnSetFeeder1"
                    SetFeeder(01)
                    lastAction = "btnSetFeeder01 FL01"

            End Select
        End If
    End If
    
    If Action = 1 Or Action = 2 Then
        ' redisplay values
        Dim count As Integer
        Dim temp
        Dim feederID
        For count = 1 To 25 ' FL ID 0 to 25
            DlgText "btnGotoFeeder" & count, "Goto G56 X:" & CStr(GetVar(FeederGCodeBaseVarX + count)) & " Y: " & CStr(GetVar(FeederGCodeBaseVarY + count))
        Next
        
        For count = 26 To 50
            DlgText "btnGotoFeeder" & count, "Goto G57 X:" & CStr(GetVar(FeederGCodeBaseVarX + count)) & " Y: " & CStr(GetVar(FeederGCodeBaseVarY + count))
        Next        

    End If
    
    ' Camera cannot reach these feeders so disable the button
    DlgEnable "btnGotoFeeder25", 0
    DlgEnable "btnGotoFeeder24", 0
    DlgEnable "btnGotoFeeder23", 0
    
    DlgEnable "btnGotoFeeder3", 0
    DlgEnable "btnGotoFeeder2", 0
    DlgEnable "btnGotoFeeder1", 0
    
    DlgEnable "btnGotoFeeder50", 0
    DlgEnable "btnGotoFeeder49", 0
    DlgEnable "btnGotoFeeder48", 0
    
    DlgEnable "btnGotoFeeder28", 0
    DlgEnable "btnGotoFeeder27", 0
    DlgEnable "btnGotoFeeder26", 0
    
    DlgText "lastAction", lastAction
    
End Function


Function dialogCalibrateHeads( ControlID$, Action%, SuppValue%)

    lastAction = "Welcome"
    
    dialogCalibrateHeads = 1
    If Action = 2 Then
        If ControlID$ = "Ok" Or ControlID$ = "Cancel" Then
            dialogCalibrateHeads = 0
            currentDialog = currentDialogIsMain

        Else
            'MsgBox(ControlID$)
            Select Case ControlID$
                Case "btnGotoG55HL3"
                    GoHead "G55", 3
                    lastAction = "btnGotoG55HL3"
                Case "btnGotoG55HL2"
                    GoHead "G55", 2
                    lastAction = "btnGotoG55HL2"
                Case "btnGotoG55HL1"
                    GoHead "G55", 1
                    lastAction = "btnGotoG55HL1"
                Case "btnGotoG55HL0"
                    GoHead "G55", 0
                    lastAction = "btnGotoG55HL0"
                Case "btnGotoG55HR3"
                    GoHead "G55", 13
                    lastAction = "btnGotoG55HR3"
                Case "btnGotoG55HR2"
                    GoHead "G55", 12
                    lastAction = "btnGotoG55HR2"
                Case "btnGotoG55HR1"
                    GoHead "G55", 11
                    lastAction = "btnGotoG55HR1"
                Case "btnGotoG55HR0"
                    GoHead "G55", 10
                    lastAction = "btnGotoG55HR0"
                    
                Case "btnGotoG56HL3"
                    GoHead "G56", 3
                    lastAction = "btnGotoG56HL3"
                Case "btnGotoG56HL2"
                    GoHead "G56", 2
                    lastAction = "btnGotoG56HL2"
                Case "btnGotoG56HL1"
                    GoHead "G56", 1
                    lastAction = "btnGotoG56HL1"
                Case "btnGotoG56HL0"
                    GoHead "G56", 0
                    lastAction = "btnGotoG56HL0"
                    
                Case "btnGotoG57HR3"
                    GoHead "G57", 13
                    lastAction = "btnGotoG57HR3"
                Case "btnGotoG57HR2"
                    GoHead "G57", 12
                    lastAction = "btnGotoG57HR2"
                Case "btnGotoG57HR1"
                    GoHead "G57", 11
                    lastAction = "btnGotoG57HR1"
                Case "btnGotoG57HR0"
                    GoHead "G57", 10
                    lastAction = "btnGotoG57HR0"
                    
                Case "btnSetG55HL3"
                    SetHead "G55", 3
                    lastAction = "btnSetG55HL3"
                Case "btnSetG55HL2"
                    SetHead "G55", 2
                    lastAction = "btnSetG55HL2"
                Case "btnSetG55HL1"
                    SetHead "G55", 1
                    lastAction = "btnSetG55HL1"
                Case "btnSetG55HL0"
                    SetHead "G55", 0
                    lastAction = "btnSetG55HL0"
                Case "btnSetG55HR3"
                    SetHead "G55", 13
                    lastAction = "btnSetG55HR3"
                Case "btnSetG55HR2"
                    SetHead "G55", 12
                    lastAction = "btnSetG55HR2"
                Case "btnSetG55HR1"
                    SetHead "G55", 11
                    lastAction = "btnSetG55HR1"
                Case "btnSetG55HR0"
                    SetHead "G55", 10
                    lastAction = "btnSetG55HR0"
                    
                Case "btnSetG56HL3"
                    SetHead "G56", 3
                    lastAction = "btnSetG56HL3"
                Case "btnSetG56HL2"
                    SetHead "G56", 2
                    lastAction = "btnSetG56HL2"
                Case "btnSetG56HL1"
                    SetHead "G56", 1
                    lastAction = "btnSetG56HL1"
                Case "btnSetG56HL0"
                    SetHead "G56", 0
                    lastAction = "btnSetG56HL0"
                    
                Case "btnSetG57HR3"
                    SetHead "G57", 13
                    lastAction = "btnSetG57HR3"
                Case "btnSetG57HR2"
                    SetHead "G57", 12
                    lastAction = "btnSetG57HR2"
                Case "btnSetG57HR1"
                    SetHead "G57", 11
                    lastAction = "btnSetG57HR1"
                Case "btnSetG57HR0"
                    SetHead "G57", 10
                    lastAction = "btnSetG57HR0"
                    
                    
                Case "btnHL3GoSmallBumpTOP"
                    GoSmallBumpTOP(3)
                    lastAction = "btnHL3GoSmallBumpTOP"
                Case "btnHL2GoSmallBumpTOP"
                    GoSmallBumpTOP(2)
                    lastAction = "btnHL2GoSmallBumpTOP"
                Case "btnHL1GoSmallBumpTOP"
                    GoSmallBumpTOP(1)
                    lastAction = "btnHL1GoSmallBumpTOP"
                Case "btnHL0GoSmallBumpTOP"
                    GoSmallBumpTOP(0)
                    lastAction = "btnHL0GoSmallBumpTOP"
                Case "btnHR3GoSmallBumpTOP"
                    GoSmallBumpTOP(13)
                    lastAction = "btnHR3GoSmallBumpTOP"
                Case "btnHR2GoSmallBumpTOP"
                    GoSmallBumpTOP(12)
                    lastAction = "btnHR2GoSmallBumpTOP"
                Case "btnHR1GoSmallBumpTOP"
                    GoSmallBumpTOP(11)
                    lastAction = "btnHR1GoSmallBumpTOP"
                Case "btnHR0GoSmallBumpTOP"
                    GoSmallBumpTOP(10)
                    lastAction = "btnHR0GoSmallBumpTOP"
                    
                Case "btnHL3GoSmallBumpBottom"
                    GoSmallBumpBottom(3)
                    lastAction = "btnHL3GoSmallBumpBottom"
                Case "btnHL2GoSmallBumpBottom"
                    GoSmallBumpBottom(2)
                    lastAction = "btnHL2GoSmallBumpBottom"
                Case "btnHL1GoSmallBumpBottom"
                    GoSmallBumpBottom(1)
                    lastAction = "btnHL1GoSmallBumpBottom"
                Case "btnHL0GoSmallBumpBottom"
                    GoSmallBumpBottom(0)
                    lastAction = "btnHL0GoSmallBumpBottom"
                Case "btnHR3GoSmallBumpBottom"
                    GoSmallBumpBottom(13)
                    lastAction = "btnHR3GoSmallBumpBottom"
                Case "btnHR2GoSmallBumpBottom"
                    GoSmallBumpBottom(12)
                    lastAction = "btnHR2GoSmallBumpBottom"
                Case "btnHR1GoSmallBumpBottom"
                    GoSmallBumpBottom(11)
                    lastAction = "btnHR1GoSmallBumpBottom"
                Case "btnHR0GoSmallBumpBottom"
                    GoSmallBumpBottom(10)
                    lastAction = "btnHR0GoSmallBumpBottom"
                    
                Case "btnHL3GoSmallBumpLeft"
                    GoSmallBumpLeft(3)
                    lastAction = "btnHL3GoSmallBumpLeft"
                Case "btnHL2GoSmallBumpLeft"
                    GoSmallBumpLeft(2)
                    lastAction = "btnHL2GoSmallBumpLeft"
                Case "btnHL1GoSmallBumpLeft"
                    GoSmallBumpLeft(1)
                    lastAction = "btnHL1GoSmallBumpLeft"
                Case "btnHL0GoSmallBumpLeft"
                    GoSmallBumpLeft(0)
                    lastAction = "btnHL0GoSmallBumpLeft"
                Case "btnHR3GoSmallBumpLeft"
                    GoSmallBumpLeft(13)
                    lastAction = "btnHR3GoSmallBumpLeft"
                Case "btnHR2GoSmallBumpLeft"
                    GoSmallBumpLeft(12)
                    lastAction = "btnHR2GoSmallBumpLeft"
                Case "btnHR1GoSmallBumpLeft"
                    GoSmallBumpLeft(11)
                    lastAction = "btnHR1GoSmallBumpLeft"
                Case "btnHR0GoSmallBumpLeft"
                    GoSmallBumpLeft(10)
                    lastAction = "btnHR0GoSmallBumpLeft"
                
                Case "btnHL3GoSmallBumpRight"
                    GoSmallBumpRight(3)
                    lastAction = "btnHL3GoSmallBumpRight"
                Case "btnHL2GoSmallBumpRight"
                    GoSmallBumpRight(2)
                    lastAction = "btnHL2GoSmallBumpRight"
                Case "btnHL1GoSmallBumpRight"
                    GoSmallBumpRight(1)
                    lastAction = "btnHL1GoSmallBumpRight"
                Case "btnHL0GoSmallBumpRight"
                    GoSmallBumpRight(0)
                    lastAction = "btnHL0GoSmallBumpRight"
                Case "btnHR3GoSmallBumpRight"
                    GoSmallBumpRight(13)
                    lastAction = "btnHR3GoSmallBumpRight"
                Case "btnHR2GoSmallBumpRight"
                    GoSmallBumpRight(12)
                    lastAction = "btnHR2GoSmallBumpRight"
                Case "btnHR1GoSmallBumpRight"
                    GoSmallBumpRight(11)
                    lastAction = "btnHR1GoSmallBumpRight"
                Case "btnHR0GoSmallBumpRight"
                    GoSmallBumpRight(10)
                    lastAction = "btnHR0GoSmallBumpRight"
                    
                Case "btnHL3SetSmallBumpTop"
                    SetSmallBumpTop(3)
                    lastAction = "btnHL3SetSmallBumpTop"
                Case "btnHL2SetSmallBumpTop"
                    SetSmallBumpTop(2)
                    lastAction = "btnHL2SetSmallBumpTop"
                Case "btnHL1SetSmallBumpTop"
                    SetSmallBumpTop(1)
                    lastAction = "btnHL1SetSmallBumpTop"
                Case "btnHL0SetSmallBumpTop"
                    SetSmallBumpTop(0)
                    lastAction = "btnHL0SetSmallBumpTop"
                Case "btnHR3SetSmallBumpTop"
                    SetSmallBumpTop(13)
                    lastAction = "btnHR3SetSmallBumpTop"
                Case "btnHR2SetSmallBumpTop"
                    SetSmallBumpTop(12)
                    lastAction = "btnHR2SetSmallBumpTop"
                Case "btnHR1SetSmallBumpTop"
                    SetSmallBumpTop(11)
                    lastAction = "btnHR1SetSmallBumpTop"
                Case "btnHR0SetSmallBumpTop"
                    SetSmallBumpTop(10)
                    lastAction = "btnHR0SetSmallBumpTop"
                    
                Case "btnHL3SetSmallBumpBottom"
                    SetSmallBumpBottom(3)
                    lastAction = "btnHL3SetSmallBumpBottom"
                Case "btnHL2SetSmallBumpBottom"
                    SetSmallBumpBottom(2)
                    lastAction = "btnHL2SetSmallBumpBottom"
                Case "btnHL1SetSmallBumpBottom"
                    SetSmallBumpBottom(1)
                    lastAction = "btnHL1SetSmallBumpBottom"
                Case "btnHL0SetSmallBumpBottom"
                    SetSmallBumpBottom(0)
                    lastAction = "btnHL0SetSmallBumpBottom"
                Case "btnHR3SetSmallBumpBottom"
                    SetSmallBumpBottom(13)
                    lastAction = "btnHR3SetSmallBumpBottom"
                Case "btnHR2SetSmallBumpBottom"
                    SetSmallBumpBottom(12)
                    lastAction = "btnHR2SetSmallBumpBottom"
                Case "btnHR1SetSmallBumpBottom"
                    SetSmallBumpBottom(11)
                    lastAction = "btnHR1SetSmallBumpBottom"
                Case "btnHR0SetSmallBumpBottom"
                    SetSmallBumpBottom(10)
                    lastAction = "btnHR0SetSmallBumpBottom"
                    
                Case "btnHL3SetSmallBumpLeft"
                    SetSmallBumpLeft(3)
                    lastAction = "btnHL3SetSmallBumpLeft"
                Case "btnHL2SetSmallBumpLeft"
                    SetSmallBumpLeft(2)
                    lastAction = "btnHL2SetSmallBumpLeft"
                Case "btnHL1SetSmallBumpLeft"
                    SetSmallBumpLeft(1)
                    lastAction = "btnHL1SetSmallBumpLeft"
                Case "btnHL0SetSmallBumpLeft"
                    SetSmallBumpLeft(0)
                    lastAction = "btnHL0SetSmallBumpLeft"
                Case "btnHR3SetSmallBumpLeft"
                    SetSmallBumpLeft(13)
                    lastAction = "btnHR3SetSmallBumpLeft"
                Case "btnHR2SetSmallBumpLeft"
                    SetSmallBumpLeft(12)
                    lastAction = "btnHR2SetSmallBumpLeft"
                Case "btnHR1SetSmallBumpLeft"
                    SetSmallBumpLeft(11)
                    lastAction = "btnHR1SetSmallBumpLeft"
                Case "btnHR0SetSmallBumpLeft"
                    SetSmallBumpLeft(10)
                    lastAction = "btnHR0SetSmallBumpLeft"
                
                Case "btnHL3SetSmallBumpRight"
                    SetSmallBumpRight(3)
                    lastAction = "btnHL3SetSmallBumpRight"
                Case "btnHL2SetSmallBumpRight"
                    SetSmallBumpRight(2)
                    lastAction = "btnHL2SetSmallBumpRight"
                Case "btnHL1SetSmallBumpRight"
                    SetSmallBumpRight(1)
                    lastAction = "btnHL1SetSmallBumpRight"
                Case "btnHL0SetSmallBumpRight"
                    SetSmallBumpRight(0)
                    lastAction = "btnHL0SetSmallBumpRight"
                Case "btnHR3SetSmallBumpRight"
                    SetSmallBumpRight(13)
                    lastAction = "btnHR3SetSmallBumpRight"
                Case "btnHR2SetSmallBumpRight"
                    SetSmallBumpRight(12)
                    lastAction = "btnHR2SetSmallBumpRight"
                Case "btnHR1SetSmallBumpRight"
                    SetSmallBumpRight(11)
                    lastAction = "btnHR1SetSmallBumpRight"
                Case "btnHR0SetSmallBumpRight"
                    SetSmallBumpRight(10)
                    lastAction = "btnHR0SetSmallBumpRight"
                    
                Case "btnHL3GoLargeBumpTOP"
                    GoLargeBumpTOP(3)
                    lastAction = "btnHL3GoLargeBumpTOP"
                Case "btnHL2GoLargeBumpTOP"
                    GoLargeBumpTOP(2)
                    lastAction = "btnHL2GoLargeBumpTOP"
                Case "btnHL1GoLargeBumpTOP"
                    GoLargeBumpTOP(1)
                    lastAction = "btnHL1GoLargeBumpTOP"
                Case "btnHL0GoLargeBumpTOP"
                    GoLargeBumpTOP(0)
                    lastAction = "btnHL0GoLargeBumpTOP"
                Case "btnHR3GoLargeBumpTOP"
                    GoLargeBumpTOP(13)
                    lastAction = "btnHR3GoLargeBumpTOP"
                Case "btnHR2GoLargeBumpTOP"
                    GoLargeBumpTOP(12)
                    lastAction = "btnHR2GoLargeBumpTOP"
                Case "btnHR1GoLargeBumpTOP"
                    GoLargeBumpTOP(11)
                    lastAction = "btnHR1GoLargeBumpTOP"
                Case "btnHR0GoLargeBumpTOP"
                    GoLargeBumpTOP(10)
                    lastAction = "btnHR0GoLargeBumpTOP"
                    
                Case "btnHL3GoLargeBumpBottom"
                    GoLargeBumpBottom(3)
                    lastAction = "btnHL3GoLargeBumpBottom"
                Case "btnHL2GoLargeBumpBottom"
                    GoLargeBumpBottom(2)
                    lastAction = "btnHL2GoLargeBumpBottom"
                Case "btnHL1GoLargeBumpBottom"
                    GoLargeBumpBottom(1)
                    lastAction = "btnHL1GoLargeBumpBottom"
                Case "btnHL0GoLargeBumpBottom"
                    GoLargeBumpBottom(0)
                    lastAction = "btnHL0GoLargeBumpBottom"
                Case "btnHR3GoLargeBumpBottom"
                    GoLargeBumpBottom(13)
                    lastAction = "btnHR3GoLargeBumpBottom"
                Case "btnHR2GoLargeBumpBottom"
                    GoLargeBumpBottom(12)
                    lastAction = "btnHR2GoLargeBumpBottom"
                Case "btnHR1GoLargeBumpBottom"
                    GoLargeBumpBottom(11)
                    lastAction = "btnHR1GoLargeBumpBottom"
                Case "btnHR0GoLargeBumpBottom"
                    GoLargeBumpBottom(10)
                    lastAction = "btnHR0GoLargeBumpBottom"
                    
                Case "btnHL3GoLargeBumpLeft"
                    GoLargeBumpLeft(3)
                    lastAction = "btnHL3GoLargeBumpLeft"
                Case "btnHL2GoLargeBumpLeft"
                    GoLargeBumpLeft(2)
                    lastAction = "btnHL2GoLargeBumpLeft"
                Case "btnHL1GoLargeBumpLeft"
                    GoLargeBumpLeft(1)
                    lastAction = "btnHL1GoLargeBumpLeft"
                Case "btnHL0GoLargeBumpLeft"
                    GoLargeBumpLeft(0)
                    lastAction = "btnHL0GoLargeBumpLeft"
                Case "btnHR3GoLargeBumpLeft"
                    GoLargeBumpLeft(13)
                    lastAction = "btnHR3GoLargeBumpLeft"
                Case "btnHR2GoLargeBumpLeft"
                    GoLargeBumpLeft(12)
                    lastAction = "btnHR2GoLargeBumpLeft"
                Case "btnHR1GoLargeBumpLeft"
                    GoLargeBumpLeft(11)
                    lastAction = "btnHR1GoLargeBumpLeft"
                Case "btnHR0GoLargeBumpLeft"
                    GoLargeBumpLeft(10)
                    lastAction = "btnHR0GoLargeBumpLeft"
                
                Case "btnHL3GoLargeBumpRight"
                    GoLargeBumpRight(3)
                    lastAction = "btnHL3GoLargeBumpRight"
                Case "btnHL2GoLargeBumpRight"
                    GoLargeBumpRight(2)
                    lastAction = "btnHL2GoLargeBumpRight"
                Case "btnHL1GoLargeBumpRight"
                    GoLargeBumpRight(1)
                    lastAction = "btnHL1GoLargeBumpRight"
                Case "btnHL0GoLargeBumpRight"
                    GoLargeBumpRight(0)
                    lastAction = "btnHL0GoLargeBumpRight"
                Case "btnHR3GoLargeBumpRight"
                    GoLargeBumpRight(13)
                    lastAction = "btnHR3GoLargeBumpRight"
                Case "btnHR2GoLargeBumpRight"
                    GoLargeBumpRight(12)
                    lastAction = "btnHR2GoLargeBumpRight"
                Case "btnHR1GoLargeBumpRight"
                    GoLargeBumpRight(11)
                    lastAction = "btnHR1GoLargeBumpRight"
                Case "btnHR0GoLargeBumpRight"
                    GoLargeBumpRight(10)
                    lastAction = "btnHR0GoLargeBumpRight"
                    
                Case "btnHL3SetLargeBumpTop"
                    SetLargeBumpTop(3)
                    lastAction = "btnHL3SetLargeBumpTop"
                Case "btnHL2SetLargeBumpTop"
                    SetLargeBumpTop(2)
                    lastAction = "btnHL2SetLargeBumpTop"
                Case "btnHL1SetLargeBumpTop"
                    SetLargeBumpTop(1)
                    lastAction = "btnHL1SetLargeBumpTop"
                Case "btnHL0SetLargeBumpTop"
                    SetLargeBumpTop(0)
                    lastAction = "btnHL0SetLargeBumpTop"
                Case "btnHR3SetLargeBumpTop"
                    SetLargeBumpTop(13)
                    lastAction = "btnHR3SetLargeBumpTop"
                Case "btnHR2SetLargeBumpTop"
                    SetLargeBumpTop(12)
                    lastAction = "btnHR2SetLargeBumpTop"
                Case "btnHR1SetLargeBumpTop"
                    SetLargeBumpTop(11)
                    lastAction = "btnHR1SetLargeBumpTop"
                Case "btnHR0SetLargeBumpTop"
                    SetLargeBumpTop(10)
                    lastAction = "btnHR0SetLargeBumpTop"
                    
                Case "btnHL3SetLargeBumpBottom"
                    SetLargeBumpBottom(3)
                    lastAction = "btnHL3SetLargeBumpBottom"
                Case "btnHL2SetLargeBumpBottom"
                    SetLargeBumpBottom(2)
                    lastAction = "btnHL2SetLargeBumpBottom"
                Case "btnHL1SetLargeBumpBottom"
                    SetLargeBumpBottom(1)
                    lastAction = "btnHL1SetLargeBumpBottom"
                Case "btnHL0SetLargeBumpBottom"
                    SetLargeBumpBottom(0)
                    lastAction = "btnHL0SetLargeBumpBottom"
                Case "btnHR3SetLargeBumpBottom"
                    SetLargeBumpBottom(13)
                    lastAction = "btnHR3SetLargeBumpBottom"
                Case "btnHR2SetLargeBumpBottom"
                    SetLargeBumpBottom(12)
                    lastAction = "btnHR2SetLargeBumpBottom"
                Case "btnHR1SetLargeBumpBottom"
                    SetLargeBumpBottom(11)
                    lastAction = "btnHR1SetLargeBumpBottom"
                Case "btnHR0SetLargeBumpBottom"
                    SetLargeBumpBottom(10)
                    lastAction = "btnHR0SetLargeBumpBottom"
                    
                Case "btnHL3SetLargeBumpLeft"
                    SetLargeBumpLeft(3)
                    lastAction = "btnHL3SetLargeBumpLeft"
                Case "btnHL2SetLargeBumpLeft"
                    SetLargeBumpLeft(2)
                    lastAction = "btnHL2SetLargeBumpLeft"
                Case "btnHL1SetLargeBumpLeft"
                    SetLargeBumpLeft(1)
                    lastAction = "btnHL1SetLargeBumpLeft"
                Case "btnHL0SetLargeBumpLeft"
                    SetLargeBumpLeft(0)
                    lastAction = "btnHL0SetLargeBumpLeft"
                Case "btnHR3SetLargeBumpLeft"
                    SetLargeBumpLeft(13)
                    lastAction = "btnHR3SetLargeBumpLeft"
                Case "btnHR2SetLargeBumpLeft"
                    SetLargeBumpLeft(12)
                    lastAction = "btnHR2SetLargeBumpLeft"
                Case "btnHR1SetLargeBumpLeft"
                    SetLargeBumpLeft(11)
                    lastAction = "btnHR1SetLargeBumpLeft"
                Case "btnHR0SetLargeBumpLeft"
                    SetLargeBumpLeft(10)
                    lastAction = "btnHR0SetLargeBumpLeft"
                
                Case "btnHL3SetLargeBumpRight"
                    SetLargeBumpRight(3)
                    lastAction = "btnHL3SetLargeBumpRight"
                Case "btnHL2SetLargeBumpRight"
                    SetLargeBumpRight(2)
                    lastAction = "btnHL2SetLargeBumpRight"
                Case "btnHL1SetLargeBumpRight"
                    SetLargeBumpRight(1)
                    lastAction = "btnHL1SetLargeBumpRight"
                Case "btnHL0SetLargeBumpRight"
                    SetLargeBumpRight(0)
                    lastAction = "btnHL0SetLargeBumpRight"
                Case "btnHR3SetLargeBumpRight"
                    SetLargeBumpRight(13)
                    lastAction = "btnHR3SetLargeBumpRight"
                Case "btnHR2SetLargeBumpRight"
                    SetLargeBumpRight(12)
                    lastAction = "btnHR2SetLargeBumpRight"
                Case "btnHR1SetLargeBumpRight"
                    SetLargeBumpRight(11)
                    lastAction = "btnHR1SetLargeBumpRight"
                Case "btnHR0SetLargeBumpRight"
                    SetLargeBumpRight(10)
                    lastAction = "btnHR0SetLargeBumpRight"
                
                    
            End Select
        End If
    End If

    If Action = 1 Or Action = 2 Then
        ' redisplay values
        Dim count As Integer
        Dim temp
        For count = 1 To 25
        
        Next

        DlgText "HL3", "HL3 X: " & CStr(getvar(1003)) & " Y: " & CStr(getvar(1023))
        DlgText "HL2", "HL2 X: " & CStr(getvar(1002)) & " Y: " & CStr(getvar(1022))
        DlgText "HL1", "HL1 X: " & CStr(getvar(1001)) & " Y: " & CStr(getvar(1021))
        DlgText "HL0", "HL0 X: " & CStr(getvar(1000)) & " Y: " & CStr(getvar(1020))
        DlgText "HR3", "HR3 X: " & CStr(getvar(1013)) & " Y: " & CStr(getvar(1033))
        DlgText "HR2", "HR2 X: " & CStr(getvar(1012)) & " Y: " & CStr(getvar(1032))
        DlgText "HR1", "HR1 X: " & CStr(getvar(1011)) & " Y: " & CStr(getvar(1031))
        DlgText "HR0", "HR0 X: " & CStr(getvar(1010)) & " Y: " & CStr(getvar(1030))        
    End If
    
    DlgText "lastAction", lastAction

End Function



Function dialogMain( ControlID$, Action%, SuppValue%)

    Dim count As Integer
    dialogMain = 1
    lastAction = "Welcome"
    
    If Action = 2 Then
        If ControlID$ = "Ok" Or ControlID$ = "Cancel" Then
            dialogMain = 0
            currentDialog = currentDialogIsNone
        Else
            'MsgBox(ControlID$)
            Select Case ControlID$
                Case "btnResetCountFeeder50"
                    SetVar (50, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder50 FR25)"
                Case "btnResetCountFeeder49"
                    SetVar (49, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder49 FR24"
                Case "btnResetCountFeeder48"
                    SetVar (48, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder48 FR23"
                Case "btnResetCountFeeder47"
                    SetVar (47, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder47 FR22"
                Case "btnResetCountFeeder46"
                    SetVar (46, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder46 FR21"
                Case "btnResetCountFeeder45"
                    SetVar (45, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder45 FR20"
                Case "btnResetCountFeeder44"
                    SetVar (44, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder44 FR19"
                Case "btnResetCountFeeder43"
                    SetVar (43, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder43 FR18"
                Case "btnResetCountFeeder42"
                    SetVar (42, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder42 FR17"
                Case "btnResetCountFeeder41"
                    SetVar (41, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder41 FR16"
                Case "btnResetCountFeeder40"
                    SetVar (40, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder40 FR15"
                Case "btnResetCountFeeder39"
                    SetVar (39, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder39 FR14"
                Case "btnResetCountFeeder38"
                    SetVar (38, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder38 FR13"
                Case "btnResetCountFeeder37"
                    SetVar (37, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder37 FR12"
                Case "btnResetCountFeeder36"
                    SetVar (36, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder36 FR11"
                Case "btnResetCountFeeder35"
                    SetVar (35, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder35 FR10"
                Case "btnResetCountFeeder34"
                    SetVar (34, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder34 FR09"
                Case "btnResetCountFeeder33"
                    SetVar (33, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder33 FR08"
                Case "btnResetCountFeeder32"
                    SetVar (32, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder32 FR07"
                Case "btnResetCountFeeder31"
                    SetVar (31, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder31 FR06"
                Case "btnResetCountFeeder30"
                    SetVar (30, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder30 FR05"
                Case "btnResetCountFeeder29"
                    SetVar (29, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder29 FR04"
                Case "btnResetCountFeeder28"
                    SetVar (28, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder28 FR03"
                Case "btnResetCountFeeder27"
                    SetVar (27, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder27 FR02"
                Case "btnResetCountFeeder26"
                    SetVar (26, DlgText("frnewcount"))
                    lastAction = "btnResetCountFeeder26 FR01"
                Case "btnResetCountFeeder25"
                    SetVar (25, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder25 FL25"
                Case "btnResetCountFeeder24"
                    SetVar (24, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder24 FL24"
                Case "btnResetCountFeeder23"
                    SetVar (23, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder23 FL23"
                Case "btnResetCountFeeder22"
                    SetVar (22, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder22 FL22"
                Case "btnResetCountFeeder21"
                    SetVar (21, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder21 FL21"
                Case "btnResetCountFeeder20"
                    SetVar (20, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder20 FL20"
                Case "btnResetCountFeeder19"
                    SetVar (19, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder19 FL19"
                Case "btnResetCountFeeder18"
                    SetVar (18, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder18 FL18"
                Case "btnResetCountFeeder17"
                    SetVar (17, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder17 FL17"
                Case "btnResetCountFeeder16"
                    SetVar (16, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder16 FL16"
                Case "btnResetCountFeeder15"
                    SetVar (15, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder15 FL15"
                Case "btnResetCountFeeder14"
                    SetVar (14, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder14 FL14"
                Case "btnResetCountFeeder13"
                    SetVar (13, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder13 FL13"
                Case "btnResetCountFeeder12"
                    SetVar (12, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder12 FL12"
                Case "btnResetCountFeeder11"
                    SetVar (11, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder11 FL11"
                Case "btnResetCountFeeder10"
                    SetVar (10, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder10 FL10"
                Case "btnResetCountFeeder9"
                    SetVar (09, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder9 FL09"
                Case "btnResetCountFeeder8"
                    SetVar (08, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder8 FL08"
                Case "btnResetCountFeeder7"
                    SetVar (07, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder7 FL07"
                Case "btnResetCountFeeder6"
                    SetVar (06, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder6 FL06"
                Case "btnResetCountFeeder5"
                    SetVar (05, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder5 FL05"
                Case "btnResetCountFeeder4"
                    SetVar (04, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder4 FL04"
                Case "btnResetCountFeeder3"
                    SetVar (03, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder3 FL03"
                Case "btnResetCountFeeder2"
                    SetVar (02, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder2 FL02"
                Case "btnResetCountFeeder1"
                    SetVar (01, DlgText("flnewcount"))
                    lastAction = "btnResetCountFeeder1 FL01"

                Case "btnInitHeadVars"
                    Code("M98 P1")
                    lastAction = "btnInitHeadVars"
                Case "btnInitFeederVars"
                    Code("M98 P2")
                    lastAction = "btnInitFeederVars"
                    
                Case "btnZeroFeeders"
                    For count = 1 To 50
                        SetVar (count, 0)
                    Next
                    lastAction = "btnZeroFeeders"
                    
                Case "btnGoG55Origin"
                    code("G0 G90 G55 X0 Y0")
                    lastAction = "btnGoG55Origin"
                Case "btnSetG55Origin"
                    SetG59OffSetToCurrentPosition(2)    ' G55 is G59 offset 2
                    lastAction = "btnSetG55Origin"
                Case "btnGoG55High"
                    code("G0 G90 G55 X70 Y275")
                    lastAction = "btnGoG55High"

                Case "btnGoG56Origin"
                    code("G0 G90 G56 X0 Y0")
                    lastAction = "btnGoG56Origin"
                Case "btnSetG56Origin"
                    SetG59OffSetToCurrentPosition(3)    ' G56 is G59 offset 3
                    lastAction = "btnSetG56Origin"
                Case "btnGoG57Origin"
                    code("G0 G90 G57 X0 Y0")
                    lastAction = "btnGoG57Origin"
                Case "btnSetG57Origin"
                    SetG59OffSetToCurrentPosition(4)    ' G57 is G59 offset 4
                    lastAction = "btnSetG57Origin"
                    
                Case "btnGoG58Origin"
                    code("G0 G90 G58 X0 Y0")
                    lastAction = "btnGoG58Origin"
                Case "btnSetG58Origin"
                    SetG59OffSetToCurrentPosition(5)    ' G57 is G59 offset 4
                    lastAction = "btnSetG58Origin"

                Case "btnGo0"
                    Code("G0 G59 P" & G59Rot0PCB1)
                    Code("X0 Y0")
                    lastAction = "btnGo0"
                Case "btnGo90"
                    Code("G0 G59 P" & G59Rot90PCB1)
                    Code("X0 Y0")
                    lastAction = "btnGo90"
                Case "btnGo180"
                    Code("G0 G59 P" & G59Rot180PCB1)
                    Code("X0 Y0")
                    lastAction = "btnGo180"
                Case "btnGo270"
                    Code("G0 G59 P" & G59Rot270PCB1)
                    Code("X0 Y0")
                    lastAction = "btnGo270"
                    
                Case "btnGo04mm"
                    Code("G0 G59 P" & G59Rot0PCB1)
                    Code("G90 X4 Y4")
                    lastAction = "btnGo04mm"
                Case "btnGo904mm"
                    Code("G0 G59 P" & G59Rot90PCB1)
                    Code("G90 X4 Y-4")
                    lastAction = "btnGo904mm"
                Case "btnGo1804mm"
                    Code("G0 G59 P" & G59Rot180PCB1)
                    Code("G90 X-4 Y-4")
                    WaitForMove
                    lastAction = "btnGo1804mm"
                Case "btnGo2704mm"
                    Code("G0 G59 P" & G59Rot270PCB1)
                    Code("G90 X-4 Y4")
                    lastAction = "btnGo2704mm"
                    
                Case "btnSet0"
                    SetG59OffSetToCurrentPosition(G59Rot0PCB1)
                    lastAction = "btnSet0"
                Case "btnSet90"
                    SetG59OffSetToCurrentPosition(G59Rot90PCB1)
                    lastAction = "btnSet90"
                Case "btnSet180"
                    SetG59OffSetToCurrentPosition(G59Rot180PCB1)
                    lastAction = "btnSet180"
                Case "btnSet270"
                    SetG59OffSetToCurrentPosition(G59Rot270PCB1)
                    lastAction = "btnSet270"
                    
                Case "btnSet04mm"
                    SetG59OffSetToCurrentPosition(G59Rot0PCB1)
                    Code("G0 G59 P" & G59Rot0PCB1)
                    Code("G91 X-4 Y-4")
                    WaitForMove
                    Code("G90")
                    SetG59OffSetToCurrentPosition(G59Rot0PCB1)
                    lastAction = "btnSet04mm"
                Case "btnSet904mm"
                    SetG59OffSetToCurrentPosition(G59Rot90PCB1)
                    Code("G0 G59 P" & G59Rot90PCB1)
                    Code("G91 X-4 Y4")
                    WaitForMove
                    Code("G90")
                    SetG59OffSetToCurrentPosition(G59Rot90PCB1)
                    lastAction = "btnSet904mm"
                Case "btnSet1804mm"
                    SetG59OffSetToCurrentPosition(G59Rot180PCB1)
                    Code("G0 G59 P" & G59Rot180PCB1)
                    Code("G91 X4 Y4")
                    WaitForMove
                    Code("G90")
                    SetG59OffSetToCurrentPosition(G59Rot180PCB1)
                    lastAction = "btnSet1804mm"
                Case "btnSet2704mm"
                    SetG59OffSetToCurrentPosition(G59Rot270PCB1)
                    Code("G0 G59 P" & G59Rot270PCB1)
                    Code("G91 X4 Y-4")
                    WaitForMove
                    Code("G90")
                    SetG59OffSetToCurrentPosition(G59Rot270PCB1)
                    lastAction = "btnSet2704mm"
                    
                Case "btnRun0"
                    setvar(2000, G59Rot0PCB1)
                    Code("M98 P0") 'Call PCB function
                    lastAction = "btnRun0"
                Case "btnRun90"
                    setvar(2000, G59Rot90PCB1)
                    Code("M98 P90") 'Call PCB function
                    lastAction = "btnRun90"
                Case "btnRun180"
                    setvar(2000, G59Rot180PCB1)
                    Code("M98 P180") 'Call PCB function
                    lastAction = "btnRun180"
                Case "btnRun270"
                    setvar(2000, G59Rot270PCB1)
                    Code("M98 P270") 'Call PCB function
                    lastAction = "btnRun270"
                
                Case "btnCalibrateFeeders"
                ' Sub menus
                    currentDialog = currentDialogIsCalibrateFeeders
                    dialogMain = 0
                Case "btnCalibrateHeads"
                ' Sub menus
                    currentDialog = currentDialogIsCalibrateHeads
                    dialogMain = 0
                    
                Case "btnBuzzerOff"
                    Code("M90001 P8")
                    Code("M90002")
                    lastAction = "btnBuzzerOff"
                    
                Case "btnBuzzerOn"
                    Code("M90001 P9")
                    Code("M90002")
                    lastAction = "btnBuzzerOn"
                    
                Case "btnVacuumOff"
                    Code("M90001 P10")
                    Code("M90002")
                    lastAction = "btnVacuumOff"
                    
                Case "btnVacuumOn"
                    Code("M90001 P11")
                    Code("M90002")
                    lastAction = "btnVacuumOn"

            End Select
        End If
    End If
    If Action = 1 Or Action = 2 Then
        ' redisplay values
        
        DlgText "flnewcount", 0
        DlgText "frnewcount", 0
            
        Dim temp
        Dim feederID
        For count = 1 To 50
            temp = GetVar(FeederGCodeBaseVarComponentsMax + count) - GetVar(count)
            DlgText "StatusFeeder" & count,CStr(GetVar(FeederGCodeBaseVarComponentsRequired + count)) + " of " + CStr(temp) & " : " & CStr(GetVar(FeederGCodeBaseVarComponentsMax + count)) & " - " & CStr(GetVar(count))
            DlgEnable "StatusFeeder" & count, 0
            
            DlgText "btnResetCountFeeder" & count, "Reset (" & CStr(GetVar(count)) & ")"

        Next
    End If
    
    DlgText "lastAction", lastAction

End Function
         
         
Sub SetG59OffSetToCurrentPosition(G59Offset As Integer)
    ' Set G59 offset to current position
    SetVar(G59BaseAddrX + (G59AddrIncrement * (G59Offset - 1)), GetParam("XMachine"))
    SetVar(G59BaseAddrY + (G59AddrIncrement * (G59Offset - 1)), GetParam("YMachine"))
    Code("G59 P" + G59Offset)
End Sub

Sub WaitForMove()
    While ismoving()
    sleep 100
    Wend
End Sub      

' Feeder functions
Sub GotoFeeder(feederID)
    If feederID >= 1 And feederID <= 26 Then
        Code("G56 G0 X[#" + CStr(FeederGCodeBaseVarX + feederID) + "] Y[#" + CStr(FeederGCodeBaseVarY + feederID) + "]")
    End If
    If feederID >= 26 And feederID <= 50 Then
        Code("G57 G0 X[#" + CStr(FeederGCodeBaseVarX + feederID) + "] Y[#" + CStr(FeederGCodeBaseVarY + feederID) + "]")
    End If
End Sub

Sub SetFeeder(feederID)
    If feederID >= 1 And feederID <= 26 Then
        Code("G56")
    End If
    If feederID >= 26 And feederID <= 50 Then
        Code("G57")
    End If
    Code("#" + CStr(FeederGCodeBaseVarX + feederID) + " = " & getparam("XDRO"))
    Code("#" + CStr(FeederGCodeBaseVarY + feederID) + " = " & getparam("YDRO"))
End Sub

'Head functions
Sub SetHead(origin, headID)
    Code(origin)
    Code("#" + CStr(HeadGCodeBaseVarX + headID) + " = " & getparam("XDRO"))
    Code("#" + CStr(HeadGCodeBaseVarY + headID) + " = " & getparam("YDRO"))
End Sub

Sub GoHead(origin, headID)
    Dim command
    command = origin + " G0 X[#" + CStr(HeadGCodeBaseVarX + headID) + "] Y[#" + CStr(HeadGCodeBaseVarY + headID) + "]"
    DlgText "debug1", command
    DlgText "debug2", ""
    DlgText "debug3", ""
    Code(command)
End Sub

' Small Bump pit functions
Sub GoSmallBumpLEFT(headID)
    strTemp = "G58 G0 X[#" + CStr(HeadGCodeBaseVarSmallBumpLeftX + headID) + "] Y" + CStr(getSmallBumpMidY(headID))
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub GoSmallBumpRight(headID)
    strTemp = "G58 G0 X[#" + CStr(HeadGCodeBaseVarSmallBumpRightX + headID) + "] Y" + CStr(getSmallBumpMidY(headID))
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub GoSmallBumpTop(headID As Integer)
    strTemp = "G58 G0 X" + CStr(getSmallBumpMidX(headID)) & "  Y[#" + CStr(HeadGCodeBaseVarSmallBumpTopY + headID) + "]"
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub GoSmallBumpBottom(headID As Integer)
    strTemp = "G58 G0 X" + CStr(getSmallBumpMidX(headID)) & "  Y[#" + CStr(HeadGCodeBaseVarSmallBumpBottomY + headID) + "]"
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub SetSmallBumpLeft(headID As Integer)
    strTemp = "#" + CStr(HeadGCodeBaseVarSmallBumpLeftX + headID) + " = " & getparam("XDRO")
    Code("G58")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub SetSmallBumpRight(headID As Integer)
    Code("G58")
    strTemp = "#" + CStr(HeadGCodeBaseVarSmallBumpRightX + headID) + " = " & getparam("XDRO")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub SetSmallBumpTop(headID As Integer)
    Code("G58")
    strTemp = "#" + CStr(HeadGCodeBaseVarSmallBumpTopY + headID) + " = " & getparam("YDRO")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub SetSmallBumpBottom(headID As Integer)
    strTemp = "#" + CStr(HeadGCodeBaseVarSmallBumpBottomY + headID) + " = " & getparam("YDRO")
    Code("G58")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub
 
' Large Bump pit functions
Sub GoLargeBumpLEFT(headID)
    strTemp = "G58 G0 X[#" + CStr(HeadGCodeBaseVarLargeBumpLeftX + headID) + "] Y" + CStr(getLargeBumpMidY(headID))
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub GoLargeBumpRight(headID)
    strTemp = "G58 G0 X[#" + CStr(HeadGCodeBaseVarLargeBumpRightX + headID) + "] Y" + CStr(getLargeBumpMidY(headID))
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub GoLargeBumpTop(headID As Integer)
    strTemp = "G58 G0 X" + CStr(getLargeBumpMidX(headID)) & "  Y[#" + CStr(HeadGCodeBaseVarLargeBumpTopY + headID) + "]"
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub GoLargeBumpBottom(headID As Integer)
    strTemp = "G58 G0 X" + CStr(getLargeBumpMidX(headID)) & "  Y[#" + CStr(HeadGCodeBaseVarLargeBumpBottomY + headID) + "]"
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub SetLargeBumpLeft(headID As Integer)
    strTemp = "#" + CStr(HeadGCodeBaseVarLargeBumpLeftX + headID) + " = " & getparam("XDRO")
    Code("G58")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub SetLargeBumpRight(headID As Integer)
    strTemp = "#" + CStr(HeadGCodeBaseVarLargeBumpRightX + headID) + " = " & getparam("XDRO")
    Code("G58")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub SetLargeBumpTop(headID As Integer)
    strTemp = "#" + CStr(HeadGCodeBaseVarLargeBumpTopY + headID) + " = " & getparam("YDRO")
    Code("G58")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub

Sub SetLargeBumpBottom(headID As Integer)
    strTemp = "#" + CStr(HeadGCodeBaseVarLargeBumpBottomY + headID) + " = " & getparam("YDRO")
    Code("G58")
    Code(strTemp)
    DlgText "Message", strtemp
End Sub


Function getSmallBumpMidY(headID)
    Dim topY, bottomY
    topY = GetVar(HeadGCodeBaseVarSmallBumpTopY + headID)
    bottomY = GetVar(HeadGCodeBaseVarSmallBumpBottomY + headID)
    getSmallBumpMidY = bottomY + ((topY - bottomY ) / 2 )
End Function

Function getSmallBumpMidX(headID)
    Dim leftX, rightX
    leftX = GetVar(HeadGCodeBaseVarSmallBumpLeftX + headID)
    rightX = GetVar(HeadGCodeBaseVarSmallBumpRightX + headID)
    getSmallBumpMidX = leftX + ((rightX - leftX ) / 2 )
End Function

Function getLargeBumpMidY(headID)
    Dim topY, bottomY
    topY = GetVar(HeadGCodeBaseVarLargeBumpTopY + headID)
    bottomY = GetVar(HeadGCodeBaseVarLargeBumpBottomY + headID)
    getLargeBumpMidY = bottomY + ((topY - bottomY ) / 2 )
End Function

Function getLargeBumpMidX(headID)
    Dim leftX, rightX
    leftX = GetVar(HeadGCodeBaseVarLargeBumpLeftX + headID)
    rightX = GetVar(HeadGCodeBaseVarLargeBumpRightX + headID)
    getLargeBumpMidX = leftX + ((rightX - leftX ) / 2 )
End Function