May 2021 Commit
Dependencies: sx128x sx12xx_hal
Diff: main.cpp
- Revision:
- 9:28f69b9b6a4c
- Parent:
- 8:efd5ceb87878
- Child:
- 10:e262a92550c6
--- a/main.cpp Mon Aug 19 01:28:02 2019 +0000 +++ b/main.cpp Thu Nov 28 05:54:24 2019 +0000 @@ -23,7 +23,15 @@ #endif Timer t; +InterruptIn UserButtonPB2(PB_2); +DigitalIn b[8] = {PB_5,PB_6,PB_8,PB_9,PB_12,PB_13,PB_14,PB_15}; +Thread thread; +// Create a queue that can hold a maximum of 32 events +EventQueue queue(32 * EVENTS_EVENT_SIZE); + + volatile bool tx_done; +uint8_t sendCommandFlag = 0; static uint16_t crc_ccitt( uint8_t *buffer, uint16_t length ) { @@ -132,12 +140,56 @@ return CMDLINE_RETCODE_SUCCESS; } +static void manual_transmission_queue_callback(void) +{ + uint8_t byte = 0; + uint8_t value = 0; + tr_debug("Parallel Port Data Input"); + for (int i = 0; i< 8; i++) + { + value = 0; + value = b[i].read(); + //tr_debug("bit %d, value: %d",i,value); + value = value << i; + //tr_debug("value shifted: %d",value); + byte |= value; + //tr_debug("byte: %d",byte); + } + tr_debug("sending byte: %d",byte); + send_alarm(byte); +} + +static void manual_transmission(void) +{ + CriticalSectionLock::enable(); + sendCommandFlag = 1; + CriticalSectionLock::disable(); +} +static void interrupt_check_in(void) +{ + if(sendCommandFlag) + { + queue.call(manual_transmission_queue_callback); + CriticalSectionLock::enable(); + sendCommandFlag = 0; + CriticalSectionLock::disable(); + } +} + + int main() { + + mbed_trace_mutex_wait_function_set( serial_out_mutex_wait ); mbed_trace_mutex_release_function_set( serial_out_mutex_release ); mbed_trace_init(); tr_debug(__FUNCTION__); + tr_debug("Program Entry"); + + thread.start(callback(&queue, &EventQueue::dispatch_forever)); + queue.call_every(100, interrupt_check_in); + UserButtonPB2.rise(&manual_transmission); wait(0.05); t.start(); @@ -154,9 +206,11 @@ cmd_mutex_wait_func( serial_out_mutex_wait ); cmd_mutex_release_func( serial_out_mutex_release ); cmd_add("transmit-byte", cmd_transmitByte,"Transmit Byte","Transmit a decimal byte over LoRa radio"); - + + while(true) { + int c = getchar(); if (c != EOF) {