1
1
import * as React from "react" ;
2
- import { Box } from "@mui/material" ;
3
- import "./css/GUICanvas.css" ;
4
-
5
- const CarJunction = ( props ) => {
6
-
7
- const [ carPose , setCarPose ] = React . useState ( null )
8
- const canvasRef = React . useRef ( null )
2
+ import PropTypes from "prop-types" ;
3
+ import { drawImage } from "./helpers/showImagesFollowRoad" ;
4
+ import noImage from "../../assets/img/noImage.png" ;
9
5
6
+ import "./css/GUICanvas.css"
7
+ function CarJunction ( props ) {
10
8
React . useEffect ( ( ) => {
11
9
console . log ( "TestShowScreen subscribing to ['update'] events" ) ;
12
10
const callback = ( message ) => {
13
- if ( message . data . update . image ) {
14
- const image = JSON . parse ( message . data . update . image )
15
- if ( image . image ) {
16
- let canvas = document . getElementById ( "canvas" ) ;
17
- //Parse encoded image data and decode it
18
- function decode_utf8 ( s ) {
19
- return decodeURIComponent ( escape ( s ) )
20
- }
21
- var source = decode_utf8 ( image . image ) ,
22
- shape = image . shape ;
11
+ console . log ( message ) ;
23
12
24
- if ( source !== "" ) {
25
- canvas . src = "data:image/png;base64," + source ;
26
- canvas . width = shape [ 1 ] ;
27
- canvas . height = shape [ 0 ] ;
28
- }
29
- }
30
- try {
31
- const pose = message . data . update . map
32
- setCarPose ( pose )
33
- } catch ( error ) {
34
-
35
- }
13
+ if ( message . data . update . image_front ) {
14
+ console . log ( "image_front" ) ;
15
+ drawImage ( message . data . update ) ;
36
16
}
37
-
17
+ // Send the ACK of the msg
38
18
window . RoboticsExerciseComponents . commsManager . send ( "gui" , "ack" ) ;
39
19
} ;
40
20
@@ -52,57 +32,16 @@ const CarJunction = (props) => {
52
32
} ;
53
33
} , [ ] ) ;
54
34
55
- React . useEffect ( ( ) => {
56
- const callback = ( message ) => {
57
- console . log ( message )
58
- if ( message . data . state === "application_running" ) {
59
- window . RoboticsExerciseComponents . commsManager . send ( "gui" , "start" ) ;
60
- } else if ( message . data . state === "paused" ) {
61
- window . RoboticsExerciseComponents . commsManager . send ( "gui" , "pause" ) ;
62
- } else if ( message . data . state === "tools_ready" ) {
63
- setCarPose ( null )
64
- }
65
- }
66
-
67
- window . RoboticsExerciseComponents . commsManager . subscribe (
68
- [ window . RoboticsExerciseComponents . commsManager . events . STATE_CHANGED ] ,
69
- callback
70
- ) ;
71
-
72
- return ( ) => {
73
- console . log ( "TestShowScreen unsubscribing from ['state-changed'] events" ) ;
74
- window . RoboticsExerciseComponents . commsManager . unsubscribe (
75
- [ window . RoboticsExerciseComponents . commsManager . events . STATE_CHANGED ] ,
76
- callback
77
- ) ;
78
- } ;
79
- } , [ ] )
80
-
81
35
return (
82
- < Box sx = { { height : "100%" , position : "relative" } } >
83
- < img ref = { canvasRef } className = { "exercise-canvas" } id = "canvas" > </ img >
84
- { carPose && (
85
- < div className = "overlay" style = { {
86
- position : 'absolute' ,
87
- bottom : '20px' ,
88
- left : '20px' ,
89
- backgroundColor : 'rgba(0,0,0,0.7)' ,
90
- color : 'white' ,
91
- padding : '10px' ,
92
- borderRadius : '5px' ,
93
- fontFamily : 'monospace' ,
94
- fontSize : '16px'
95
- } } >
96
- Position: { carPose }
97
- </ div >
98
- ) }
99
- </ Box >
36
+ < div style = { { display : "flex" , width : "100%" , height : "100%" , justifyContent : "center" , alignItems : "center" } } >
37
+ < img className = "image" id = "gui_canvas_front" style = { { maxWidth : "100%" , maxHeight : "100%" } }
38
+ src = { noImage } />
39
+ </ div >
100
40
) ;
101
- } ;
41
+ }
102
42
103
- CarJunction . defaultProps = {
104
- width : 800 ,
105
- height : 600 ,
43
+ CarJunction . propTypes = {
44
+ circuit : PropTypes . string ,
106
45
} ;
107
46
108
- export default CarJunction
47
+ export default CarJunction ;
0 commit comments