Microchip® Advanced Software Framework

iot_qtouch_demo/demo.c File Reference

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
 Message format definitions. More...
 

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_1_PIN   PIN_PB01
 Discrete LED output pin definitions. More...
 
#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_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
 [rtc_module_instance] More...
 
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)
Value:
ROTOR_SLIDER_NUMBER]
touch_measure_data_t * p_mutlcap_measure_data
Mutual Cap sensors measured data pointer.
Definition: thirdparty/qtouch/devspecific/sam0/samd/examples/example_selfcap/qtouch/touch.c:93
uint8_t * p_rotor_slider_values
Definition: touch_api_SAMD.h:764

Referenced by demo_start(), and rtc_overflow_callback().

#define GET_MUTLCAP_SENSOR_STATE (   SENSOR_NUMBER)
Value:
p_sensor_states[(SENSOR_NUMBER / \
8)] & (1 << (SENSOR_NUMBER % 8))
touch_measure_data_t * p_mutlcap_measure_data
Mutual Cap sensors measured data pointer.
Definition: thirdparty/qtouch/devspecific/sam0/samd/examples/example_selfcap/qtouch/touch.c:93

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_1_PIN   PIN_PB01

Discrete LED output pin definitions.

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_B_PIN   PIN_PA17
#define LED_G_PIN   PIN_PB15
#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().

static int32_t button_press_duration ( uint8_t  button_state)
static

References ms_ticks.

Referenced by demo_start().

static void configure_port_pins ( void  )
static
static void configure_rtc_callbacks ( void  )
static
static void configure_rtc_count ( void  )
static
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, at30tse_init(), at30tse_read_temperature(), s_msg_touch_report::b1_state, s_msg_touch_report::b2_state, bind(), button_press_duration(), s_msg_user_input::channel, cnt, configure_port_pins(), connected, CREDENTIAL_ENTRY_BUTTON, delay, delay_clt_keepalive, delay_ms, delay_srv_keepalive, delay_us, DEMO_REPORT_INTERVAL, DEMO_SERVER_PORT, demo_wifi_socket_handler(), demo_wifi_state(), gacHttpProvDomainName, GET_MUTLCAP_ROTOR_SLIDER_POSITION, GET_MUTLCAP_SENSOR_STATE, IMU_RX_TIMEOUT, IMU_TX_KEEPALIVE_DELAY, ioport_get_pin_level(), ioport_toggle_pin_level(), s_msg_temp_report::led, LED_1_PIN, LED_2_PIN, LED_3_PIN, LED_4_PIN, LED_5_PIN, LED_6_PIN, LED_7_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_get_input_level(), port_pin_get_output_level(), port_pin_set_output_level(), port_pin_toggle_output_level(), print_provisioning_details(), printf, PWM_Count, registerSocketCallback(), remote_addr, ret, 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, s_msg_temp_report::temp, timer_init(), toggle_led_ms, touch_sensors_init(), touch_sensors_measure(), tx_socket, user_credentials, wifi_connected, and wifi_provisioned.

static uint32_t isSubStr ( uint8_t *  buf,
uint32_t  len,
uint8_t *  msg,
uint32_t  msglen 
)
static

References i, j, and len.

Referenced by m2m_wifi_socket_handler().

static void m2m_wifi_socket_handler ( SOCKET  sock,
uint8  u8Msg,
void *  pvMsg 
)
static

Callback to get the Data from socket.

Parameters
[in]socksocket handler.
[in]u8Msgsocket event type. Possible values are:
  • SOCKET_MSG_BIND
  • SOCKET_MSG_LISTEN
  • SOCKET_MSG_ACCEPT
  • SOCKET_MSG_CONNECT
  • SOCKET_MSG_RECV
  • SOCKET_MSG_SEND
  • SOCKET_MSG_SENDTO
  • SOCKET_MSG_RECVFROM
[in]pvMsgis 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 void m2m_wifi_state ( uint8  u8MsgType,
void *  pvMsg 
)
static

Callback to get the WiFi status update.

Parameters
[in]u8MsgTypetype of WiFi notification. Possible types are:
[in]pvMsgA 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(), printf, provision_pwd, provision_ssid, tstrM2MDefaultConnResp::s8ErrorCode, s_msg_user_input::security, s_msg_user_input::SSID, strncpy(), tstrM2mWifiStateChanged::u8CurrState, tstrM2MProvisionInfo::u8SecType, tstrM2MProvisionInfo::u8Status, wifi_connected, and wifi_provisioned.

Referenced by demo_start().

static void print_provisioning_details ( void  )
static

References DEMO_WLAN_AP_NAME, and printf.

Referenced by demo_start(), and m2m_wifi_state().

static void timer_init ( void  )
static

tstrM2MAPConfig ap_config
Initial value:
= {
}
#define DEMO_WLAN_AP_NAME
Access point configuration for provisioning.
Definition: iot_cloud_demo/demo.h:42
#define DEMO_WLAN_AP_MODE
Definition: iot_cloud_demo/demo.h:48
#define DEMO_WLAN_AP_WEP_KEY
Definition: iot_cloud_demo/demo.h:46
#define DEMO_WLAN_AP_IP_ADDRESS
Definition: iot_cloud_demo/demo.h:50
#define DEMO_WLAN_AP_CHANNEL
Definition: iot_cloud_demo/demo.h:43
#define DEMO_WLAN_AP_WEP_SIZE
Definition: iot_cloud_demo/demo.h:45
#define DEMO_WLAN_AP_WEP_INDEX
Definition: iot_cloud_demo/demo.h:44
#define DEMO_WLAN_AP_SECURITY
Definition: iot_cloud_demo/demo.h:47
uint32_t delay = 0
static

Global counter delay for timer.

Referenced by demo_start().

uint32_t delay_clt_keepalive = 0
static

Referenced by demo_start().

uint32_t delay_srv_keepalive = 0
static
char gacHttpProvDomainName[] = DEMO_WLAN_AP_DOMAIN_NAME
uint8 gau8HttpProvServerIP[] = DEMO_WLAN_AP_IP_ADDRESS
uint8 gau8SocketTestBuffer[TEST_BUFFER_SIZE]
static

Referenced by m2m_wifi_socket_handler().

uint32_t ms_ticks

SysTick counter for non busy wait delay.

TLS read functionality.

SysTick counter for non busy wait delay.

t_msg_touch_keepalive msg_touch_keepalive
static
Initial value:
=
{
.id0 = 0,
.id1 = 1,
.type = 4,
}
#define DEMO_PRODUCT_NAME
Sensor name.
Definition: iot_temperature_demo/demo.h:48

Message format declarations.

t_msg_touch_report msg_touch_report
static
Initial value:
=
{
.id0 = 0,
.id1 = 6,
}
#define DEMO_PRODUCT_NAME
Sensor name.
Definition: iot_temperature_demo/demo.h:48
char provision_pwd[30]
char provision_ssid[70]
volatile uint8_t PWM_Count
const uint8_t PWM_RGB_values[64][3]
struct sockaddr_in remote_addr
static
uint8_t rotor_position
uint8_t rotor_state

Variables.

SOCKET rx_socket = -1
static

RX and TX socket handlers.

Referenced by demo_start(), and m2m_wifi_socket_handler().

uint32_t toggle_led_ms = 0
static

Global counters for LED toggling.

Referenced by demo_start().

volatile uint16_t touch_time_counter = 0u
SOCKET tx_socket = -1
static

Referenced by demo_start().

char user_credentials[108]
t_msg_user_input user_data
static
volatile uint8 wifi_connected = 0
static

WiFi status variable.

Referenced by demo_start(), and m2m_wifi_state().

uint8 wifi_provisioned = 1
static

Referenced by demo_start(), and m2m_wifi_state().