@@ -324,14 +324,17 @@ function onDeviceReady() {
324324 else { this . _hideContent ( ) ; }
325325 } ,
326326 setContent : function ( obj ) {
327- //alert(JSON.stringify(obj));
328327 if ( ! this . _infoContentContainer ) return ;
328+ if ( ( obj . validPos & 7 ) != 7 ) { return ; } // check if we have lat, lon, alt in data; if not no update of display
329+
329330 if ( obj . type == null ) obj . type = "RS41" ; // TODO fix in plugin
330331 distance = "" ;
331- distance = L . latLng ( obj ) . distanceTo ( L . latLng ( mypos ) )
332- if ( distance > 9999 ) { distance = "d=" + ( 0.001 * distance ) . toFixed ( 1 ) + "km" ; }
333- else if ( distance > 99 ) { distance = "d=" + distance . toFixed ( 0 ) + "m" ; }
334- else { distance = "d=" + distance . toFixed ( 1 ) + "m" ; }
332+ try {
333+ distance = L . latLng ( obj ) . distanceTo ( L . latLng ( mypos ) )
334+ if ( distance > 9999 ) { distance = "d=" + ( 0.001 * distance ) . toFixed ( 1 ) + "km" ; }
335+ else if ( distance > 99 ) { distance = "d=" + distance . toFixed ( 0 ) + "m" ; }
336+ else { distance = "d=" + distance . toFixed ( 1 ) + "m" ; }
337+ } catch ( error ) { }
335338 sym = "<span class=\"lifenessinfo\">⬤ </span>" ;
336339 l1 = "<table class=\"infotable\"><tr><td class=\"infotd\">" + sym + obj . type + "</td><td class=\"infotdr\">" + obj . ser + "</td></tr></table>" ;
337340 // normal layout
@@ -416,6 +419,7 @@ function onDeviceReady() {
416419 }
417420 if ( obj . hdop < 0 ) { // GPS fix lost
418421 } else {
422+ console . log ( "updateMybos..updateMybos...." )
419423 var p0 = L . latLng ( obj ) ;
420424 var p1 = L . latLng ( this . _currentObj ) ;
421425 var b = p0 . bearingTo ( p1 ) ;
@@ -499,6 +503,8 @@ function onDeviceReady() {
499503 } ) ;
500504 ready = 1 ;
501505 RdzWx . start ( "testarg" , callBack ) ;
506+ console . log ( "Starting setupTTGO" ) ;
507+ setupTTGOconfig ( ) ;
502508 setInterval ( periodicStatusCheck , 1000 ) ;
503509
504510 // just for testing
@@ -781,8 +787,8 @@ function update(obj) {
781787 return ;
782788 }
783789
784- // position update
785- //console.log("Pos update: "+JSON.stringify(obj));
790+ // sonde data update
791+ //console.log("Sonde update: "+JSON.stringify(obj));
786792 if ( obj . egmdiff && obj . alt ) { obj . alt -= obj . egmdiff ; }
787793 infobox . setContent ( obj ) ;
788794 infobox . setStatus ( obj . res ) ;
@@ -802,7 +808,7 @@ function update(obj) {
802808 markers [ obj . id ] = marker ;
803809 lastMarker = marker
804810 } else {
805- console . log ( "pos update: No valid update: " + JSON . stringify ( obj ) ) ;
811+ // console.log("pos update: No valid update: "+JSON.stringify(obj));
806812 }
807813 return ;
808814 }
@@ -923,3 +929,70 @@ function reqauth() {
923929 }
924930 xhr . send ( 'submitted=1&username=DL9RDZ&password=ct1jzmhr&Submit=Login' ) ;
925931}
932+
933+
934+ // Handling settings for TTGO address
935+ // Must be called after RdzWx has been initialized, as it calls updateDiscovery(...)
936+ function setupTTGOconfig ( ) {
937+ // Restore state on application start
938+ const savedState = localStorage . getItem ( 'connectionState' ) || 'auto' ;
939+ const savedAddr = localStorage . getItem ( 'manualAddress' ) || 'rdzsonde.local' ;
940+ console . log ( "updating to " + savedState + ", " + savedAddr ) ;
941+ updateTTGOaddr ( savedState , savedAddr )
942+
943+ if ( savedState === 'auto' ) {
944+ document . getElementById ( 'auto-discovery' ) . checked = true ;
945+ document . getElementById ( 'manual-address' ) . style . display = 'none' ;
946+ } else if ( savedState === 'manual' ) {
947+ document . getElementById ( 'manual-entry' ) . checked = true ;
948+ document . getElementById ( 'manual-address' ) . style . display = 'block' ;
949+ }
950+
951+ if ( savedAddr ) {
952+ document . getElementById ( 'manual-address' ) . value = savedAddr ;
953+ }
954+
955+ // Save state and call updateTTGOaddr on changes
956+ const radioButtons = document . querySelectorAll ( 'input[name="connection"]' ) ;
957+ const manualAddressInput = document . getElementById ( 'manual-address' ) ;
958+
959+ radioButtons . forEach ( radio => {
960+ radio . addEventListener ( 'change' , ( ) => {
961+ const state = document . getElementById ( 'auto-discovery' ) . checked ? 'auto' : 'manual'
962+ const addr = manualAddressInput . value ;
963+ localStorage . setItem ( 'connectionState' , state ) ;
964+ if ( state === 'manual' ) {
965+ manualAddressInput . style . display = 'block' ;
966+ } else {
967+ manualAddressInput . style . display = 'none' ;
968+ }
969+ updateTTGOaddr ( state , addr ) ;
970+ } ) ;
971+ } ) ;
972+
973+ manualAddressInput . addEventListener ( 'blur' , ( ) => {
974+ if ( document . getElementById ( 'manual-entry' ) . checked ) {
975+ const addr = manualAddressInput . value ;
976+ localStorage . setItem ( 'manualAddress' , addr ) ;
977+ updateTTGOaddr ( 'manual' , addr ) ;
978+ }
979+ } ) ;
980+
981+ manualAddressInput . addEventListener ( 'keypress' , ( e ) => {
982+ if ( e . key === 'Enter' ) {
983+ manualAddressInput . blur ( ) ; // Trigger the blur event
984+ }
985+ } ) ;
986+ } ;
987+
988+ // Placeholder for your custom function
989+ function updateTTGOaddr ( state , addr ) {
990+ console . log ( 'State:' , state , 'Address:' , addr ) ;
991+ RdzWx . mdnsUpdateDiscovery ( state , addr , function ( ) { } )
992+ // Implement your custom logic here
993+ }
994+
995+
996+
997+
998+
0 commit comments