'---------------------------------------------------------------------
' Copyright  2006 Raymund Sarmiento
'
' Permission is hereby granted to use this Software for any purpose
' including combining with commercial products, creating derivative
' works, and redistribution of source or binary code, without
' limitation or consideration. Any redistributed copies of this
' Software must include the above Copyright Notice.
'
' THIS SOFTWARE IS PROVIDED "AS IS". THE AUTHOR OF THIS CODE MAKES NO
' WARRANTIES REGARDING THIS SOFTWARE, EXPRESS OR IMPLIED, AS TO ITS
' SUITABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
'---------------------------------------------------------------------
'
'
' Written:  07-Oct-06   Raymund Sarmiento
'
' Edits:
'
' When      Who     What
' --------- ---     --------------------------------------------------
' 24-Oct-03 rcs     Initial edit for EQ Mount Driver Function Prototype
'---------------------------------------------------------------------
'
'
'  SYNOPSIS:
'
'  This is a demonstration of a EQ6/ATLAS/EQG direct stepper motor control access
'  using the EQCONTRL.DLL driver code.
'
'  File EQCONTROL.bas contains all the function prototypes of all subroutines
'  encoded in the EQCONTRL.dll
'
'  The EQ6CONTRL.DLL simplifies execution of the Mount controller board stepper
'  commands.
'
'  The mount circuitry needs to be modified for this test program to work.
'  Circuit details can be found at http://www.freewebs.com/eq6mod/
'

'  DISCLAIMER:

'  You can use the information on this site COMPLETELY AT YOUR OWN RISK.
'  The modification steps and other information on this site is provided
'  to you "AS IS" and WITHOUT WARRANTY OF ANY KIND, express, statutory,
'  implied or otherwise, including without limitation any warranty of
'  merchantability or fitness for any particular or intended purpose.
'  In no event the author will  be liable for any direct, indirect,
'  punitive, special, incidental or consequential damages or loss of any
'  kind whether or not the author  has been advised of the possibility
'  of such loss.

'  WARNING:

'  Circuit modifications implemented on your setup could invalidate
'  any warranty that you may have with your product. Use this
'  information at your own risk. The modifications involve direct
'  access to the stepper motor controls of your mount. Any "mis-control"
'  or "mis-command"  / "invalid parameter" or "garbage" data sent to the
'  mount could accidentally activate the stepper motors and allow it to
'  rotate "freely" damaging any equipment connected to your mount.
'  It is also possible that any garbage or invalid data sent to the mount
'  could cause its firmware to generate mis-steps pulse sequences to the
'  motors causing it to overheat. Make sure that you perform the
'  modifications and testing while there is no physical "load" or
'  dangling wires on your mount. Be sure to disconnect the power once
'  this event happens or if you notice any unusual sound coming from
'  the motor assembly.
'
'  CREDITS:
'
'  Portions of the information on this code should be attributed
'  to Mr. John Archbold from his initial observations and analysis
'  of the interface circuits and of the ASCII data stream between
'  the Hand Controller (HC) and the Go To Controller.
'


' ************* Mount initialization ***************

' Intialize Mount / Driver
Public Declare Function EQ_Ini(BytVal COMPORT As String, ByVal baud As Long, ByVal timeout As Long, ByVal retry As Long) As Long

' Initialize RA/DEC Motors
Public Declare Function EQ_InitMotors(ByVal RA as Long, ByVal DEC As Long) As Long

' Disconnect Driver
Public Declare Function EQ_End() As Long

' ************* Mount and Driver Parameters *************

' Get mount stepping info
Public Declare Function EQ_GetTotal360microstep(ByVal value As Long) As Long

' Mount version
Public Declare Function EQ_GetMountVersion() As Long

' Mount/Driver state
Public Declare Function EQ_GetMountStatus() As Long

' ************* Motor Parameters *************

' Get Motor microstep position
Public Declare Function EQ_GetMotorValues(ByVal motor_id As Long) As Long

' Get Motor status
Public Declare Function EQ_GetMotorStatus(ByVal motor_id  As Long) As Long

' Set Motor microstep position (counter value set only)
Public Declare Function EQ_SetMotorValues(ByVal motor_id As Long, ByVal motor_val As Long) As Long

' ************* Slewing and GOTO *************

' Move motor based on microstep values
Public Declare Function EQ_StartMoveMotor(ByVal motor_id As Long, ByVal hemisphere As Long, ByVal direction As Long, ByVal steps As Long, ByVal stepslowdown As Long) As Long

' Slew Motor based on specified slew speed 
Public Declare Function EQ_Slew(ByVal motor_id As Long, ByVal hemisphere As Long, ByVal direction As Long, ByVal rate As Long) As Long

' ************* Tracking *************

' Move motor at specified tracking speed
Public Declare Function EQ_StartRATrack(ByVal trackrate As Long, ByVal hemisphere As Long, ByVal direction As Long) As Long

' Customized speed (for orbital data)
Public Declare Function EQ_SendCustomTrackRate(ByVal motor_id As Long, ByVal trackrate As Long, ByVal trackoffset As Long, ByVal trackdir As Long, ByVal hemisphere As Long, ByVal direction As Long) As Long

' ************* Guiding / PEC *************

' Initiate speed change (guiding)
Public Declare Function EQ_SendGuideRate(ByVal motor_id As Long, ByVal trackrate As Long, ByVal guiderate As Long, ByVal guidedir As Long, ByVal hemisphere As Long, ByVal direction As Long) As Long

' Customized guide speed
Public Declare Function EQ_SendCustomTrackRate(ByVal motor_id As Long, ByVal trackrate As Long, ByVal trackoffset As Long, ByVal trackdir As Long, ByVal hemisphere As Long, ByVal direction As Long) As Long

' Autoguider port speed
Public Declare Function EQ_SetAutoguiderPortRate Lib "EQCONTRL" (ByVal motor_id As Long, ByVal guideportrate As Long) As Long


' ************* Motor Stop *************
Public Declare Function EQ_MotorStop(ByVal value As Long) As Long


