Ubiei Ubiei / Mbed OS FTHR_USBMSD_Demo_27

Dependencies:   USBMSD_BD max32630fthr USBDevice

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PushButton.cpp Source File

PushButton.cpp

00001 /*******************************************************************************
00002  * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
00003  *
00004  * Permission is hereby granted, free of charge, to any person obtaining a
00005  * copy of this software and associated documentation files (the "Software"),
00006  * to deal in the Software without restriction, including without limitation
00007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00008  * and/or sell copies of the Software, and to permit persons to whom the
00009  * Software is furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included
00012  * in all copies or substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00015  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00016  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00017  * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
00018  * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
00019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00020  * OTHER DEALINGS IN THE SOFTWARE.
00021  *
00022  * Except as contained in this notice, the name of Maxim Integrated
00023  * Products, Inc. shall not be used except as stated in the Maxim Integrated
00024  * Products, Inc. Branding Policy.
00025  *
00026  * The mere transfer of this software does not imply any licenses
00027  * of trade secrets, proprietary technology, copyrights, patents,
00028  * trademarks, maskwork rights, or any other form of intellectual
00029  * property whatsoever. Maxim Integrated Products, Inc. retains all
00030  * ownership rights.
00031  *******************************************************************************
00032  */
00033 
00034 #include "PushButton.h"
00035 #include "Peripherals.h"
00036 
00037 extern MAX30001 max30001;
00038 extern uint32_t global_key_judge;
00039 extern int current_log_number;
00040 
00041 PushButton::PushButton(PinName pin) : interruptButton(pin) {
00042   this->pin = pin;
00043 
00044   interruptButton.mode(PullUp);
00045   debouncingState = false;
00046   // Delay for initial pullup to take effect
00047   wait(0.01f);
00048   // Attach the address of the interrupt handler routine for pushbutton
00049   interruptButton.fall(callback(this, &PushButton::pb_hit_interrupt_fall));
00050 }
00051 
00052 bool PushButton::GetButtonFallState(void) { 
00053  return buttonFallState; 
00054 }
00055 
00056 void PushButton::SetButtonFallState(bool state) { 
00057  buttonFallState = state; 
00058 }
00059 
00060 void PushButton::clearButtonFallState(void) { 
00061  buttonFallState = false; 
00062 }
00063 
00064 int PushButton::Read(void) { 
00065  return interruptButton.read(); 
00066 }
00067 
00068 void PushButton::pb_hit_interrupt_fall(void) {
00069     /* switch debouncing */
00070     if (!debouncingState)
00071     {
00072         timeout.attach(callback(this, &PushButton::pb_debounce_timeout), debounceTime);
00073     }
00074     
00075     if ( global_key_judge&0x01 == 1 )
00076     {
00077         max30001.max30001_BIOZ_InitStart(0b1, 0b0, 0b0, 0b00, 
00078                                         0b00, 0b00, 7, 0b0,
00079                                         0b010, 0b0, 0b00, 0b00, 0b00, 
00080                                         2, 0b0, 0b011, 0b0000, 0b0000);
00081         max30001.max30001_synch();
00082         
00083         /*
00084         printf("global_key_judge = %d\n", global_key_judge);
00085         FILE *fp_index = fopen("/sd/index.txt", "r+");
00086         int index_number = 0;
00087         int err = fscanf(fp_index, "%d", &index_number);
00088         printf("Scan err = %d\n", err);
00089         index_number += 1;
00090         err = fprintf(fp_index, "%d\n", index_number);
00091         printf("err = %d\n", err);
00092         printf("index_number = %d\n", index_number);
00093         printf("Start Sampling \n");
00094         printf("index_number = %d \n", index_number);
00095         fclose(fp_index);
00096         */
00097         printf("Save to Bioz_%d.txt", current_log_number);
00098         current_log_number += 1;
00099         wait_ms(200);
00100     }
00101     else
00102     {
00103         max30001.max30001_Stop_ECG();
00104         max30001.max30001_Stop_PACE();
00105         max30001.max30001_Stop_BIOZ();
00106         max30001.max30001_Stop_RtoR();
00107         printf("Stop Sampling \n");
00108         wait_ms(200);
00109     }
00110     
00111     global_key_judge += 1;
00112 
00113     
00114     //max30001.max30001_ECG_InitStart(0b1, 0b1, 0b1, 0b0, 0b10, 0b11, 0x1F, 0b00,
00115     //                               0b00, 0b0, 0b01);
00116 }
00117 
00118 void PushButton::pb_debounce_timeout(void) {
00119     if (!interruptButton.read())
00120     {
00121         if (Peripherals::pushButton() != NULL){
00122             Peripherals::pushButton()->SetButtonFallState(true);
00123         }
00124     }
00125     debouncingState = false;
00126 }
00127