C Language Development Kit/Functions/ComIdle
From OptiWiki
| Description | Starts or exits a Bluetooth low power mode. | ||||||||||||||
| Syntax | int com_idle(int state, int arg); | ||||||||||||||
| Arguments | State is the type of low-power mode that will be selected. See table and remarks for more information.
int state The arg parameter depends on the value for state. The following options are defined:
int arg
| ||||||||||||||
| Returns | All functions return OK, but the EXIT_HOLD_CHECK function returns -1 when the
terminal is still in hold mode. | ||||||||||||||
| Remarks | Although described in the Bluetooth specification, not all Bluetooth devices support all the above modes. Some devices only initiate, but do not accept when the terminal tries to initiate.
Bluetooth connection modes from high to low power: Active or full speed mode. In Active mode the terminal actively participates on the channel. The Master (Server) schedules the traffic demands of the terminal. It supports regular data transmission from Master to and from terminal to keep the terminal synchronized to the channel. Active terminal listen to master of terminal packets.
| ||||||||||||||
| Example | // // Example application to show some of the OPL9724, OPL9712 // bluetooth functions // // The application connect to bluetooth host. // Then scan barcode and after that directly transmit // barcode to the host. // #include <stdio.h> #include "lib.h" #define BCR_MAX 50 #define COM_USED COM3 // SPP Connect port void keybeep( void ) { sound( TSHORT, VMEDIUM, SHIGH, 0); } void okbeep( void ) { sound( TSTANDARD, VMEDIUM, SHIGH, SMEDIUM, SHIGH, 0); } void errbeep( void ) { sound( TLONG, VMEDIUM, SLOW, SMEDIUM, SHIGH, 0); } int waitkey( void ) { int c; while( ( c = getchar()) == EOF) idle(); keybeep(); // make the beeping sound return c; } int check_connection( void ) { int result; // // Check if the bluetooth device is still connected // for(;;) { result = blt_is_connected(); switch( result ) { case NG: // // Connection can not be determined at // the moment we have to wait a little while. // delay(5); break; default: return result; // return TRUE or FALSE } } } int ScanBarcode( char* string, int min_length, int max_length) { static int fActive; static char barcode_buffer[ BCR_MAX ]; int key; struct barcode code; code.min = min_length; code.max = max_length; code.text = barcode_buffer; if( !fActive ) { com_idle( EXIT_SNIFF, 0 ); fActive = TRUE; gotoxy(0,3); printf("Active..."); } starttimer( 600 ); // wait 12 seconds before powersaving mode while( readbarcode( ) != OK ) { scannerpower( SINGLE, 300 ); if( kbhit() ) { resetkey(); starttimer( 600 ); // wait 12 seconds before powersaving mode if( !fActive ) com_idle( EXIT_SNIFF, 0 ); fActive = TRUE; gotoxy(0,3); printf("Active..."); } // // Check if the OPL is still connected to the PC // if( check_connection() == FALSE ) return ERROR; if( scanneroff() && fActive && endtimer()) { com_idle( SNIFF, 100 ); fActive = FALSE; gotoxy(0,3); printf("Sniff... "); } idle(); } strcpy( string, barcode_buffer ); return( OK ); } int transmit_barcode( char* barcode ) { char* ptr; static char transm_string[ 40 + 2 + 1 ]; strcpy( transm_string, barcode ); strcat( transm_string, "\r\n"); ptr = transm_string; while( *ptr ) { if( putcom( *ptr ) == ERROR ) return ERROR; ptr++; } return OK; } void main( void ) { static char barcode[ 40 + 2+1 ]; static char msg[40+25]; static int scanned_barcode; autopowerdown( ON, 1000 ); // 20 seconds systemsetting("SZ"); // 115200 baud systemsetting("7G"); // show charging indication LED scanned_barcode = FALSE; cursor( NOWRAP ); setfont( LARGE_FONT, NULL ); // // Set bluetooth name (max. 18 characters) // SetBltLocalName("Ex OPL-9724" ); // // The main application loop. // for(;;) { printf("\f%s\nSPP con. to\n %s\npress a key", GetBltLocalName(), GetBltAddress()); waitkey(); for(;;) { printf("\fConnecting..."); // // Open the comport with SPP // if( comopen( COM_USED ) != 0 ) { printf("\fError open\nSPP port\n\npress a key"); waitkey(); continue; } break; } printf("\fConnected... "); for(;;) { if( check_connection() == FALSE ) { printf("\fconn. lost\nget closer\nto BT station\npress a key"); waitkey(); break; } if( scanned_barcode ) { // // A barcode was previously scanned but could not be transmitted // if( transmit_barcode( barcode ) == OK ) scanned_barcode = FALSE; else break; // connection failed printf("\fConnected... "); } memset( barcode, '\0', sizeof( barcode )); gotoxy(0,1); printf("Scan barcode."); // // Scan barcode // if( ScanBarcode( barcode, 1, 40 ) == ERROR) continue; okbeep(); gotoxy(0,2); printf("%-14.14s",barcode ); scanned_barcode = TRUE; // // Transmit the barcode // if( scanned_barcode && transmit_barcode( barcode ) == OK ) scanned_barcode = FALSE; } // // Close the SPP port to make reconnection is possible // comclose( COM_USED ); } } |
