用蓝牙芯片CC2541/CC2540实现一个智能恒温箱
最近突然想自己做一个智能小冰箱玩一玩,于是决定动手试一试。
成品效果图
原材料
半导体制冷片一只
散热风扇
12V电源一台
智能恒温箱电路板
控制板的PCB图
原理图
供电部分原理图
制冷片控制部分原理图
蜂鸣器原理图
温度传感器原理图
GITHUB地址
完整代码以及电路图我放在了GITHUB上,欢迎下载哦。
https://github.com/dingbig/bluttooth_ice_box
控制部分源代码
/************************************************************************************************** Filename: simpleBLEPeripheral.c Revised: $Date: 2010-08-06 08:56:11 -0700 (Fri, 06 Aug 2010) $ Revision: $Revision: 23333 $ Description: This file contains the Simple BLE Peripheral sample application for use with the CC2540 Bluetooth Low Energy Protocol Stack. Copyright 2010 - 2014 Texas Instruments Incorporated. All rights reserved. IMPORTANT: Your use of this Software is limited to those specific rights granted under the terms of a software license agreement between the user who downloaded the software, his/her employer (which must be your employer) and Texas Instruments Incorporated (the "License"). You may not use this Software unless you agree to abide by the terms of the License. The License limits your use, and you acknowledge, that the Software may not be modified, copied or distributed unless embedded on a Texas Instruments microcontroller or used solely and exclusively in conjunction with a Texas Instruments radio frequency transceiver, which is integrated into your product. Other than for the foregoing purpose, you may not use, reproduce, copy, prepare derivative works of, modify, distribute, perform, display or sell this Software and/or its documentation for any purpose. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE PROVIDED 揂S IS?WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE, NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT, NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS. Should you have any questions regarding your right to use this Software, contact Texas Instruments Incorporated at www.TI.com. **************************************************************************************************/ /********************************************************************* * INCLUDES */ #include "bcomdef.h" #include "OSAL.h" #include "OSAL_PwrMgr.h" #include "OnBoard.h" #include "hal_adc.h" #include "hal_led.h" #include "hal_key.h" #include "hal_lcd.h" #include "gatt.h" #include "hci.h" #include "gapgattserver.h" #include "gattservapp.h" #include "devinfoservice.h" #include "simpleGATTprofile.h" #include "ds18b20.h" #include "stdio.h" #include "oled.h" #if defined( CC2540_MINIDK ) #include "simplekeys.h" #endif #include "peripheral.h" #include "gapbondmgr.h" #include "simpleBLEPeripheral.h" #if defined FEATURE_OAD #include "oad.h" #include "oad_target.h" #endif /********************************************************************* * MACROS */ /********************************************************************* * CONSTANTS */ // How often to perform periodic event #define SBP_PERIODIC_EVT_PERIOD 5000 #define SBP_TEMP_EVT_PERIOD 500 // What is the advertising interval when device is discoverable (units of 625us, 160=100ms) #define DEFAULT_ADVERTISING_INTERVAL 160 // Limited discoverable mode advertises for 30.72s, and then stops // General discoverable mode advertises indefinitely #if defined ( CC2540_MINIDK ) #define DEFAULT_DISCOVERABLE_MODE GAP_ADTYPE_FLAGS_LIMITED #else #define DEFAULT_DISCOVERABLE_MODE GAP_ADTYPE_FLAGS_GENERAL #endif // defined ( CC2540_MINIDK ) // Minimum connection interval (units of 1.25ms, 80=100ms) if automatic parameter update request is enabled #define DEFAULT_DESIRED_MIN_CONN_INTERVAL 80 // Maximum connection interval (units of 1.25ms, 800=1000ms) if automatic parameter update request is enabled #define DEFAULT_DESIRED_MAX_CONN_INTERVAL 800 // Slave latency to use if automatic parameter update request is enabled #define DEFAULT_DESIRED_SLAVE_LATENCY 0 // Supervision timeout value (units of 10ms, 1000=10s) if automatic parameter update request is enabled #define DEFAULT_DESIRED_CONN_TIMEOUT 1000 // Whether to enable automatic parameter update request when a connection is formed #define DEFAULT_ENABLE_UPDATE_REQUEST TRUE // Connection Pause Peripheral time value (in seconds) #define DEFAULT_CONN_PAUSE_PERIPHERAL 6 // Company Identifier: Texas Instruments Inc. (13) #define TI_COMPANY_ID 0x000D #define INVALID_CONNHANDLE 0xFFFF // Length of bd addr as a string #define B_ADDR_STR_LEN 15 /********************************************************************* * TYPEDEFS */ /********************************************************************* * GLOBAL VARIABLES */ /********************************************************************* * EXTERNAL VARIABLES */ /********************************************************************* * EXTERNAL FUNCTIONS */ /********************************************************************* * LOCAL VARIABLES */ static uint8 simpleBLEPeripheral_TaskID; // Task ID for internal task/event processing static gaprole_States_t gapProfileState = GAPROLE_INIT; // GAP - SCAN RSP data (max size = 31 bytes) static uint8 scanRspData[] = { // complete name 0x14, // length of this data GAP_ADTYPE_LOCAL_NAME_COMPLETE, 0x51, // 'Q' 0x69, // 'i' 0x6d, // 'm' 0x70, // 'p' 0x6c, // 'l' 0x65, // 'e' 0x42, // 'B' 0x4c, // 'L' 0x45, // 'E' 0x50, // 'P' 0x65, // 'e' 0x72, // 'r' 0x69, // 'i' 0x70, // 'p' 0x68, // 'h' 0x65, // 'e' 0x72, // 'r' 0x61, // 'a' 0x6c, // 'l' // connection interval range 0x05, // length of this data GAP_ADTYPE_SLAVE_CONN_INTERVAL_RANGE, LO_UINT16( DEFAULT_DESIRED_MIN_CONN_INTERVAL ), // 100ms HI_UINT16( DEFAULT_DESIRED_MIN_CONN_INTERVAL ), LO_UINT16( DEFAULT_DESIRED_MAX_CONN_INTERVAL ), // 1s HI_UINT16( DEFAULT_DESIRED_MAX_CONN_INTERVAL ), // Tx power level 0x02, // length of this data GAP_ADTYPE_POWER_LEVEL, // 0dBm }; // GAP - Advertisement data (max size = 31 bytes, though this is // best kept short to conserve power while advertisting) static uint8 advertData[] = { // Flags; this sets the device to use limited discoverable // mode (advertises for 30 seconds at a time) instead of general // discoverable mode (advertises indefinitely) 0x02, // length of this data GAP_ADTYPE_FLAGS, DEFAULT_DISCOVERABLE_MODE | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED, // service UUID, to notify central devices what services are included // in this peripheral 0x03, // length of this data GAP_ADTYPE_16BIT_MORE, // some of the UUID's, but not all LO_UINT16( SIMPLEPROFILE_SERV_UUID ), HI_UINT16( SIMPLEPROFILE_SERV_UUID ), }; // GAP GATT Attributes static uint8 attDeviceName[GAP_DEVICE_NAME_LEN] = "Simple BLE Peripheral"; /********************************************************************* * LOCAL FUNCTIONS */ static void simpleBLEPeripheral_ProcessOSALMsg( osal_event_hdr_t *pMsg ); static void simpleBLEPeripheral_ProcessGATTMsg( gattMsgEvent_t *pMsg ); static void peripheralStateNotificationCB( gaprole_States_t newState ); static void performPeriodicTask( void ); static void simpleProfileChangeCB( uint8 paramID ); #if defined( CC2540_MINIDK ) static void simpleBLEPeripheral_HandleKeys( uint8 shift, uint8 keys ); #endif #if (defined HAL_LCD) && (HAL_LCD == TRUE) static char *bdAddr2Str ( uint8 *pAddr ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) /********************************************************************* * PROFILE CALLBACKS */ // GAP Role Callbacks static gapRolesCBs_t simpleBLEPeripheral_PeripheralCBs = { peripheralStateNotificationCB, // Profile State Change Callbacks NULL // When a valid RSSI is read from controller (not used by application) }; // GAP Bond Manager Callbacks static gapBondCBs_t simpleBLEPeripheral_BondMgrCBs = { NULL, // Passcode callback (not used by application) NULL // Pairing / Bonding state Callback (not used by application) }; // Simple GATT Profile Callbacks static simpleProfileCBs_t simpleBLEPeripheral_SimpleProfileCBs = { simpleProfileChangeCB // Charactersitic value change callback }; /********************************************************************* * PUBLIC FUNCTIONS */ /********************************************************************* * @fn SimpleBLEPeripheral_Init * * @brief Initialization function for the Simple BLE Peripheral App Task. * This is called during initialization and should contain * any application specific initialization (ie. hardware * initialization/setup, table initialization, power up * notificaiton ... ). * * @param task_id - the ID assigned by OSAL. This ID should be * used to send messages and set timers. * * @return none */ void SimpleBLEPeripheral_Init( uint8 task_id ) { simpleBLEPeripheral_TaskID = task_id; osal_set_event(simpleBLEPeripheral_TaskID, SBP_START_TEMP_TIMER_EVT); // Setup the GAP VOID GAP_SetParamValue( TGAP_CONN_PAUSE_PERIPHERAL, DEFAULT_CONN_PAUSE_PERIPHERAL ); // Setup the GAP Peripheral Role Profile { #if defined( CC2540_MINIDK ) // For the CC2540DK-MINI keyfob, device doesn't start advertising until button is pressed uint8 initial_advertising_enable = FALSE; #else // For other hardware platforms, device starts advertising upon initialization uint8 initial_advertising_enable = TRUE; #endif // By setting this to zero, the device will go into the waiting state after // being discoverable for 30.72 second, and will not being advertising again // until the enabler is set back to TRUE uint16 gapRole_AdvertOffTime = ; uint8 enable_update_request = DEFAULT_ENABLE_UPDATE_REQUEST; uint16 desired_min_interval = DEFAULT_DESIRED_MIN_CONN_INTERVAL; uint16 desired_max_interval = DEFAULT_DESIRED_MAX_CONN_INTERVAL; uint16 desired_slave_latency = DEFAULT_DESIRED_SLAVE_LATENCY; uint16 desired_conn_timeout = DEFAULT_DESIRED_CONN_TIMEOUT; // Set the GAP Role Parameters GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &initial_advertising_enable ); GAPRole_SetParameter( GAPROLE_ADVERT_OFF_TIME, sizeof( uint16 ), &gapRole_AdvertOffTime ); GAPRole_SetParameter( GAPROLE_SCAN_RSP_DATA, sizeof ( scanRspData ), scanRspData ); GAPRole_SetParameter( GAPROLE_ADVERT_DATA, sizeof( advertData ), advertData ); GAPRole_SetParameter( GAPROLE_PARAM_UPDATE_ENABLE, sizeof( uint8 ), &enable_update_request ); GAPRole_SetParameter( GAPROLE_MIN_CONN_INTERVAL, sizeof( uint16 ), &desired_min_interval ); GAPRole_SetParameter( GAPROLE_MAX_CONN_INTERVAL, sizeof( uint16 ), &desired_max_interval ); GAPRole_SetParameter( GAPROLE_SLAVE_LATENCY, sizeof( uint16 ), &desired_slave_latency ); GAPRole_SetParameter( GAPROLE_TIMEOUT_MULTIPLIER, sizeof( uint16 ), &desired_conn_timeout ); } // Set the GAP Characteristics GGS_SetParameter( GGS_DEVICE_NAME_ATT, GAP_DEVICE_NAME_LEN, attDeviceName ); // Set advertising interval { uint16 advInt = DEFAULT_ADVERTISING_INTERVAL; GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MIN, advInt ); GAP_SetParamValue( TGAP_LIM_DISC_ADV_INT_MAX, advInt ); GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MIN, advInt ); GAP_SetParamValue( TGAP_GEN_DISC_ADV_INT_MAX, advInt ); } // Setup the GAP Bond Manager { uint32 passkey = ; // passkey "000000" uint8 pairMode = GAPBOND_PAIRING_MODE_WAIT_FOR_REQ; uint8 mitm = TRUE; uint8 ioCap = GAPBOND_IO_CAP_DISPLAY_ONLY; uint8 bonding = TRUE; GAPBondMgr_SetParameter( GAPBOND_DEFAULT_PASSCODE, sizeof ( uint32 ), &passkey ); GAPBondMgr_SetParameter( GAPBOND_PAIRING_MODE, sizeof ( uint8 ), &pairMode ); GAPBondMgr_SetParameter( GAPBOND_MITM_PROTECTION, sizeof ( uint8 ), &mitm ); GAPBondMgr_SetParameter( GAPBOND_IO_CAPABILITIES, sizeof ( uint8 ), &ioCap ); GAPBondMgr_SetParameter( GAPBOND_BONDING_ENABLED, sizeof ( uint8 ), &bonding ); } // Initialize GATT attributes GGS_AddService( GATT_ALL_SERVICES ); // GAP GATTServApp_AddService( GATT_ALL_SERVICES ); // GATT attributes DevInfo_AddService(); // Device Information Service SimpleProfile_AddService( GATT_ALL_SERVICES ); // Simple GATT Profile #if defined FEATURE_OAD VOID OADTarget_AddService(); // OAD Profile #endif // Setup the SimpleProfile Characteristic Values { uint8 charValue1 = ; uint8 charValue2 = ; uint8 charValue3 = ; uint8 charValue4 = ; uint8 charValue5[SIMPLEPROFILE_CHAR5_LEN] = { , , , , }; SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR1, sizeof ( uint8 ), &charValue1 ); SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR2, sizeof ( uint8 ), &charValue2 ); SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR3, sizeof ( uint8 ), &charValue3 ); SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR4, sizeof ( uint8 ), &charValue4 ); SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR5, SIMPLEPROFILE_CHAR5_LEN, charValue5 ); } #if defined( CC2540_MINIDK ) SK_AddService( GATT_ALL_SERVICES ); // Simple Keys Profile // Register for all key events - This app will handle all key events RegisterForKeys( simpleBLEPeripheral_TaskID ); // makes sure LEDs are off HalLedSet( (HAL_LED_1 | HAL_LED_2), HAL_LED_MODE_OFF ); // For keyfob board set GPIO pins into a power-optimized state // Note that there is still some leakage current from the buzzer, // accelerometer, LEDs, and buttons on the PCB. P0SEL = ; // Configure Port 0 as GPIO P1SEL = ; // Configure Port 1 as GPIO P2SEL = ; // Configure Port 2 as GPIO P0DIR = 0xFC; // Port 0 pins P0.0 and P0.1 as input (buttons), // all others (P0.2-P0.7) as output P1DIR = 0xFF; // All port 1 pins (P1.0-P1.7) as output P2DIR = 0x1F; // All port 1 pins (P2.0-P2.4) as output P0 = 0x03; // All pins on port 0 to low except for P0.0 and P0.1 (buttons) P1 = ; // All pins on port 1 to low P2 = ; // All pins on port 2 to low #endif // #if defined( CC2540_MINIDK ) #if (defined HAL_LCD) && (HAL_LCD == TRUE) #if defined FEATURE_OAD #if defined (HAL_IMAGE_A) HalLcdWriteStringValue( , HAL_LCD_LINE_1 ); #else HalLcdWriteStringValue( , HAL_LCD_LINE_1 ); #endif // HAL_IMAGE_A #else HalLcdWriteString( "BLE Peripheral", HAL_LCD_LINE_1 ); #endif // FEATURE_OAD #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) // Register callback with SimpleGATTprofile VOID SimpleProfile_RegisterAppCBs( &simpleBLEPeripheral_SimpleProfileCBs ); // Enable clock divide on halt // This reduces active current while radio is active and CC254x MCU // is halted HCI_EXT_ClkDivOnHaltCmd( HCI_EXT_ENABLE_CLK_DIVIDE_ON_HALT ); #if defined ( DC_DC_P0_7 ) // Enable stack to toggle bypass control on TPS62730 (DC/DC converter) HCI_EXT_MapPmIoPortCmd( HCI_EXT_PM_IO_PORT_P0, HCI_EXT_PM_IO_PORT_PIN7 ); #endif // defined ( DC_DC_P0_7 ) // Setup a delayed profile startup osal_set_event( simpleBLEPeripheral_TaskID, SBP_START_DEVICE_EVT ); } float last_temp; /********************************************************************* * @fn SimpleBLEPeripheral_ProcessEvent * * @brief Simple BLE Peripheral Application Task event processor. This function * is called to process all events for the task. Events * include timers, messages and any other user defined events. * * @param task_id - The OSAL assigned task ID. * @param events - events to process. This is a bit map and can * contain more than one event. * * @return events not processed */ uint16 SimpleBLEPeripheral_ProcessEvent( uint8 task_id, uint16 events ) { VOID task_id; // OSAL required parameter that isn't used in this function if ( events & SYS_EVENT_MSG ) { uint8 *pMsg; if ( (pMsg = osal_msg_receive( simpleBLEPeripheral_TaskID )) != NULL ) { simpleBLEPeripheral_ProcessOSALMsg( (osal_event_hdr_t *)pMsg ); // Release the OSAL message VOID osal_msg_deallocate( pMsg ); } // return unprocessed events return (events ^ SYS_EVENT_MSG); } if ( events & SBP_START_DEVICE_EVT ) { // Start the Device VOID GAPRole_StartDevice( &simpleBLEPeripheral_PeripheralCBs ); // Start Bond Manager VOID GAPBondMgr_Register( &simpleBLEPeripheral_BondMgrCBs ); // Set timer for first periodic event osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD ); return ( events ^ SBP_START_DEVICE_EVT ); } if ( events & SBP_PERIODIC_EVT ) { // Restart timer if ( SBP_PERIODIC_EVT_PERIOD ) { osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_PERIODIC_EVT, SBP_PERIODIC_EVT_PERIOD ); } // Perform periodic application task performPeriodicTask(); return (events ^ SBP_PERIODIC_EVT); } if(events & SBP_START_TEMP_TIMER_EVT) { if(SBP_TEMP_EVT_PERIOD) { osal_start_timerEx( simpleBLEPeripheral_TaskID, SBP_START_TEMP_TIMER_EVT, SBP_TEMP_EVT_PERIOD ); } { uint16 numBytes; float ft; ]; extern float DS18B20_ReadMain(void); P0SEL &= ~(BV()); ft = DS18B20_ReadMain(); printf("done.. %.1f\r\n", ft); //int len = sprintf(buf,">%.1f", ft); && ft > -) { if(last_temp!=ft) { oled_printf(FONT_32, ,," ", ft); oled_printf(FONT_32, ,,"%.1f", ft); last_temp = ft; } } ) { void relay_ctl(int id, int status); relay_ctl(,); relay_ctl(,); relay_ctl(,); relay_ctl(,); //red on P2DIR |= BV(); P2SEL &=~(BV()); P2_0 = ; } else { relay_ctl(,); relay_ctl(,); relay_ctl(,); relay_ctl(,); //red off P2DIR |= BV(); P2SEL &=~(BV()); P2_0 = ; } } return events ^ SBP_START_TEMP_TIMER_EVT; } printf("unknown events\r\n"); // Discard unknown events ; } /********************************************************************* * @fn simpleBLEPeripheral_ProcessOSALMsg * * @brief Process an incoming task message. * * @param pMsg - message to process * * @return none */ static void simpleBLEPeripheral_ProcessOSALMsg( osal_event_hdr_t *pMsg ) { printf("on msg\r\n"); switch ( pMsg->event ) { #if defined( CC2540_MINIDK ) case KEY_CHANGE: simpleBLEPeripheral_HandleKeys( ((keyChange_t *)pMsg)->state, ((keyChange_t *)pMsg)->keys ); break; #endif // #if defined( CC2540_MINIDK ) case GATT_MSG_EVENT: // Process GATT message simpleBLEPeripheral_ProcessGATTMsg( (gattMsgEvent_t *)pMsg ); break; default: // do nothing break; } } #if defined( CC2540_MINIDK ) /********************************************************************* * @fn simpleBLEPeripheral_HandleKeys * * @brief Handles all key events for this device. * * @param shift - true if in shift/alt. * @param keys - bit field for key events. Valid entries: * HAL_KEY_SW_2 * HAL_KEY_SW_1 * * @return none */ static void simpleBLEPeripheral_HandleKeys( uint8 shift, uint8 keys ) { uint8 SK_Keys = ; VOID shift; // Intentionally unreferenced parameter if ( keys & HAL_KEY_SW_1 ) { SK_Keys |= SK_KEY_LEFT; } if ( keys & HAL_KEY_SW_2 ) { SK_Keys |= SK_KEY_RIGHT; // if device is not in a connection, pressing the right key should toggle // advertising on and off // Note: If PLUS_BROADCASTER is define this condition is ignored and // Device may advertise during connections as well. #ifndef PLUS_BROADCASTER if( gapProfileState != GAPROLE_CONNECTED ) { #endif // PLUS_BROADCASTER uint8 current_adv_enabled_status; uint8 new_adv_enabled_status; //Find the current GAP advertisement status GAPRole_GetParameter( GAPROLE_ADVERT_ENABLED, ¤t_adv_enabled_status ); if( current_adv_enabled_status == FALSE ) { new_adv_enabled_status = TRUE; } else { new_adv_enabled_status = FALSE; } //change the GAP advertisement status to opposite of current status GAPRole_SetParameter( GAPROLE_ADVERT_ENABLED, sizeof( uint8 ), &new_adv_enabled_status ); #ifndef PLUS_BROADCASTER } #endif // PLUS_BROADCASTER } // Set the value of the keys state to the Simple Keys Profile; // This will send out a notification of the keys state if enabled SK_SetParameter( SK_KEY_ATTR, sizeof ( uint8 ), &SK_Keys ); } #endif // #if defined( CC2540_MINIDK ) /********************************************************************* * @fn simpleBLEPeripheral_ProcessGATTMsg * * @brief Process GATT messages * * @return none */ static void simpleBLEPeripheral_ProcessGATTMsg( gattMsgEvent_t *pMsg ) { GATT_bm_free( &pMsg->msg, pMsg->method ); } /********************************************************************* * @fn peripheralStateNotificationCB * * @brief Notification from the profile of a state change. * * @param newState - new state * * @return none */ static void peripheralStateNotificationCB( gaprole_States_t newState ) { #ifdef PLUS_BROADCASTER ; #endif // PLUS_BROADCASTER switch ( newState ) { case GAPROLE_STARTED: { uint8 ownAddress[B_ADDR_LEN]; uint8 systemId[DEVINFO_SYSTEM_ID_LEN]; GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress); // use 6 bytes of device address for 8 bytes of system ID value systemId[] = ownAddress[]; systemId[] = ownAddress[]; systemId[] = ownAddress[]; // set middle bytes to zero systemId[] = 0x00; systemId[] = 0x00; // shift three bytes up systemId[] = ownAddress[]; systemId[] = ownAddress[]; systemId[] = ownAddress[]; DevInfo_SetParameter(DEVINFO_SYSTEM_ID, DEVINFO_SYSTEM_ID_LEN, systemId); #if (defined HAL_LCD) && (HAL_LCD == TRUE) // Display device address HalLcdWriteString( bdAddr2Str( ownAddress ), HAL_LCD_LINE_2 ); HalLcdWriteString( "Initialized", HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) } break; case GAPROLE_ADVERTISING: { #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteString( "Advertising", HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) } break; #ifdef PLUS_BROADCASTER /* After a connection is dropped a device in PLUS_BROADCASTER will continue * sending non-connectable advertisements and shall sending this change of * state to the application. These are then disabled here so that sending * connectable advertisements can resume. */ case GAPROLE_ADVERTISING_NONCONN: { uint8 advertEnabled = FALSE; // Disable non-connectable advertising. GAPRole_SetParameter(GAPROLE_ADV_NONCONN_ENABLED, sizeof(uint8), &advertEnabled); // Reset flag for next connection. first_conn_flag = ; } break; #endif //PLUS_BROADCASTER case GAPROLE_CONNECTED: { #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteString( "Connected", HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) #ifdef PLUS_BROADCASTER // Only turn advertising on for this state when we first connect // otherwise, when we go from connected_advertising back to this state // we will be turning advertising back on. ) { uint8 advertEnabled = FALSE; // Turn on Advertising // Disable connectable advertising. GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8), &advertEnabled); // Set to true for non-connectabel advertising. advertEnabled = TRUE; // Enable non-connectable advertising. GAPRole_SetParameter(GAPROLE_ADV_NONCONN_ENABLED, sizeof(uint8), &advertEnabled); first_conn_flag = ; } #endif // PLUS_BROADCASTER } break; case GAPROLE_CONNECTED_ADV: { #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteString( "Connected Advertising", HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) } break; case GAPROLE_WAITING: { #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteString( "Disconnected", HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) #ifdef PLUS_BROADCASTER uint8 advertEnabled = TRUE; // Enabled connectable advertising. GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8), &advertEnabled); #endif //PLUS_BROADCASTER } break; case GAPROLE_WAITING_AFTER_TIMEOUT: { #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteString( "Timed Out", HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) #ifdef PLUS_BROADCASTER // Reset flag for next connection. first_conn_flag = ; #endif //#ifdef (PLUS_BROADCASTER) } break; case GAPROLE_ERROR: { #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteString( "Error", HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) } break; default: { #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteString( "", HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) } break; } gapProfileState = newState; #if !defined( CC2540_MINIDK ) VOID gapProfileState; // added to prevent compiler warning with // "CC2540 Slave" configurations #endif } /********************************************************************* * @fn performPeriodicTask * * @brief Perform a periodic application task. This function gets * called every five seconds as a result of the SBP_PERIODIC_EVT * OSAL event. In this example, the value of the third * characteristic in the SimpleGATTProfile service is retrieved * from the profile, and then copied into the value of the * the fourth characteristic. * * @param none * * @return none */ static void performPeriodicTask( void ) { uint8 valueToCopy; uint8 stat; // Call to retrieve the value of the third characteristic in the profile stat = SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR3, &valueToCopy); if( stat == SUCCESS ) { /* * Call to set that value of the fourth characteristic in the profile. Note * that if notifications of the fourth characteristic have been enabled by * a GATT client device, then a notification will be sent every time this * function is called. */ SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR4, sizeof(uint8), &valueToCopy); } } /********************************************************************* * @fn simpleProfileChangeCB * * @brief Callback from SimpleBLEProfile indicating a value change * * @param paramID - parameter ID of the value that was changed. * * @return none */ static void simpleProfileChangeCB( uint8 paramID ) { uint8 newValue; switch( paramID ) { case SIMPLEPROFILE_CHAR1: SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR1, &newValue ); #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteStringValue( , HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) break; case SIMPLEPROFILE_CHAR3: SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR3, &newValue ); #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteStringValue( , HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) break; default: // should not reach here! break; } } #if (defined HAL_LCD) && (HAL_LCD == TRUE) /********************************************************************* * @fn bdAddr2Str * * @brief Convert Bluetooth address to string. Only needed when * LCD display is used. * * @return none */ char *bdAddr2Str( uint8 *pAddr ) { uint8 i; char hex[] = "0123456789ABCDEF"; static char str[B_ADDR_STR_LEN]; char *pStr = str; *pStr++ = '; *pStr++ = 'x'; // Start from end of addr pAddr += B_ADDR_LEN; ; i-- ) { *pStr++ = hex[*--pAddr >> ]; *pStr++ = hex[*pAddr & 0x0F]; } *pStr = ; return str; } #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) /********************************************************************* *********************************************************************/
用蓝牙芯片CC2541/CC2540实现一个智能恒温箱的更多相关文章
- 2、利用蓝牙定位及姿态识别实现一个智能篮球场套件(二)——CC2540/CC2541基于广播的RSSI获得
CC2541一拖多例程中RSSI获得是通过一个事件回调函数实现的,前提是需要连接上蓝牙设备. 这个对于多点定位来说是不可行的,由于主机搜索蓝牙设备过程中也能获得当前蓝牙设备的RSSI等信息,因此可基于 ...
- 1、利用蓝牙定位及姿态识别实现一个智能篮球场套件(一)——用重写CC2541透传模块做成智能手环
一.预言 要实现一个智能篮球场套件,需要设计一个佩戴在篮球运动员手臂上的可以检测投篮.记步的手环,以及一套可以根据RSSI定位运动员的蓝牙定位装置.下面是大致需要的步骤: 首先,需要用CC2541透传 ...
- 【转】 C++易混知识点4: 自己编写一个智能指针(Reference Counting)学习auto_ptr和reference counting
这篇文章建大的介绍了如何编写一个智能指针. 介绍: 什么是智能指针?答案想必大家都知道,智能指针的目的就是更好的管理好内存和动态分配的资源,智能指针是一个智能的指针,顾名思义,他可以帮助我们管理内存. ...
- NEO从入门到开窗(1) - 一个智能合约的诞生
一.啰嗦两句 最近一直都在研究区块链,BitCoin,Etherenum, Hyper Ledger Fabric还有今天的主角小蚂蚁,当然出名以后改了一个艺名叫NEO.区块链大部分都是用Golang ...
- QT学习日记篇-03-仿写一个智能家居界面
课程大纲: <1>让界面漂亮起来,仿写一个智能家居界面 ->第一:给QT工程添加图片 进入下一步: <注意路径和名称一定不能有中文> ...
- 啥?你想diy一个智能音箱,来吧
没错,这是智zhang语音助手 本系统基于自美系统二次开发,添加连接EMQ服务器,语音远程控制LED(Nodemcu),当然也可以扩展控制更多的设备,只需要将下位机设备连接到EMQ服务器即可. 由于使 ...
- 动手实践丨手把手教你用STM32做一个智能鱼缸
摘要:本文基于STM32单片机设计了一款基于物联网的智能鱼缸. 本文分享自华为云社区<基于STM32+华为云IOT设计的物联网鱼缸[玩转华为云]>,作者: DS小龙哥 . 1. 前言 为了 ...
- cc2540 cc2541 低功耗实測和总结-与注意事项 - 低功耗小于10uA
CC2541 CC2540 实现超低功耗是很重要的: 我们来总结一下实现方法: 1,有定时器在跑时会一直跑在 PM2 电流在 300uA左右. 没有定时器跑后会到 PM3 , 电流会少于1 ...
- [cocos2dx注意事项014]一个用于cocos2dx对象智能指针模板
现在,C++有许多实现智能指针,一个更无所谓.哈. 这种智能指针是专为cocos2dx 2.2.x自定义.主要的易用性,同时必须遵循现有的cocos2dx内存管理.特殊实现这样的智能指针.无需在使用时 ...
随机推荐
- Linux 下安装配置 JDK1.7
目录[-] 1.下载JDK 2.解压安装 3.配置环境变量 4.配置默认JDK(一般情况下这一步都可以省略) 5.测试 1.下载JDK Linux操作系统是:Centos6.5-x64 目前最新的JD ...
- Binary Watch
Binary Watch 描述 Consider a binary watch with 5 binary digits to display hours (00 - 23) and 6 binary ...
- 破解JS加密:url unicode加密而已
加密所在的地方:http://tool.chinaz.com/Tools/UrlCrypt.aspx?url=www.baidu.com 结果: http://%77%77%77%2E%62%61%6 ...
- 一道变态的js题
一道腾讯js面试题 题目如下: f = function() {return true;}; g = function() {return false;}; (function() { if (g() ...
- codeforces 492E. Vanya and Field(exgcd求逆元)
题目链接:codeforces 492e vanya and field 留个扩展gcd求逆元的板子. 设i,j为每颗苹果树的位置,因为gcd(n,dx) = 1,gcd(n,dy) = 1,所以当走 ...
- HDU 3265 Posters
矩形面积并,一个拆成四个 #include<cstdio> #include<cstring> #include<cmath> #include<map> ...
- Java——类谜题
1.令人混淆的构造器 代码如下格式: public class Confusing { private Confusing(Object o) { System.out.println("O ...
- [iOS]C语言技术视频-02-程序分支结构(if...else)
下载地址: 链接: http://pan.baidu.com/s/1dREc2 密码: egbt
- Spring--AOP--面向切面编程
AOP: 面向切面编程. 通过动态代理实现. AOP就3条线, 2条线给剪断. 实现:动态代理 如果实现interface的话, 用Proxy, InvocationHandler. 不实现inter ...
- Nginx http_user_agent 防御 ab 等
日志出现大量: xxxxxxxxxxxxx - - [04/Jul/2013:23:37:49 +0800] "GET /1000.html HTTP/1.0" 200 56471 ...