Rapid Prototyping a Bluetooth® Smart Appliance Control Application on a 32-bit MCU-based Curiosity Nano Evaluation Kit Using MPLAB® Harmony v3 Software Framework: Step 7
Add Application Code to the Project
The custom eink_bundle_image.c and eink_bundle_image.h files for this application are pre-developed and are available in <your unzip folder>/pic32cmmc_smart_appliance_control /dev_files/pic32cm_mc00_cnano folder.
The eink_bundle_image.c file contains the image array.
- Go to the pic32cmmc_smart_appliance_control /dev_files/pic32cm_mc00_cnano folder and copy the pre-developed eink_bundle_image.c and eink_bundle_image.h files.
- Replace the eink_bundle_image.c and eink_bundle_image.h file of your project available at <Your project folder>/ pic32cmmc_smart_appliance_control /firmware/click_routines/eink_bundle/ by over-writing it with the copied file.
The application is already partially developed and is available in the main.c file under <your unzip folder>/pic32cmmc_smart_appliance_control/dev_files/pic32cm_mc00_cnano. The main.c file contains the application logic. It also contains placeholders that you will populate with the necessary code in the next step.
- Go to the pic32cmmc_smart_appliance_control /dev_files/pic32cm_mc00_cnano folder and copy the pre-developed main.c file.
- Replace (over-write) the main.c file of your project available at <Your project folder>/pic32cmmc_smart_appliance_control /firmware/src with the copied file.
- Open main.c in MPLAB® X IDE and add the application code by following the steps below:
Under the main.c file, in the main() function, notice the call to the SYS_Initialize function. The generated SYS_Initialize function initializes all the peripheral modules used in the application, configured through MPLAB Harmony Configurator (MHC).
In the int main (void) function, below the SYS_Initialize() function call, add the below lines of code to initialize Fan Click, eINK Click, and BM71 BLE
CLICK_FAN_DelayMs(1000);
fan_init();
fan_switch_off();
CLICK_FAN_DelayMs(1000);
eink_init();
eink_set_font( guiFont_Tahoma_14_Regular, EINK_COLOR_BLACK, FO_HORIZONTAL);
eink_image_bmp(mchp_logo_fan);
DRV_BM71_Initialize();
bleInitialize(true);
strcpy(BLE_Cmd_buf, (char *)"TEMP_CTRL");
bleTasks();
{
Weather_readSensors();
temperature =(int16_t)Weather_getTemperatureDegC();
if(temperature >=18 && temperature <=25 )
{
fan_set_speed(SPEED_LOW);
sprintf(buffer1, " LOW");
}
else if(temperature >=26 && temperature <=30 )
{
fan_set_speed(SPEED_MEDIUM);
sprintf(buffer1, "MEDIUM");
}
else if(temperature > 30)
{
fan_set_speed(SPEED_HIGH);
sprintf(buffer1, " HIGH");
}
else if(temperature < 18)
{
fan_switch_off();
sprintf(buffer1, "OFF");
}
sprintf(buffer, "%d C",temperature);
if(Isble_adv_started() == true){
if(((strcmp(temp_buffer,buffer1)) != 0)|(dummy_temperature != temperature ))
{
strcpy(temp_buffer,buffer1);
dummy_temperature = temperature;
eink_image_bmp(mchp_logo_fan);
eink_text(buffer,18,73 );
eink_text("Tempr =",0,55 );
eink_text(buffer1,0,145 );
CLICK_FAN_DelayMs(1000);
}
}
}
Following the above if statement, add an else if statement where the user can control the fan from the BLE-based MBD app running on the connected smartphone by sending commands and update the fan speed on eINK display.
{
if(!strcmp((char *)&BLE_Cmd_buf[8 + 1], "FAN_ON"))
{
fan_switch_on();
sprintf(buffer1, " ON");
}
else if(!strcmp((char *)&BLE_Cmd_buf[8 + 1], "FAN_LOW"))
{
fan_set_speed(SPEED_LOW);
sprintf(buffer1, " LOW");
}
else if(!strcmp((char *)&BLE_Cmd_buf[8 + 1], "FAN_MID"))
{
fan_set_speed(SPEED_MEDIUM);
sprintf(buffer1, "MEDIUM");
}
else if(!strcmp((char *)&BLE_Cmd_buf[8 + 1], "FAN_HIGH"))
{
fan_set_speed(SPEED_HIGH);
sprintf(buffer1, " HIGH");
}
else if(!strcmp((char *)&BLE_Cmd_buf[8 + 1], "FAN_OFF"))
{
fan_switch_off();
sprintf(buffer1, " OFF");
}
else
{
;
}
memset(BLE_Cmd_buf, 0x00, 100);
if((strcmp(temp_buffer,buffer1)) != 0)
{
strcpy(temp_buffer,buffer1);
eink_image_bmp(mchp_logo_fan);
eink_text(buffer1,0,145 );
}
}
else
{
;
}
You are now ready to build the code and observe the results!