forked from bluerobotics/cockpit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
156 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export const COCKPIT_WIDGET_API_VERSION = '0.0.0' | ||
|
||
/** | ||
* Listens to updates for a specific datalake variable. | ||
* @param {string} variable - The name of the datalake variable to listen to. | ||
* @param {Function} callback - The function to call when the variable is updated. | ||
* @param {number} maxRateHz - The maximum rate (in Hz) at which updates should be received. Default is 10 Hz. | ||
*/ | ||
export function listenToDatalakeVariable(variable: string, callback: (data: any) => void, maxRateHz = 10): void { | ||
const message = { | ||
type: 'cockpit:listenToDatalakeVariables', | ||
variable: variable, | ||
maxRateHz: maxRateHz, | ||
} | ||
window.postMessage(message, window.parent.location.origin) | ||
|
||
window.addEventListener('message', function handler(event) { | ||
if (event.data.type === 'cockpit:datalakeVariableUpdate' && event.data.variable === variable) { | ||
callback(event.data) | ||
} | ||
}) | ||
} | ||
|
||
export default listenToDatalakeVariable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<style> | ||
body { | ||
background-color: white; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Datalake consumption test</h1> | ||
<div id="messageDisplay"></div> | ||
|
||
<script> | ||
function listenToDatalakeVariable(variable, callback, maxRateHz) { | ||
const message = { | ||
type: "cockpit:listenToDatalakeVariables", | ||
variable: variable, | ||
maxRateHz: 10, | ||
}; | ||
window.parent.postMessage(message, '*'); | ||
|
||
window.addEventListener('message', function handler(event) { | ||
if (event.data.type === "cockpit:datalakeVariable" && event.data.variable === variable) { | ||
callback(event.data.value); | ||
} | ||
}); | ||
} | ||
|
||
listenToDatalakeVariable('mainvehicle.attitude.yaw', function(data) { | ||
document.getElementById('messageDisplay').innerText = 'Yaw: ' + data; | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters