⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bluetoothpn.cxx

📁 linux系统下的关于蓝牙模块的源代码!十分的经典的程序!
💻 CXX
📖 第 1 页 / 共 2 页
字号:
//// BluePN.cxx// This file contains code that implements an fltk-based Bluetooth// Piconet Neighborhood.  What a user will see is a window with a tree// view that locates every Bluetooth-enabled device.  Each bluetooth// device will be queried for services and attributes for those services// using SDP.  This UI is tied to the Axis Bluetooth stack simply by// ioctl() calls.//// This UI was created by a combination of fluid generated window and menu// design + the Fl_Toggle_Tree widget.//// Created By: Marcus Smith// Date: 2/8/2001//// Copyright (C) 2001 RidgeRun Inc.//#include "BluetoothPN.h"#include <stdlib.h>#include <string.h>#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <termios.h>#include <sys/ioctl.h>//// Some bluetooth defines necessary to talk to the Axis Bluetooth stack//#define BT_CONTROL_TTY "/dev/ttyBTC"#define MAX_BT_DEVICES 10#define BT_ADDRESS_SIZE 6//// Include some xpm icons.  The bluetooth xpm was created by taking the bluetooth// icon from www.bluetooth.com and shrinking via gimp.#include <FL/bluetooth.xpm>#include <FL/file_small.xpm>//// The new version of BTNeighborhood support a dialog box indicating that the ioctl()// is in process.  Since HTINQUIRY and SDP client take time, this indication helps// the user think something is actually happening.//#include <pthread.h>//// Bluetooth include files//#include <linux/bluetooth/btcommon.h>//// These global variables are used to track the pthread spawned by // BTNeighborhood:btScanForBluetoothDevices() and to track the open// ttyBTC device.//static int bt_cfd = -1;static pthread_t pthread;//// Callbacks generated by Fluid.  These callbacks drive the menu bar // interaction with the user.//inline void BTNeighborhood::cb_btFileMenuCloseItem_i(Fl_Menu_*, void*) {  btMainWindow->hide();exit(0);}void BTNeighborhood::cb_btFileMenuCloseItem(Fl_Menu_* o, void* v) {  ((BTNeighborhood*)(o->parent()->user_data()))->cb_btFileMenuCloseItem_i(o,v);}inline void BTNeighborhood::cb_btViewMenuRefreshItem_i(Fl_Menu_*, void*) {  btScanForBluetoothDevices();}void BTNeighborhood::cb_btViewMenuRefreshItem(Fl_Menu_* o, void* v) {  ((BTNeighborhood*)(o->parent()->user_data()))->cb_btViewMenuRefreshItem_i(o,v);}inline void BTNeighborhood::cb_btHelpMenuAboutItem_i(Fl_Menu_*, void*) {  btHelpMenuAboutItemWindow->show();}void BTNeighborhood::cb_btHelpMenuAboutItem(Fl_Menu_* o, void* v) {  ((BTNeighborhood*)(o->parent()->user_data()))->cb_btHelpMenuAboutItem_i(o,v);}//// Menu bar definition.  Generated by Fluid//Fl_Menu_Item BTNeighborhood::menu_btMainMenuBar[] = { {"File", 0,  0, 0, 64, 0, 0, 14, 0}, {"Close", 0x40078,  (Fl_Callback*)BTNeighborhood::cb_btFileMenuCloseItem, 0, 0, 0, 0, 14, 0}, {0}, {"View", 0,  0, 0, 64, 0, 0, 14, 0}, {"Refresh", 0x40072,  (Fl_Callback*)BTNeighborhood::cb_btViewMenuRefreshItem, 0, 0, 0, 0, 14, 0}, {0}, {"Help", 0,  0, 0, 64, 0, 0, 14, 0}, {"About", 0x40061,  (Fl_Callback*)BTNeighborhood::cb_btHelpMenuAboutItem, 0, 0, 0, 0, 14, 0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}};//// Menu item definitions.  Generated by Fluid//Fl_Menu_Item* BTNeighborhood::btFileMenu = BTNeighborhood::menu_btMainMenuBar + 0;Fl_Menu_Item* BTNeighborhood::btFileMenuCloseItem = BTNeighborhood::menu_btMainMenuBar + 1;Fl_Menu_Item* BTNeighborhood::btViewMenu = BTNeighborhood::menu_btMainMenuBar + 3;Fl_Menu_Item* BTNeighborhood::btViewMenuRefreshItem = BTNeighborhood::menu_btMainMenuBar + 4;Fl_Menu_Item* BTNeighborhood::btHelpMenu = BTNeighborhood::menu_btMainMenuBar + 6;Fl_Menu_Item* BTNeighborhood::btHelpMenuAboutItem = BTNeighborhood::menu_btMainMenuBar + 7;//// Help and Action window callback functions.  Most of these callbacks attach to// widgets on help windows and information dialog boxes.//inline void BTNeighborhood::cb_btHelpMenuAboutItemWindowOKButton_i(Fl_Return_Button*, void*) {  btHelpMenuAboutItemWindow->hide();}void BTNeighborhood::cb_btHelpMenuAboutItemWindowOKButton(Fl_Return_Button* o, void* v) {  ((BTNeighborhood*)(o->parent()->user_data()))->cb_btHelpMenuAboutItemWindowOKButton_i(o,v);}inline void BTNeighborhood::cb_OK_i(Fl_Button*, void*) {  btErrorCantFindBTDriverWindow->hide();}void BTNeighborhood::cb_OK(Fl_Button* o, void* v) {  ((BTNeighborhood*)(o->parent()->user_data()))->cb_OK_i(o,v);}inline void BTNeighborhood::cb_OK1_i(Fl_Button*, void*) {  btErrorHCIInquiry->hide();}void BTNeighborhood::cb_OK1(Fl_Button* o, void* v) {  ((BTNeighborhood*)(o->parent()->user_data()))->cb_OK1_i(o,v);}//// This callback function is called whenever the user highlights// something in the toggle tree view.//voidcb_test(Fl_Widget* widget, void*) {  Fl_Toggle_Tree* tree = (Fl_Toggle_Tree*) widget;  printf("state: %d\n", tree->state());  if (tree->selected())    printf("current=%s\n", tree->selected()->label());  else {    int i;    // if selected()==0 then we have a multiple select    printf("MULTIPLE:\n");    Fl_Toggle_Node* s;    while ((s = tree->selection()))      printf(" selected=%s\n", s->label());    int n = tree->selection_count();    printf("%d selections:\n", n);    for (i = 0; i < n; i++) {      s = tree->selection(i);      printf(" %d %s\n", i, s->label());    }    for (i = n - 1; i >= 0; i--) {      s = tree->selection(i);      printf(" %d %s\n", i, s->label());    }  }}//// Start of the BTNeighborhood class implementation//BTNeighborhood::BTNeighborhood() {   Fl_Window* w;   //   // Start of the main window definition.   //   {      //      // Start the main window out small, thereby accomodating smaller screens.  Overall      // the window can be resized.      //      Fl_Window* o = btMainWindow = new Fl_Window(240, 320, "Bluetooth Piconet Neighborhood");      w = o;      o->labeltype(FL_NORMAL_LABEL);      o->user_data((void*)(this));      {          //         // Menu bar definition.  Same width as the main window         //         Fl_Menu_Bar* o = btMainMenuBar = new Fl_Menu_Bar(0, 0, 240, 25);         o->menu(menu_btMainMenuBar);      }  // End of menu bar definition      //      // Setup a scroll bar and add valuable attributes      // The scroll bars will have initial height and width matching      // the window.  The type will be set to BOTH, thereby enabling the      // fltk system to remove any scroll bar that is not useful (i.e.      // the window is already larger than the scroll area).      //      scrollWidgetV = new Fl_Scroll(0, btMainMenuBar->h(), 240, 320 - (btMainMenuBar->h()));      scrollWidgetV->type(Fl_Scroll::BOTH);      scrollWidgetV->box(FL_THIN_DOWN_FRAME);      //      // Construct a Fl_Toggle_Tree.  This tree will be populated with the number      // of bluetooth addresses found in a query.  We pick a large width, like 1280,      // so the horizontal scroll area will be large, thereby accomodating large      // window areas.      //      treeWidget = new Fl_Toggle_Tree(0, 0, 1280-(scrollWidgetV->scrollbar.w()), 10);      //      // End the scroll bar placement.  The tree widget is a child of the scroll bar.      // This is done so the scroll bar can manage the tree area.      //      scrollWidgetV->end();      //      // Add a callback to the tree widget.  This is so we can be informed in any state change.      // We may not care, but it is good to at least to be notified.      //      treeWidget->callback(cb_test);      //      // Define some bitmaps to use as icons on the tree view.  For our purposes, we probably      // want the top-level icons to be bluetooth related.        //      bluetoothIcon = new Fl_Pixmap(bluetooth_xpm);      fileSmall = new Fl_Pixmap(file_small);      //      // End the main window definition.  Set the resize control of the main window to be      // the area of the toggle tree widget.      //      o->end();      o->resizable(treeWidget);   }  // End of main window definition

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -