Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion k3ng_rotator_controller/k3ng_rotator_controller.ino
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,13 @@ byte current_az_speed_voltage = 0;
#endif //GPS_MIRROR_PORT
#endif //defined(FEATURE_GPS)

#if defined(FEATURE_EL_POSITION_LCH)
HardwareSerial * lch_port;
char lchbuffer[30];
int lchbufferIndex = 0;
float lchreading = 0.0;
#endif //defined(FEATURE_LCH)

#if defined(FEATURE_MOON_TRACKING) || defined(FEATURE_SUN_TRACKING) || defined(FEATURE_CLOCK) || defined(FEATURE_GPS) || defined(FEATURE_REMOTE_UNIT_SLAVE) || defined(OPTION_DISPLAY_ALT_HHMM_CLOCK_AND_MAIDENHEAD) || defined(OPTION_DISPLAY_CONSTANT_HHMMSS_CLOCK_AND_MAIDENHEAD)
double latitude = DEFAULT_LATITUDE;
double longitude = DEFAULT_LONGITUDE;
Expand Down Expand Up @@ -2789,7 +2796,20 @@ void check_serial(){

}
#endif // defined(FEATURE_MASTER_WITH_SERIAL_SLAVE)

#ifdef FEATURE_EL_POSITION_LCH
if (lch_port->available()) {
char ch = lch_port->read();
if( ch == '\r')
{
lchbuffer[ lchbufferIndex ] = 0; // terminate the string with a 0
lchbufferIndex = 0; // reset the index ready for another string;

lchreading = atof (lchbuffer);
}
else
lchbuffer[ lchbufferIndex++ ] = ch; // add the character into the buffer
}
#endif // FEATURE_EL_POSITION_LCH

#ifdef FEATURE_GPS
#if defined(OPTION_DONT_READ_GPS_PORT_AS_OFTEN)
Expand Down Expand Up @@ -5336,7 +5356,15 @@ void read_elevation(byte force_read){
elevation = 0;
}
#endif // FEATURE_EL_POSITION_POTENTIOMETER
#ifdef FEATURE_EL_POSITION_LCH

elevation = lchreading*10;
#ifdef FEATURE_ELEVATION_CORRECTION
elevation = (correct_elevation(elevation / (float) HEADING_MULTIPLIER) * HEADING_MULTIPLIER);
#endif // FEATURE_ELEVATION_CORRECTION
elevation = elevation + (configuration.elevation_offset * HEADING_MULTIPLIER);

#endif // FEATURE_EL_POSITION_LCH

#ifdef FEATURE_EL_POSITION_ROTARY_ENCODER
static byte el_position_encoder_state = 0;
Expand Down Expand Up @@ -6675,6 +6703,18 @@ void initialize_serial(){
#endif //GPS_MIRROR_PORT
#endif //FEATURE_GPS

#ifdef FEATURE_EL_POSITION_LCH
lch_port = LCH_PORT_MAPPED_TO;
lch_port->begin(LCH_PORT_BAUD_RATE);
//sets default settings (filters, etc) and sets autoupdate (device just pushes data without asking it)
lch_port->write("str0100\n"); //sets autopudate speed to 0.1sec
lch_port->write("setcasc\n"); //this activates auto push
//lch_port->write("setflt1\n"); //sets device filter to 0.125Hz
//lch_port->write("stpcasc\n");
//lch_port->write("setcasc\n");
lch_port->flush();
#endif //FEATURE_lch

} /* initialize_serial */


Expand Down Expand Up @@ -9306,6 +9346,10 @@ void port_flush(){

#if defined(FEATURE_MASTER_WITH_SERIAL_SLAVE)
remote_unit_port->flush();
#endif

#if defined(FEATURE_EL_POSITION_LCH)
lch_port->flush();
#endif

#if defined(GPS_PORT_MAPPED_TO) && defined(FEATURE_GPS)
Expand Down
1 change: 1 addition & 0 deletions k3ng_rotator_controller/rotator_features.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
// #define FEATURE_EL_POSITION_INCREMENTAL_ENCODER
// #define FEATURE_EL_POSITION_MEMSIC_2125
// #define FEATURE_EL_POSITION_A2_ABSOLUTE_ENCODER
#define FEATURE_EL_POSITION_LCH

// If you are using an Adafruit, Yourduino, RFRobot, YWRobot, or SainSmart display, you must also change the feature setting in rotator_k3ngdisplay.h!!!!
// #define FEATURE_4_BIT_LCD_DISPLAY // Uncomment for classic 4 bit LCD display (most common)
Expand Down
2 changes: 2 additions & 0 deletions k3ng_rotator_controller/rotator_settings.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ You can tweak these, but read the online documentation!
#define REMOTE_UNIT_PORT_BAUD_RATE 9600
#define GPS_PORT_BAUD_RATE 9600
#define GPS_MIRROR_PORT_BAUD_RATE 9600
#define LCH_PORT_BAUD_RATE 9600
#define LCH_PORT_MAPPED_TO &Serial1 // change this line to map the LCH-360 sensor port
#define CONTROL_PORT_MAPPED_TO &Serial // change this line to map the control port to a different serial port (Serial1, Serial2, etc.)
//#define REMOTE_PORT_MAPPED_TO &Serial1 // change this line to map the remote_unit port to a different serial port
#define GPS_PORT_MAPPED_TO &Serial2 // change this line to map the GPS port to a different serial port
Expand Down
114 changes: 114 additions & 0 deletions lch360_emulator/lch360_emulator.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@

#include <SerialCommand.h>

SerialCommand sCmd; // The SerialCommand object
int delayauto = 1000;
String output = "+181.010";
boolean automa = true ;
int val = 0;

//float val3 = 0.0;s
float r;
void setup() {


// put your setup code here, to run once:
Serial.begin(9600); // set up Serial library at 9600 bps
while (! Serial);
sCmd.addCommand("get-360", print_angle); // prints angle to serial
sCmd.addCommand("str0100", set_delay_100ms); // sets auto print delay to 100ms
sCmd.addCommand("str1000", set_delay_1000ms); // sets auto print delay to 1000ms
sCmd.addCommand("setcasc", setauto); // set auto print on
sCmd.addCommand("stpcasc", stopauto); // stop auto print
sCmd.setDefaultHandler(unrecognized); // Handler for command that isn't matched (says "What?")
Serial.println("LCH-360 emulator");
Serial.println("get-360 gives onetime readings, setcasc gives reading every 0.1 sec (set by str0100),stpcasc stops ");
}

void loop() {

// put your main code here, to run repeatedly:
sCmd.readSerial();
if (automa)
{
Serial.println(output);
delay(delayauto);
}
val = analogRead(5);
//val3 = 360/1024;
float val2 = 0.0;
val2 = ((float)val*((float)360/(float)1024))-(float)180;
delay(delayauto/10);
char buf[16];

r = sprintf(buf, "%04d", val2);
String str2 = String(val2, 3);

// creating somewhat similar output as sensor, hax hax
String outout = String();
//Serial.println(sizeof(str2));
//Serial.println(str2.length());
//Serial.println(str2);
//char outout[7] = "+000.000";
//Serial.println(sizeof(outout));
if (val2 < 0){
outout += "-";
str2.remove(0,1);
//if
}
else
{
outout += "+";
}
if (8-str2.length()==4){
outout += "000";
}
if (8-str2.length()==3){
outout += "00";
}
if (8-str2.length()==2){
outout += "0";
}

outout += str2;
output = outout;
//Serial.println(outout);

//Serial.println(str2);
// now print the string inside of 'buf'
//Serial.println(buf);
//Serial.println(val);
//Serial.println(val2);

//Serial.println(val3);
//String output = String(analogRead(5), DEC);

}
void print_angle() {
Serial.println(output);
//digitalWrite(arduinoLED, HIGH);
}
void set_delay_100ms() {
Serial.println("OK");
delayauto = 100;
//digitalWrite(arduinoLED, HIGH);
}
void set_delay_1000ms() {
Serial.println("OK");
delayauto = 1000;
//digitalWrite(arduinoLED, HIGH);
}
void setauto() {
Serial.println("OK");
automa = true;
//digitalWrite(arduinoLED, HIGH);
}
void stopauto() {
Serial.println("OK");
automa = false;
//digitalWrite(arduinoLED, HIGH);
}
void unrecognized(const char *command) {
Serial.println("What?");
}