
Controlador da Panificador
Dependencies: BLE_API mbed nRF51822
Fork of BLENano_SimpleControls by
Revision 6:8d65e62ce233, committed 2016-09-08
- Comitter:
- vgoliveira
- Date:
- Thu Sep 08 17:19:41 2016 +0000
- Parent:
- 5:1ccc4165731f
- Commit message:
- Primeira vers?o funcional, implementa COMMAND e PROGRAM.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 1ccc4165731f -r 8d65e62ce233 main.cpp --- a/main.cpp Wed Sep 07 21:28:10 2016 +0000 +++ b/main.cpp Thu Sep 08 17:19:41 2016 +0000 @@ -24,53 +24,37 @@ #define TXRX_BUF_LEN 20 -#define TIME_MORE P0_4 -#define TIME_LESS P0_5 -#define DOUGH_QNT P0_8 -#define OPTIONS P0_9 -#define COLOR P0_10 -#define INIT_STOP P0_11 -#define TEST_LED P0_19 - -#define PRESS_BUTTON 0x01 -#define RELEASE_BUTTON 0x02 +#define PIN_TIME_MORE P0_4 +#define PIN_TIME_LESS P0_5 +#define PIN_DOUGH_QNT P0_8 +#define PIN_OPTIONS P0_9 +#define PIN_COLOR P0_10 +#define PIN_INIT_STOP P0_11 +#define PIN_TEST_LED P0_19 // only used for debuggin (visual check) -#define CLK_TIME_MORE 0x01 -#define CLK_TIME_LESS 0x02 -#define CLK_DOUGH_QNT 0x03 -#define CLK_INIT_STOP 0x04 -#define CLK_OPTIONS 0x05 -#define CLK_COLOR 0x06 -#define CLK_TEST_LED 0x07 -#define CLK_TIME 500 // 500 ms holding the up state +#define OPERATION 0x00 +#define COMMAND 0x01 +#define PROGRAM 0x02 -/* -#define DIGITAL_IN_PIN P0_10 //CTS -#define PWM_PIN P0_11 //RXD -#define SERVO_PIN P0_8 //RTS -#define ANALOG_IN_PIN P0_4 //P04 -*/ +#define TIME_MORE 0x04 +#define TIME_LESS 0x05 +#define DOUGH_QNT 0x02 +#define INIT_STOP 0x06 +#define OPTIONS 0x01 +#define COLOR 0x03 +#define TEST_LED 0x07 + +#define DELAY 250 // 250 ms holding the up state for button clicking + BLE ble; -DigitalOut time_more(TIME_MORE,0); -DigitalOut time_less(TIME_LESS,0); -DigitalOut dough_qnt(DOUGH_QNT,0); -DigitalOut init_stop(INIT_STOP,0); -DigitalOut options(OPTIONS,0); -DigitalOut color(COLOR,0); -DigitalOut test_led(TEST_LED,0); - -/* -DigitalIn BUTTON(DIGITAL_IN_PIN); -PwmOut PWM(PWM_PIN); -AnalogIn ANALOG(ANALOG_IN_PIN); -Servo MYSERVO(SERVO_PIN); - -//Serial pc(USBTX, USBRX); - -static uint8_t analog_enabled = 0; -static uint8_t old_state = 0; -*/ +DigitalOut time_more(PIN_TIME_MORE,0); +DigitalOut time_less(PIN_TIME_LESS,0); +DigitalOut dough_qnt(PIN_DOUGH_QNT,0); +DigitalOut init_stop(PIN_INIT_STOP,0); +DigitalOut options(PIN_OPTIONS,0); +DigitalOut color(PIN_COLOR,0); +DigitalOut test_led(PIN_TEST_LED,1); /* The Nordic UART Service */ @@ -109,6 +93,18 @@ ble.startAdvertising(); } +void ClickButton(DigitalOut *button, uint8_t *click_num) +{ + for (uint8_t i = *click_num; i > 0; i--) + { + *button = 0; + wait_ms(DELAY); + *button = 1; + wait_ms(DELAY); + *button = 0; + } +} + void WrittenHandler(const GattWriteCallbackParams *Handler) { uint8_t buf[TXRX_BUF_LEN]; @@ -120,57 +116,23 @@ memset(txPayload, 0, TXRX_BUF_LEN); memcpy(txPayload, buf, TXRX_BUF_LEN); - switch (buf[0]) { - case PRESS_BUTTON: - switch(buf[1]) { - case CLK_TIME_MORE : - time_more = 1; - break; - case CLK_TIME_LESS : - time_less = 1; - break; - case CLK_DOUGH_QNT : - dough_qnt = 1; - break; - case CLK_INIT_STOP : - init_stop = 1; - break; - case CLK_OPTIONS : - options = 1; - break; - case CLK_COLOR : - color = 1; - break; - case CLK_TEST_LED : - test_led = 1; - break; - } - break; - case RELEASE_BUTTON: // released button - switch(buf[1]) { - case CLK_TIME_MORE : - time_more = 0; - break; - case CLK_TIME_LESS : - time_less = 0; - break; - case CLK_DOUGH_QNT : - dough_qnt = 0; - break; - case CLK_INIT_STOP : - init_stop = 0; - break; - case CLK_OPTIONS : - options = 0; - break; - case CLK_COLOR : - color = 0; - break; - case CLK_TEST_LED : - test_led = 0; - break; - } - break; + switch (buf[OPERATION]) { + case COMMAND: + options = buf[OPTIONS]; + dough_qnt = buf[DOUGH_QNT]; + color = buf[COLOR]; + time_more = buf[TIME_MORE]; + time_less = buf[TIME_LESS]; + init_stop = buf[INIT_STOP]; + break; + case PROGRAM: + ClickButton(&options,&buf[OPTIONS]); + ClickButton(&dough_qnt, &buf[DOUGH_QNT]); + ClickButton(&color, &buf[COLOR]); + ClickButton(&time_more, &buf[TIME_MORE]); + ClickButton(&time_less, &buf[TIME_LESS]); + ClickButton(&init_stop, &buf[INIT_STOP]); + break; } } } @@ -250,7 +212,7 @@ ble.accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED); ble.setAdvertisingType(GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED); ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, - (const uint8_t *)"Vini", sizeof("Vini") - 1); + (const uint8_t *)"Panificadora", sizeof("Panificadora") - 1); ble.accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_128BIT_SERVICE_IDS, (const uint8_t *)uart_base_uuid_rev, sizeof(uart_base_uuid)); // 100ms; in multiples of 0.625ms.