Started implementing style guide
This commit is contained in:
@@ -18,22 +18,22 @@
|
|||||||
|
|
||||||
//Function prototypes
|
//Function prototypes
|
||||||
static void mqtt_pub_request_cb(void*, err_t);
|
static void mqtt_pub_request_cb(void*, err_t);
|
||||||
static void example_publish(mqtt_client_t* , void*);
|
static void publish_data(mqtt_client_t* , void*);
|
||||||
static void mqtt_incoming_publish_cb(void*, const char*, u32_t);
|
static void mqtt_incoming_publish_cb(void*, const char*, u32_t);
|
||||||
static void mqtt_incoming_data_cb(void*, const uint8_t*, u16_t, u8_t);
|
static void mqtt_incoming_data_cb(void*, const uint8_t*, u16_t, u8_t);
|
||||||
static void mqtt_sub_request_cb(void*, err_t);
|
static void mqtt_sub_request_cb(void*, err_t);
|
||||||
static void mqtt_connection_cb(mqtt_client_t*, void*, mqtt_connection_status_t);
|
static void mqtt_connection_cb(mqtt_client_t*, void*, mqtt_connection_status_t);
|
||||||
static void example_do_connect(mqtt_client_t*);
|
static void mosquitto_connect(mqtt_client_t*);
|
||||||
static uint32_t color_picker(char*);
|
static uint32_t color_picker(char*);
|
||||||
|
|
||||||
//global variable used in mqtt_incoming_publish_cb and mqtt_incoming_data_cb to give an easy to use ID to the subscribed topics
|
//global variables used in mqtt_incoming_publish_cb and mqtt_incoming_data_cb to give an easy to use ID to the subscribed topics
|
||||||
static int inpub_id;
|
static sFONT* font;
|
||||||
static const char *TAG = "mug";
|
|
||||||
static uint16_t xpos;
|
static uint16_t xpos;
|
||||||
static uint16_t ypos;
|
static uint16_t ypos;
|
||||||
static sFONT* font;
|
|
||||||
static uint32_t color;
|
static uint32_t color;
|
||||||
static uint32_t bgcolor;
|
static uint32_t bgcolor;
|
||||||
|
static int inpub_id;
|
||||||
|
static const char *TAG = "mug";
|
||||||
|
|
||||||
static void mqtt_pub_request_cb(void *arg, err_t result) {
|
static void mqtt_pub_request_cb(void *arg, err_t result) {
|
||||||
if(result != ERR_OK) {
|
if(result != ERR_OK) {
|
||||||
@@ -45,15 +45,16 @@ static void mqtt_pub_request_cb(void *arg, err_t result) {
|
|||||||
* @brief Publishes data
|
* @brief Publishes data
|
||||||
* Publishes the names of all the .bmp and .gif files on the topic getImageList
|
* Publishes the names of all the .bmp and .gif files on the topic getImageList
|
||||||
*/
|
*/
|
||||||
static void example_publish(mqtt_client_t *client, void *arg) {
|
static void publish_data(mqtt_client_t *client, void *arg) {
|
||||||
LOG_INFO(TAG, "Entering publish");
|
|
||||||
char pub_payload[200];
|
char pub_payload[200];
|
||||||
err_t err;
|
err_t err;
|
||||||
|
size_t max_files = 20;
|
||||||
|
size_t num_files;
|
||||||
|
llfs_file_t file_list[max_files];
|
||||||
u8_t qos = 2;
|
u8_t qos = 2;
|
||||||
u8_t retain = 1 ;
|
u8_t retain = 1 ;
|
||||||
size_t max_files = 20;
|
|
||||||
llfs_file_t file_list[max_files];
|
LOG_DEBUG(TAG, "Entering publish");
|
||||||
size_t num_files;
|
|
||||||
|
|
||||||
num_files = llfs_file_list(file_list, max_files, "*.bmp");
|
num_files = llfs_file_list(file_list, max_files, "*.bmp");
|
||||||
|
|
||||||
@@ -94,8 +95,8 @@ static void example_publish(mqtt_client_t *client, void *arg) {
|
|||||||
* @brief Handles incoming publish
|
* @brief Handles incoming publish
|
||||||
* Callback function for when data was published to a subscribed topic
|
* Callback function for when data was published to a subscribed topic
|
||||||
*/
|
*/
|
||||||
static void mqtt_incoming_publish_cb(void *arg, const char *topic, u32_t tot_len) {
|
static void mqtt_incoming_publish_cb(void *arg, const char *topic, uint32_t tot_len) {
|
||||||
LOG_INFO(TAG, "Incoming publish at topic %s with total length %u", topic, (unsigned int)tot_len);
|
LOG_DEBUG(TAG, "Incoming publish at topic %s with total length %u", topic, (unsigned int)tot_len);
|
||||||
//check for which topic a publish was received
|
//check for which topic a publish was received
|
||||||
if (strcmp(topic, "input/setText") == 0) {
|
if (strcmp(topic, "input/setText") == 0) {
|
||||||
inpub_id = 0;
|
inpub_id = 0;
|
||||||
@@ -115,8 +116,9 @@ static void mqtt_incoming_publish_cb(void *arg, const char *topic, u32_t tot_len
|
|||||||
* @brief Handles incoming publish data
|
* @brief Handles incoming publish data
|
||||||
* Handles the recieved data from a publish to a subscribed topic
|
* Handles the recieved data from a publish to a subscribed topic
|
||||||
*/
|
*/
|
||||||
static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t flags) {
|
static void mqtt_incoming_data_cb(void *arg, const uint8_t *data, uint16_t len, uint8_t flags) {
|
||||||
char data_buffer[len + 1];
|
char data_buffer[len + 1];
|
||||||
|
|
||||||
LOG_INFO(TAG, "Incoming publish payload with length %d, flags %u", len, (unsigned int)flags);
|
LOG_INFO(TAG, "Incoming publish payload with length %d, flags %u", len, (unsigned int)flags);
|
||||||
if (flags & MQTT_DATA_FLAG_LAST) {
|
if (flags & MQTT_DATA_FLAG_LAST) {
|
||||||
memcpy(data_buffer, data, len);
|
memcpy(data_buffer, data, len);
|
||||||
@@ -165,8 +167,9 @@ static void mqtt_sub_request_cb(void *arg, err_t result) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection_status_t status) {
|
static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection_status_t status) {
|
||||||
LOG_INFO(TAG, "entered connection cb function");
|
|
||||||
err_t err;
|
err_t err;
|
||||||
|
|
||||||
|
LOG_INFO(TAG, "entered connection cb function");
|
||||||
if (status == MQTT_CONNECT_ACCEPTED) {
|
if (status == MQTT_CONNECT_ACCEPTED) {
|
||||||
LOG_INFO(TAG, "mqtt_connection_cb: Successfully connected");
|
LOG_INFO(TAG, "mqtt_connection_cb: Successfully connected");
|
||||||
|
|
||||||
@@ -180,20 +183,21 @@ static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection
|
|||||||
}
|
}
|
||||||
|
|
||||||
//publish list of images here
|
//publish list of images here
|
||||||
example_publish(client, NULL);
|
publish_data(client, NULL);
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO(TAG, "mqtt_connection_cb: Disconnected, reason: %d", status);
|
LOG_INFO(TAG, "mqtt_connection_cb: Disconnected, reason: %d", status);
|
||||||
|
|
||||||
//try to reconnect
|
//try to reconnect
|
||||||
example_do_connect(client);
|
mosquitto_connect(client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void example_do_connect(mqtt_client_t *client) {
|
static void mosquitto_connect(mqtt_client_t *client) {
|
||||||
LOG_INFO(TAG, "testing the connection");
|
|
||||||
struct mqtt_connect_client_info_t ci;
|
struct mqtt_connect_client_info_t ci;
|
||||||
err_t err;
|
err_t err;
|
||||||
|
|
||||||
|
LOG_INFO(TAG, "testing the connection");
|
||||||
|
|
||||||
memset(&ci, 0, sizeof(ci));
|
memset(&ci, 0, sizeof(ci));
|
||||||
|
|
||||||
ci.client_id = "lwip_test";
|
ci.client_id = "lwip_test";
|
||||||
@@ -219,12 +223,13 @@ void mug_init(void) {
|
|||||||
mqtt_client_t *client = mqtt_client_new();
|
mqtt_client_t *client = mqtt_client_new();
|
||||||
if (client != NULL) {
|
if (client != NULL) {
|
||||||
LOG_INFO(TAG, "Starting connection test");
|
LOG_INFO(TAG, "Starting connection test");
|
||||||
example_do_connect(client);
|
mosquitto_connect(client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t color_picker(char* color) {
|
uint32_t color_picker(char* color) {
|
||||||
uint32_t output = LCD_BLACK;
|
uint32_t output = LCD_BLACK;
|
||||||
|
|
||||||
if (strcmp((const char*)color, "blue") == 0) {
|
if (strcmp((const char*)color, "blue") == 0) {
|
||||||
output = LCD_BLUE;
|
output = LCD_BLUE;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user