3 #include "kernel_id.h"
\r
4 #include "ecrobot_interface.h"
\r
6 /* OSEK declarations */
\r
7 DeclareCounter(SysTimerCnt);
\r
8 DeclareTask(EventDispatcher);
\r
9 DeclareTask(EventHandler);
\r
10 DeclareTask(IdleTask);
\r
11 DeclareEvent(TouchSensorOnEvent);
\r
12 DeclareEvent(TouchSensorOffEvent);
\r
14 /* below macro enables run-time Bluetooth connection */
\r
15 #define RUNTIME_CONNECTION
\r
17 /* slave device's Bluetooth Device Address (this has to be modified for your NXT) */
\r
18 const U8 bd_addr[7] = {0x00, 0x16, 0x53, 0x04, 0xF1, 0xB3, 0x00};
\r
20 /* LEJOS OSEK hooks */
\r
21 void ecrobot_device_initialize()
\r
23 #ifndef RUNTIME_CONNECTION
\r
24 ecrobot_init_bt_master(bd_addr, "LEJOS-OSEK");
\r
27 void ecrobot_device_terminate()
\r
29 ecrobot_term_bt_connection();
\r
32 /* LEJOS OSEK hook to be invoked from an ISR in category 2 */
\r
33 void user_1ms_isr_type2(void)
\r
37 ercd = SignalCounter(SysTimerCnt); /* Increment OSEK Alarm Counter */
\r
44 /* EventDispatcher executed every 5ms */
\r
45 TASK(EventDispatcher)
\r
47 static U8 bt_receive_buf[32];
\r
48 static U8 TouchSensorStatus_old = 0;
\r
49 U8 TouchSensorStatus;
\r
51 /* read packet data from the slave device */
\r
52 ecrobot_read_bt_packet(bt_receive_buf, 32);
\r
53 if (bt_receive_buf[0] == 1)
\r
55 ecrobot_set_motor_speed(NXT_PORT_B, 100);
\r
59 ecrobot_set_motor_speed(NXT_PORT_B, 0);
\r
62 TouchSensorStatus = ecrobot_get_touch_sensor(NXT_PORT_S4);
\r
63 if (TouchSensorStatus == 1 && TouchSensorStatus_old == 0)
\r
65 /* Send a Touch Sensor ON Event to the Handler */
\r
66 SetEvent(EventHandler, TouchSensorOnEvent);
\r
68 else if (TouchSensorStatus == 0 && TouchSensorStatus_old == 1)
\r
70 /* Send a Touch Sensor OFF Event to the Handler */
\r
71 SetEvent(EventHandler, TouchSensorOffEvent);
\r
73 TouchSensorStatus_old = TouchSensorStatus;
\r
78 /* EventHandler executed by OSEK Events */
\r
81 static U8 bt_send_buf[32];
\r
85 WaitEvent(TouchSensorOnEvent); /* Task is in waiting status until the Event comes */
\r
86 ClearEvent(TouchSensorOnEvent);
\r
87 /* send packet data to the slave device */
\r
89 ecrobot_send_bt_packet(bt_send_buf, 32);
\r
91 WaitEvent(TouchSensorOffEvent); /* Task is in waiting status until the Event comes */
\r
92 ClearEvent(TouchSensorOffEvent);
\r
93 /* send packet data to the slave device */
\r
95 ecrobot_send_bt_packet(bt_send_buf, 32);
\r
104 static SINT bt_status = BT_NO_INIT;
\r
108 #ifdef RUNTIME_CONNECTION
\r
109 ecrobot_init_bt_master(bd_addr, "LEJOS-OSEK");
\r
112 if (ecrobot_get_bt_status() == BT_STREAM && bt_status != BT_STREAM)
\r
115 display_goto_xy(0, 0);
\r
116 display_string("[BT]");
\r
119 bt_status = ecrobot_get_bt_status();
\r