@@ -50,29 +50,77 @@ const char led_OFF[768] = "\n"
5050                          " /_____________________________________________//\n " 
5151                          " `---------------------------------------------'\n " 
5252
53+ using  namespace  client ; 
54+ 
55+ static  bool  isBrowser;
56+ [[cheerp::genericjs]] HTMLElement *ledDisplay;
57+ 
5358/* ******************************************************************************
5459 * Function 
5560 ******************************************************************************/  
56- static  void  Led_MsgHandler (service_t  *service, const  msg_t  *msg);
61+ static  void 
62+ Led_MsgHandler (service_t  *service, const  msg_t  *msg);
5763
5864void  clear_screen (void )
5965{
6066    //  clear the console
6167    printf (" \x1B [2J\x1B [H" 
6268}
6369
70+ [[cheerp::genericjs]] void  define_browser ()
71+ {
72+     __asm__ (" typeof %1 !== 'undefined'" " =r" " r" 
73+ }
74+ 
75+ [[cheerp::genericjs]] void  browser_init ()
76+ {
77+     client::HTMLElement *body = client::document.get_body ();
78+     HTMLElement *board        = document.createElement (" div" 
79+     board->setAttribute (" style" " width: 200px; height: 100px; background-color: #449944; display: flex; border-radius: 5%; border: 2px solid #000000;" 
80+     body->appendChild (board);
81+     HTMLElement *chip = document.createElement (" div" 
82+     chip->setAttribute (" style" " margin: 25px; width: 50px; height: 50px; background-color: #101010; border-radius: 10%; color: #FFFFFF; text-align: center; line-height: 50px; font-size: 15px; font-weight: bold;" 
83+     chip->appendChild (document.createTextNode (" MCU" 
84+     board->appendChild (chip);
85+     ledDisplay = document.createElement (" div" 
86+     ledDisplay->setAttribute (" style" " margin: 30px; width: 30px; height: 30px; background-color: #F0F0F0; border-radius: 50%" 
87+     board->appendChild (ledDisplay);
88+ }
89+ 
90+ [[cheerp::genericjs]] void  browser_display (bool  state)
91+ {
92+     if  (state)
93+     {
94+         ledDisplay->setAttribute (" style" " margin: 30px; width: 30px; height: 30px; background-color: #00ff00; border-radius: 50%" 
95+     }
96+     else 
97+     {
98+ 
99+         ledDisplay->setAttribute (" style" " margin: 30px; width: 30px; height: 30px; background-color: #F0F0F0; border-radius: 50%" 
100+     }
101+ }
102+ 
64103/* *****************************************************************************
65104 * @brief init must be call in project init 
66105 * @param None 
67106 * @return None 
68107 ******************************************************************************/  
69108PUBLIC void  Led_Init (void )
70109{
110+     define_browser ();
71111    revision_t  revision = {.major  = 1 , .minor  = 0 , .build  = 0 };
72112    Luos_CreateService (Led_MsgHandler, STATE_TYPE, " led" 
73113    clear_screen ();
74114    printf (" LED service running.\n\n " 
75-     printf (led_OFF);
115+     if  (isBrowser)
116+     {
117+         browser_init ();
118+         browser_display (false );
119+     }
120+     else 
121+     {
122+         printf (led_OFF);
123+     }
76124}
77125
78126/* *****************************************************************************
@@ -99,11 +147,25 @@ static void Led_MsgHandler(service_t *service, const msg_t *msg)
99147            printf (" LED service running.\n\n " 
100148            if  (Led_last_state == LED_OFF)
101149            {
102-                 printf (led_OFF);
150+                 if  (isBrowser)
151+                 {
152+                     browser_display (false );
153+                 }
154+                 else 
155+                 {
156+                     printf (led_OFF);
157+                 }
103158            }
104159            else  if  (Led_last_state == LED_ON)
105160            {
106-                 printf (led_ON);
161+                 if  (isBrowser)
162+                 {
163+                     browser_display (true );
164+                 }
165+                 else 
166+                 {
167+                     printf (led_ON);
168+                 }
107169            }
108170            else 
109171            {
0 commit comments