Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2022
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 1.17 KB | None | 0 0
  1. import strutils
  2. import nesper/general, nesper/uarts, nesper/gpios, nesper/tasks
  3. import bytesequtils
  4. import ./example
  5. import ./tasks as mytasks
  6.  
  7. proc sendAT() =
  8.   var conf = newUartConfig(
  9.     stop_bits = UART_STOP_BITS_1,
  10.     data_bits = UART_DATA_8_BITS,
  11.     parity = UART_PARITY_DISABLE,
  12.     flow_ctrl = UART_HW_FLOWCTRL_DISABLE)
  13.  
  14.   var urt1 = newUart(
  15.     uart_num = UART_NUM_1,
  16.     config = conf,
  17.     tx_pin = gpios.GPIO_NUM_17,
  18.     rx_pin = gpios.GPIO_NUM_16,
  19.     buffer = 16_384.SzBytes)
  20.  
  21.   while true:
  22.     echo "Writing to the uart..."
  23.     var len = urt1.write("AT\r")
  24.     echo $len
  25.     # check: uart_wait_tx_done(urt1.port, 100)
  26.  
  27.     echo "Here is where I'd read it..."
  28.     vTaskDelay(10)
  29.  
  30.     var buf = urt1.read()
  31.     if buf.len > 0:
  32.       var res = buf.toStrBuf()
  33.       echo "'" & res & "'"
  34.       echo res.contains("OK")
  35.       echo res == "OK"
  36.     vTaskDelay(300)
  37.  
  38. app_main():
  39.   echo "Hello, Nim!"
  40.   example.run()
  41.   var t: Task = newTask(sendAT, "sendAT", (16384 * 3).SzBytes)
  42.   if t.ret == pdPASS:
  43.     echo "Created task successfully!"
  44.   # discard xTaskCreate(sendAT, "sendAT", 16384 * 3, nil, 10, nil)
  45.   assert false, "Should never get here"
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement