IOT QTouch Sensor Demo.
Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include "asf.h"
#include "demo.h"
#include "bsp/include/nm_bsp.h"
#include "driver/include/m2m_wifi.h"
#include "socket/include/socket.h"
#include "conf_winc.h"
Data Structures | |
struct | s_msg_touch_keepalive |
struct | s_msg_touch_report |
struct | s_msg_user_input |
Macros | |
#define | GET_MUTLCAP_ROTOR_SLIDER_POSITION(ROTOR_SLIDER_NUMBER) |
#define | GET_MUTLCAP_SENSOR_STATE(SENSOR_NUMBER) |
#define | IMU_RX_TIMEOUT 8000 |
Message format definitions. More... | |
#define | IMU_TX_KEEPALIVE_DELAY 1000 |
#define | LED_0_PIN PIN_PB00 |
Discrete LED output pin definitions. More... | |
#define | LED_1_PIN PIN_PB01 |
#define | LED_2_PIN PIN_PB02 |
#define | LED_3_PIN PIN_PB03 |
#define | LED_4_PIN PIN_PA05 |
#define | LED_5_PIN PIN_PA06 |
#define | LED_6_PIN PIN_PA04 |
#define | LED_7_PIN PIN_PA07 |
#define | LED_8_PIN PIN_PA22 |
#define | LED_9_PIN PIN_PA23 |
#define | LED_B_PIN PIN_PA17 |
#define | LED_G_PIN PIN_PB15 |
#define | LED_R_PIN PIN_PB14 |
RGB LED output pin definitions. More... | |
#define | TEST_BUFFER_SIZE 1460 |
Receive buffer definition. More... | |
#define | TIME_PERIOD_1MSEC 33u |
RTC Interrupt timing definition. More... | |
Typedefs | |
typedef struct s_msg_touch_keepalive | t_msg_touch_keepalive |
typedef struct s_msg_touch_report | t_msg_touch_report |
typedef struct s_msg_user_input | t_msg_user_input |
Functions | |
static int32_t | button_press_duration (uint8_t button_state) |
static void | configure_port_pins (void) |
Port pin configuration / assignments. More... | |
static void | configure_rtc_callbacks (void) |
Configure the RTC timer callback. More... | |
static void | configure_rtc_count (void) |
Configure the RTC timer count after which interrupts comes. More... | |
void | demo_start (void) |
Demo main function. More... | |
static uint32_t | isSubStr (uint8_t *buf, uint32_t len, uint8_t *msg, uint32_t msglen) |
static void | m2m_wifi_socket_handler (SOCKET sock, uint8 u8Msg, void *pvMsg) |
Callback to get the Data from socket. More... | |
static void | m2m_wifi_state (uint8 u8MsgType, void *pvMsg) |
Callback to get the WiFi status update. More... | |
static void | parse_user_input (char *user_input) |
static void | print_provisioning_details (void) |
static void | rtc_overflow_callback (void) |
static void | timer_init (void) |
Initialize timer. More... | |
Variables | |
tstrM2MAPConfig | ap_config |
static uint32_t | connected = 0 |
static uint32_t | delay = 0 |
Global counter delay for timer. More... | |
static uint32_t | delay_clt_keepalive = 0 |
static uint32_t | delay_srv_keepalive = 0 |
char | gacHttpProvDomainName [] = DEMO_WLAN_AP_DOMAIN_NAME |
uint8 | gau8HttpProvServerIP [] = DEMO_WLAN_AP_IP_ADDRESS |
static uint8 | gau8SocketTestBuffer [TEST_BUFFER_SIZE] |
uint32_t | ms_ticks |
SysTick counter for non busy wait delay. More... | |
static t_msg_touch_keepalive | msg_touch_keepalive |
Message format declarations. More... | |
static t_msg_touch_report | msg_touch_report |
char | provision_pwd [30] |
char | provision_ssid [70] |
volatile uint8_t | PWM_Count |
const uint8_t | PWM_RGB_values [64][3] |
static struct sockaddr_in | remote_addr |
uint8_t | rotor_position |
uint8_t | rotor_state |
Variables. More... | |
struct rtc_module | rtc_instance |
static SOCKET | rx_socket = -1 |
RX and TX socket handlers. More... | |
static uint32_t | toggle_led_ms = 0 |
Global counters for LED toggling. More... | |
volatile uint16_t | touch_time_counter = 0u |
static SOCKET | tx_socket = -1 |
char | user_credentials [108] |
static t_msg_user_input | user_data |
static volatile uint8 | wifi_connected = 0 |
WiFi status variable. More... | |
static uint8 | wifi_provisioned = 1 |
#define GET_MUTLCAP_ROTOR_SLIDER_POSITION | ( | ROTOR_SLIDER_NUMBER | ) |
Referenced by demo_start(), and rtc_overflow_callback().
#define GET_MUTLCAP_SENSOR_STATE | ( | SENSOR_NUMBER | ) |
Referenced by demo_start().
#define IMU_RX_TIMEOUT 8000 |
Message format definitions.
Referenced by demo_start().
#define IMU_TX_KEEPALIVE_DELAY 1000 |
Referenced by demo_start().
#define LED_0_PIN PIN_PB00 |
Discrete LED output pin definitions.
Referenced by configure_port_pins(), and demo_start().
#define LED_1_PIN PIN_PB01 |
Referenced by configure_port_pins(), and demo_start().
#define LED_2_PIN PIN_PB02 |
Referenced by configure_port_pins(), and demo_start().
#define LED_3_PIN PIN_PB03 |
Referenced by configure_port_pins(), and demo_start().
#define LED_4_PIN PIN_PA05 |
Referenced by configure_port_pins(), and demo_start().
#define LED_5_PIN PIN_PA06 |
Referenced by configure_port_pins(), and demo_start().
#define LED_6_PIN PIN_PA04 |
Referenced by configure_port_pins(), and demo_start().
#define LED_7_PIN PIN_PA07 |
Referenced by configure_port_pins(), and demo_start().
#define LED_8_PIN PIN_PA22 |
Referenced by configure_port_pins(), and demo_start().
#define LED_9_PIN PIN_PA23 |
Referenced by configure_port_pins(), and demo_start().
#define LED_B_PIN PIN_PA17 |
Referenced by configure_port_pins(), demo_start(), and rtc_overflow_callback().
#define LED_G_PIN PIN_PB15 |
Referenced by configure_port_pins(), demo_start(), and rtc_overflow_callback().
#define LED_R_PIN PIN_PB14 |
RGB LED output pin definitions.
Referenced by configure_port_pins(), demo_start(), and rtc_overflow_callback().
#define TEST_BUFFER_SIZE 1460 |
Receive buffer definition.
Referenced by m2m_wifi_socket_handler().
#define TIME_PERIOD_1MSEC 33u |
RTC Interrupt timing definition.
Referenced by timer_init().
typedef struct s_msg_touch_keepalive t_msg_touch_keepalive |
typedef struct s_msg_touch_report t_msg_touch_report |
typedef struct s_msg_user_input t_msg_user_input |
|
static |
References ms_ticks.
Referenced by demo_start().
|
static |
Port pin configuration / assignments.
References port_config::direction, LED_0_PIN, LED_1_PIN, LED_2_PIN, LED_3_PIN, LED_4_PIN, LED_5_PIN, LED_6_PIN, LED_7_PIN, LED_8_PIN, LED_9_PIN, LED_B_PIN, LED_G_PIN, LED_R_PIN, port_get_config_defaults(), PORT_PIN_DIR_OUTPUT, and port_pin_set_config().
Referenced by demo_start().
|
static |
Configure the RTC timer callback.
References RTC_COUNT_CALLBACK_OVERFLOW, rtc_count_enable_callback(), rtc_count_register_callback(), rtc_instance, and rtc_overflow_callback().
Referenced by timer_init().
|
static |
Configure the RTC timer count after which interrupts comes.
References rtc_count_config::continuously_update, rtc_count_config::mode, rtc_count_config::prescaler, rtc_count_enable(), rtc_count_get_config_defaults(), rtc_count_init(), RTC_COUNT_MODE_16BIT, RTC_COUNT_PRESCALER_DIV_1, and rtc_instance.
Referenced by timer_init().
void demo_start | ( | void | ) |
Demo main function.
Initialize timer.
Initialize QTouch library and configure touch sensors.
Configure port pins
Turn off all extension board LEDs
Start touch sensor measurement, if touch_time.time_to_measure_touch flag is set by timer.
Get touch sensor states
Clear all slider controlled LEDs
If slider is activated
Parse slider position
References _htons, AF_INET, s_msg_touch_report::b1_state, s_msg_touch_report::b2_state, bind(), button_press_duration(), s_msg_user_input::channel, configure_port_pins(), connected, delay, delay_clt_keepalive, delay_ms, delay_srv_keepalive, delay_us, DEMO_REPORT_INTERVAL, DEMO_SERVER_PORT, gacHttpProvDomainName, GET_MUTLCAP_ROTOR_SLIDER_POSITION, GET_MUTLCAP_SENSOR_STATE, IMU_RX_TIMEOUT, IMU_TX_KEEPALIVE_DELAY, LED_0_PIN, LED_1_PIN, LED_2_PIN, LED_3_PIN, LED_4_PIN, LED_5_PIN, LED_6_PIN, LED_7_PIN, LED_8_PIN, LED_9_PIN, LED_B_PIN, LED_G_PIN, LED_R_PIN, M2M_SUCCESS, m2m_wifi_connect(), m2m_wifi_default_connect(), m2m_wifi_disable_ap(), m2m_wifi_handle_events(), m2m_wifi_init(), m2m_wifi_socket_handler(), m2m_wifi_start_provision_mode(), m2m_wifi_state(), tag_touch_measure_data_t::measurement_done_touch, ms_ticks, nm_bsp_init(), NULL, p_mutlcap_measure_data, parse_user_input(), s_msg_user_input::password, tstrWifiInitParam::pfAppWifiCb, port_pin_set_output_level(), print_provisioning_details(), PWM_Count, registerSocketCallback(), remote_addr, s_msg_touch_report::rot_position, s_msg_touch_report::rot_state, rotor_position, rotor_state, rx_socket, in_addr::s_addr, s_msg_user_input::security, sendto(), setsockopt(), sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_port, s_msg_touch_report::sl_pos, s_msg_touch_report::sl_state, SO_SET_UDP_SEND_CALLBACK, SOCK_DGRAM, socket(), socketInit(), SOL_SOCKET, s_msg_user_input::SSID, timer_init(), toggle_led_ms, touch_sensors_init(), touch_sensors_measure(), tx_socket, user_credentials, wifi_connected, and wifi_provisioned.
Referenced by main().
|
static |
Referenced by m2m_wifi_socket_handler().
Callback to get the Data from socket.
[in] | sock | socket handler. |
[in] | u8Msg | socket event type. Possible values are:
|
[in] | pvMsg | is a pointer to message structure. Existing types are: |
References connected, delay_srv_keepalive, gau8SocketTestBuffer, isSubStr(), ms_ticks, tstrSocketRecvMsg::pu8Buffer, recvfrom(), remote_addr, rx_socket, tstrSocketRecvMsg::s16BufferSize, in_addr::s_addr, sockaddr_in::sin_addr, SOCK_ERR_TIMEOUT, SOCKET_MSG_BIND, SOCKET_MSG_RECVFROM, tstrSocketBindMsg::status, tstrSocketRecvMsg::strRemoteAddr, and TEST_BUFFER_SIZE.
Referenced by demo_start().
|
static |
Callback to get the WiFi status update.
[in] | u8MsgType | type of WiFi notification. Possible types are:
|
[in] | pvMsg | A pointer to a buffer containing the notification parameters (if any). It should be casted to the correct data type corresponding to the notification type. Existing types are:
|
References tstrM2MConnInfo::acSSID, tstrM2MProvisionInfo::au8Password, tstrM2MProvisionInfo::au8SSID, s_msg_user_input::channel, gacHttpProvDomainName, M2M_DEFAULT_CONN_EMPTY_LIST, M2M_DEFAULT_CONN_SCAN_MISMATCH, M2M_SUCCESS, M2M_WIFI_CH_ALL, m2m_wifi_connect(), M2M_WIFI_CONNECTED, M2M_WIFI_DISCONNECTED, m2m_wifi_get_connection_info(), M2M_WIFI_REQ_DHCP_CONF, m2m_wifi_request_dhcp_client(), M2M_WIFI_RESP_CON_STATE_CHANGED, M2M_WIFI_RESP_CONN_INFO, M2M_WIFI_RESP_DEFAULT_CONNECT, M2M_WIFI_RESP_PROVISION_INFO, M2M_WIFI_SEC_OPEN, m2m_wifi_start_provision_mode(), s_msg_user_input::password, print_provisioning_details(), provision_pwd, provision_ssid, tstrM2MDefaultConnResp::s8ErrorCode, s_msg_user_input::security, s_msg_user_input::SSID, tstrM2mWifiStateChanged::u8CurrState, tstrM2MProvisionInfo::u8SecType, tstrM2MProvisionInfo::u8Status, wifi_connected, and wifi_provisioned.
Referenced by demo_start().
|
static |
References s_msg_user_input::channel, DEFAULT_AUTH, DEFAULT_CHANNEL, DEFAULT_PWD, DEFAULT_SSID, NULL, s_msg_user_input::password, s_msg_user_input::security, and s_msg_user_input::SSID.
Referenced by demo_start().
|
static |
References DEMO_WLAN_AP_NAME.
Referenced by demo_start(), and m2m_wifi_state().
|
static |
References tag_touch_time_t::current_time_ms, GET_MUTLCAP_ROTOR_SLIDER_POSITION, LED_B_PIN, LED_G_PIN, LED_R_PIN, tag_touch_time_t::measurement_period_ms, port_pin_set_output_level(), PWM_Count, PWM_RGB_values, rotor_position, rotor_state, tag_touch_time_t::time_to_measure_touch, touch_time, and touch_time_counter.
Referenced by configure_rtc_callbacks().
|
static |
Initialize timer.
References configure_rtc_callbacks(), configure_rtc_count(), rtc_count_set_period(), rtc_instance, and TIME_PERIOD_1MSEC.
Referenced by demo_start().
tstrM2MAPConfig ap_config |
|
static |
Referenced by demo_start(), and m2m_wifi_socket_handler().
|
static |
Global counter delay for timer.
Referenced by demo_start().
|
static |
Referenced by demo_start().
|
static |
Referenced by demo_start(), and m2m_wifi_socket_handler().
char gacHttpProvDomainName[] = DEMO_WLAN_AP_DOMAIN_NAME |
Referenced by demo_start(), and m2m_wifi_state().
uint8 gau8HttpProvServerIP[] = DEMO_WLAN_AP_IP_ADDRESS |
|
static |
Referenced by m2m_wifi_socket_handler().
uint32_t ms_ticks |
SysTick counter for non busy wait delay.
SysTick counter for non busy wait delay.
Referenced by button_press_duration(), demo_start(), m2m_wifi_socket_handler(), and SysTick_Handler().
|
static |
Message format declarations.
|
static |
char provision_pwd[30] |
Referenced by m2m_wifi_state().
char provision_ssid[70] |
Referenced by m2m_wifi_state().
volatile uint8_t PWM_Count |
Referenced by demo_start(), and rtc_overflow_callback().
const uint8_t PWM_RGB_values[64][3] |
Referenced by rtc_overflow_callback().
|
static |
Referenced by demo_start(), and m2m_wifi_socket_handler().
uint8_t rotor_position |
Referenced by demo_start(), and rtc_overflow_callback().
uint8_t rotor_state |
Variables.
Referenced by demo_start(), and rtc_overflow_callback().
struct rtc_module rtc_instance |
Referenced by configure_rtc_callbacks(), configure_rtc_count(), and timer_init().
|
static |
RX and TX socket handlers.
Referenced by demo_start(), and m2m_wifi_socket_handler().
|
static |
Global counters for LED toggling.
Referenced by demo_start().
volatile uint16_t touch_time_counter = 0u |
Referenced by rtc_overflow_callback().
|
static |
Referenced by demo_start().
char user_credentials[108] |
Referenced by demo_start().
|
static |
|
static |
WiFi status variable.
Referenced by demo_start(), and m2m_wifi_state().
|
static |
Referenced by demo_start(), and m2m_wifi_state().