-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.cpp | 31 | ||||
-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.h | 8 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/device.cc | 5 |
3 files changed, 36 insertions, 8 deletions
diff --git a/noncore/net/opietooth/applet/bluezapplet.cpp b/noncore/net/opietooth/applet/bluezapplet.cpp index f7774f0..127b0af 100644 --- a/noncore/net/opietooth/applet/bluezapplet.cpp +++ b/noncore/net/opietooth/applet/bluezapplet.cpp | |||
@@ -64,42 +64,44 @@ namespace OpieTooth { | |||
64 | bluezOnPixmap = Resource::loadPixmap( "bluetoothapplet/bluezon" ); | 64 | bluezOnPixmap = Resource::loadPixmap( "bluetoothapplet/bluezon" ); |
65 | bluezOffPixmap = Resource::loadPixmap( "bluetoothapplet/bluezoff" ); | 65 | bluezOffPixmap = Resource::loadPixmap( "bluetoothapplet/bluezoff" ); |
66 | bluezDiscoveryOnPixmap = Resource::loadPixmap( "bluetoothapplet/magglass.png" ); | 66 | bluezDiscoveryOnPixmap = Resource::loadPixmap( "bluetoothapplet/magglass.png" ); |
67 | #else | 67 | #else |
68 | bluezOnPixmap = OResource::loadImage( "bluetoothapplet/bluezon", OResource::SmallIcon ); | 68 | bluezOnPixmap = OResource::loadImage( "bluetoothapplet/bluezon", OResource::SmallIcon ); |
69 | bluezOffPixmap = OResource::loadImage( "bluetoothapplet/bluezoff", Opie::Core::OResource::SmallIcon ); | 69 | bluezOffPixmap = OResource::loadImage( "bluetoothapplet/bluezoff", Opie::Core::OResource::SmallIcon ); |
70 | bluezDiscoveryOnPixmap = OResource::loadImage( "bluetoothapplet/bluezondiscovery", Opie::Core::OResource::SmallIcon ); | 70 | bluezDiscoveryOnPixmap = OResource::loadImage( "bluetoothapplet/bluezondiscovery", Opie::Core::OResource::SmallIcon ); |
71 | #endif | 71 | #endif |
72 | startTimer(2000); | 72 | startTimer(2000); |
73 | btDevice = 0; | 73 | btDevice = 0; |
74 | btManager = 0; | 74 | btManager = 0; |
75 | bluezactive = false; | 75 | bluezactive = false; |
76 | bluezDiscoveryActive = false; | 76 | bluezDiscoveryActive = false; |
77 | doListDevice = false; | 77 | doListDevice = false; |
78 | isScanning = false; | 78 | isScanning = false; |
79 | m_wasOn = false; | 79 | m_wasOn = false; |
80 | m_sync = false; | ||
80 | 81 | ||
81 | // TODO: determine whether this channel has to be closed at destruction time. | 82 | // TODO: determine whether this channel has to be closed at destruction time. |
82 | QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this ); | 83 | QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this ); |
83 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), | 84 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), |
84 | this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); | 85 | this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); |
85 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); | 86 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); |
86 | } | 87 | } |
87 | 88 | ||
88 | BluezApplet::~BluezApplet() { | 89 | BluezApplet::~BluezApplet() { |
89 | if ( btDevice ) { | 90 | if ( btDevice ) { |
91 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); | ||
90 | delete btDevice; | 92 | delete btDevice; |
91 | } | 93 | } |
92 | if ( btManager ) { | 94 | if ( btManager ) { |
93 | delete btManager; | 95 | delete btManager; |
94 | } | 96 | } |
95 | } | 97 | } |
96 | 98 | ||
97 | int BluezApplet::position() | 99 | int BluezApplet::position() |
98 | { | 100 | { |
99 | return 6; | 101 | return 6; |
100 | } | 102 | } |
101 | 103 | ||
102 | 104 | ||
103 | bool BluezApplet::checkBluezStatus() { | 105 | bool BluezApplet::checkBluezStatus() { |
104 | if (btDevice) { | 106 | if (btDevice) { |
105 | if (btDevice->isLoaded() ) { | 107 | if (btDevice->isLoaded() ) { |
@@ -114,48 +116,46 @@ namespace OpieTooth { | |||
114 | return false; | 116 | return false; |
115 | } | 117 | } |
116 | } | 118 | } |
117 | 119 | ||
118 | int BluezApplet::setBluezStatus(int c, bool sync) { | 120 | int BluezApplet::setBluezStatus(int c, bool sync) { |
119 | 121 | ||
120 | if ( c == 1 ) { | 122 | if ( c == 1 ) { |
121 | switch ( ODevice::inst()->model() ) { | 123 | switch ( ODevice::inst()->model() ) { |
122 | case Model_iPAQ_H39xx: | 124 | case Model_iPAQ_H39xx: |
123 | btDevice = new Device( "/dev/tts/1", "bcsp", "921600" ); | 125 | btDevice = new Device( "/dev/tts/1", "bcsp", "921600" ); |
124 | break; | 126 | break; |
125 | 127 | ||
126 | case Model_iPAQ_H5xxx: | 128 | case Model_iPAQ_H5xxx: |
127 | btDevice = new Device( "/dev/tts/1", "any", "921600" ); | 129 | btDevice = new Device( "/dev/tts/1", "any", "921600" ); |
128 | break; | 130 | break; |
129 | 131 | ||
130 | #ifndef OPIE120 | 132 | #if OPIE_VERSION >= 102010 |
131 | case Model_MyPal_716: | 133 | case Model_MyPal_716: |
132 | btDevice = new Device( "/dev/ttyS1", "bcsp", "921600" ); | 134 | btDevice = new Device( "/dev/ttyS1", "bcsp", "921600" ); |
133 | break; | 135 | break; |
134 | #endif | 136 | #endif |
135 | 137 | ||
136 | default: | 138 | default: |
137 | btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" ); | 139 | btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" ); |
138 | break; | 140 | break; |
139 | } | 141 | } |
140 | if (sync) { | 142 | m_sync = sync; |
141 | ::system("/etc/init.d/bluetooth start >/dev/null 2>/dev/null"); | 143 | connect(btDevice, SIGNAL(device(const QString&, bool)), |
142 | } else { | 144 | this, SLOT(slotDevice(const QString&, bool))); |
143 | QCopEnvelope e("QPE/System", "execute(QString)"); | 145 | |
144 | e << QString("/etc/init.d/bluetooth start"); | ||
145 | } | ||
146 | } else { | 146 | } else { |
147 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); | 147 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); |
148 | if ( btManager ) { | 148 | if ( btManager ) { |
149 | delete btManager; | 149 | delete btManager; |
150 | btManager = 0; | 150 | btManager = 0; |
151 | } | 151 | } |
152 | if ( btDevice ) { | 152 | if ( btDevice ) { |
153 | delete btDevice; | 153 | delete btDevice; |
154 | btDevice = 0; | 154 | btDevice = 0; |
155 | } | 155 | } |
156 | } | 156 | } |
157 | return 0; | 157 | return 0; |
158 | } | 158 | } |
159 | 159 | ||
160 | int BluezApplet::checkBluezDiscoveryStatus() { | 160 | int BluezApplet::checkBluezDiscoveryStatus() { |
161 | return isScanning; | 161 | return isScanning; |
@@ -323,21 +323,38 @@ namespace OpieTooth { | |||
323 | p.drawPixmap( 0, -1, bluezOnPixmap ); | 323 | p.drawPixmap( 0, -1, bluezOnPixmap ); |
324 | #else | 324 | #else |
325 | p.drawPixmap( 0, 0, bluezOnPixmap ); | 325 | p.drawPixmap( 0, 0, bluezOnPixmap ); |
326 | #endif | 326 | #endif |
327 | } else { | 327 | } else { |
328 | #if OPIE_VERSION < 102010 | 328 | #if OPIE_VERSION < 102010 |
329 | p.drawPixmap( 0, -1, bluezOffPixmap ); | 329 | p.drawPixmap( 0, -1, bluezOffPixmap ); |
330 | #else | 330 | #else |
331 | p.drawPixmap( 0, 0, bluezOffPixmap ); | 331 | p.drawPixmap( 0, 0, bluezOffPixmap ); |
332 | #endif | 332 | #endif |
333 | } | 333 | } |
334 | 334 | ||
335 | if (bluezDiscoveryActive) { | 335 | if (bluezDiscoveryActive) { |
336 | p.drawPixmap( 0, 0, bluezDiscoveryOnPixmap ); | 336 | p.drawPixmap( 0, 0, bluezDiscoveryOnPixmap ); |
337 | } | 337 | } |
338 | } | 338 | } |
339 | /** | ||
340 | * Reacts on device up | ||
341 | * @param name device name | ||
342 | * @param up if device was brought up | ||
343 | */ | ||
344 | void BluezApplet::slotDevice(const QString& name, bool up) | ||
345 | { | ||
346 | if (!up) | ||
347 | return; | ||
348 | odebug << name << " is up" << oendl; | ||
349 | if (m_sync) { | ||
350 | ::system("/etc/init.d/bluetooth start >/dev/null 2>/dev/null"); | ||
351 | } else { | ||
352 | QCopEnvelope e("QPE/System", "execute(QString)"); | ||
353 | e << QString("/etc/init.d/bluetooth start"); | ||
354 | } | ||
355 | } | ||
339 | }; | 356 | }; |
340 | 357 | ||
341 | 358 | ||
342 | EXPORT_OPIE_APPLET_v1( OpieTooth::BluezApplet ) | 359 | EXPORT_OPIE_APPLET_v1( OpieTooth::BluezApplet ) |
343 | 360 | ||
diff --git a/noncore/net/opietooth/applet/bluezapplet.h b/noncore/net/opietooth/applet/bluezapplet.h index 1937934..b79ed5b 100644 --- a/noncore/net/opietooth/applet/bluezapplet.h +++ b/noncore/net/opietooth/applet/bluezapplet.h | |||
@@ -57,25 +57,33 @@ public slots: | |||
57 | bool checkBluezStatus(); | 57 | bool checkBluezStatus(); |
58 | int setBluezStatus(int, bool sync = false); | 58 | int setBluezStatus(int, bool sync = false); |
59 | int checkBluezDiscoveryStatus(); | 59 | int checkBluezDiscoveryStatus(); |
60 | int setBluezDiscoveryStatus(int); | 60 | int setBluezDiscoveryStatus(int); |
61 | 61 | ||
62 | private: | 62 | private: |
63 | Device* btDevice; | 63 | Device* btDevice; |
64 | Manager *btManager; | 64 | Manager *btManager; |
65 | QPixmap bluezOnPixmap; | 65 | QPixmap bluezOnPixmap; |
66 | QPixmap bluezOffPixmap; | 66 | QPixmap bluezOffPixmap; |
67 | QPixmap bluezDiscoveryOnPixmap; | 67 | QPixmap bluezDiscoveryOnPixmap; |
68 | bool bluezactive; | 68 | bool bluezactive; |
69 | bool bluezDiscoveryActive; | 69 | bool bluezDiscoveryActive; |
70 | bool doListDevice; //If I have to list devices after bringing BT up? | 70 | bool doListDevice; //If I have to list devices after bringing BT up? |
71 | bool isScanning; //If I'm scanning devices | 71 | bool isScanning; //If I'm scanning devices |
72 | bool m_wasOn; //If BT was started by menu? | 72 | bool m_wasOn; //If BT was started by menu? |
73 | protected: | ||
74 | bool m_sync; //If we have to bring BT synchronously | ||
73 | 75 | ||
74 | private slots: | 76 | private slots: |
75 | void slotMessage( const QCString& , const QByteArray& ); | 77 | void slotMessage( const QCString& , const QByteArray& ); |
78 | /** | ||
79 | * Reacts on device up | ||
80 | * @param name device name | ||
81 | * @param up if device was brought up | ||
82 | */ | ||
83 | void slotDevice(const QString&, bool); | ||
76 | }; | 84 | }; |
77 | }; | 85 | }; |
78 | 86 | ||
79 | 87 | ||
80 | #endif | 88 | #endif |
81 | 89 | ||
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc index 2f04d46..88d4cf9 100644 --- a/noncore/net/opietooth/lib/device.cc +++ b/noncore/net/opietooth/lib/device.cc | |||
@@ -113,57 +113,60 @@ void Device::slotExited( OProcess* proc) | |||
113 | owarn << "prcess exited" << oendl; | 113 | owarn << "prcess exited" << oendl; |
114 | if(proc== m_process ){ | 114 | if(proc== m_process ){ |
115 | owarn << "proc == m_process" << oendl; | 115 | owarn << "proc == m_process" << oendl; |
116 | if( m_process->normalExit() ){ // normal exit | 116 | if( m_process->normalExit() ){ // normal exit |
117 | owarn << "normalExit" << oendl; | 117 | owarn << "normalExit" << oendl; |
118 | int ret = m_process->exitStatus(); | 118 | int ret = m_process->exitStatus(); |
119 | if( ret == 0 ){ // attached | 119 | if( ret == 0 ){ // attached |
120 | owarn << "attached" << oendl; | 120 | owarn << "attached" << oendl; |
121 | owarn << "Output: " << m_output.data() << oendl; | 121 | owarn << "Output: " << m_output.data() << oendl; |
122 | pid = parsePid( m_output ); | 122 | pid = parsePid( m_output ); |
123 | owarn << "Pid = " << pid << oendl; | 123 | owarn << "Pid = " << pid << oendl; |
124 | // now hciconfig hci0 up ( determine hciX FIXME) | 124 | // now hciconfig hci0 up ( determine hciX FIXME) |
125 | // and call hciconfig hci0 up | 125 | // and call hciconfig hci0 up |
126 | // FIXME hardcoded to hci0 now :( | 126 | // FIXME hardcoded to hci0 now :( |
127 | m_hci = new OProcess( ); | 127 | m_hci = new OProcess( ); |
128 | *m_hci << "hciconfig"; | 128 | *m_hci << "hciconfig"; |
129 | *m_hci << "hci0 up"; | 129 | *m_hci << "hci0"; |
130 | *m_hci << "up"; | ||
130 | connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), | 131 | connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), |
131 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); | 132 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); |
132 | if(!m_hci->start() ){ | 133 | if(!m_hci->start() ){ |
133 | owarn << "could not start" << oendl; | 134 | owarn << "could not start" << oendl; |
134 | m_attached = false; | 135 | m_attached = false; |
135 | emit device("hci0", false ); | 136 | emit device("hci0", false ); |
136 | } | 137 | } |
137 | }else{ | 138 | }else{ |
138 | owarn << "crass" << oendl; | 139 | owarn << "crass" << oendl; |
139 | m_attached = false; | 140 | m_attached = false; |
140 | emit device("hci0", false ); | 141 | emit device("hci0", false ); |
141 | 142 | ||
142 | } | 143 | } |
143 | } | 144 | } |
144 | delete m_process; | 145 | delete m_process; |
145 | m_process = 0; | 146 | m_process = 0; |
146 | }else if(proc== m_hci ){ | 147 | }else if(proc== m_hci ){ |
147 | owarn << "M HCI exited" << oendl; | 148 | owarn << "M HCI exited" << oendl; |
148 | if( m_hci->normalExit() ){ | 149 | if( m_hci->normalExit() ){ |
149 | owarn << "normal exit" << oendl; | 150 | owarn << "normal exit" << oendl; |
150 | int ret = m_hci->exitStatus(); | 151 | int ret = m_hci->exitStatus(); |
151 | if( ret == 0 ){ | 152 | if( ret == 0 ){ |
152 | owarn << "attached really really attached" << oendl; | 153 | owarn << "attached really really attached" << oendl; |
153 | m_attached = true; | 154 | m_attached = true; |
155 | //Wait for a device to be brought up | ||
156 | ::sleep(1); | ||
154 | emit device("hci0", true ); | 157 | emit device("hci0", true ); |
155 | }else{ | 158 | }else{ |
156 | owarn << "failed" << oendl; | 159 | owarn << "failed" << oendl; |
157 | emit device("hci0", false ); | 160 | emit device("hci0", false ); |
158 | m_attached = false; | 161 | m_attached = false; |
159 | } | 162 | } |
160 | }// normal exit | 163 | }// normal exit |
161 | delete m_hci; | 164 | delete m_hci; |
162 | m_hci = 0; | 165 | m_hci = 0; |
163 | } | 166 | } |
164 | } | 167 | } |
165 | void Device::slotStdOut(OProcess* proc, char* chars, int len) | 168 | void Device::slotStdOut(OProcess* proc, char* chars, int len) |
166 | { | 169 | { |
167 | owarn << "std out" << oendl; | 170 | owarn << "std out" << oendl; |
168 | if( len <1 ){ | 171 | if( len <1 ){ |
169 | owarn << "len < 1 " << oendl; | 172 | owarn << "len < 1 " << oendl; |