Files
mqtt-rc/main/bsp.h

180 lines
4.6 KiB
C

/* MQTT (over TCP) Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#ifndef BSP_FINISTRC
#define BSP_FINISTRC
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include "esp_wifi.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "esp_event.h"
#include "esp_netif.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "freertos/queue.h"
#include "freertos/portmacro.h"
#include "lwip/sockets.h"
#include "lwip/dns.h"
#include "lwip/netdb.h"
#include "esp_log.h"
#include "mqtt_client.h"
#include "esp_err.h"
#include "wifi.h"
#include "mqttHandler.h"
#include "loop.h"
//static const char *TAG = "mqtt_example";
//#define GPIO_OUTPUT_IO_0 CONFIG_GPIO_OUTPUT_0
//#define GPIO_OUTPUT_IO_1 CONFIG_GPIO_OUTPUT_1
//#define GPIO_OUTPUT_PIN_SEL ((1ULL<<GPIO_OUTPUT_IO_0) | (1ULL<<GPIO_OUTPUT_IO_1))
//configuration pins section
#include "driver/gpio.h"
#define TYPE (36)
#define IN1 (39)
#define CONF1 (22)
#define CONF2 (21)
#define CONF3 (19)
#define CONF4 (18)
#define CONF5 (5)
#define CONF6 (17)
#define CONF7 (16)
#define CONF8 (4)
#define CONF9 (2)
#define M1A (25)
#define M1B (32)
#define M2A (27)
#define M2B (26)
#define GPIO_INPUT_PIN_SEL ((1ULL<<TYPE) | (1ULL<<IN1) | (1ULL<<CONF1) | (1ULL<<CONF2) | (1ULL<<CONF3) | (1ULL<<CONF4) | (1ULL<<CONF5) | (1ULL<<CONF6) | (1ULL<<CONF7) | (1ULL<<CONF8) | (1ULL<<CONF9))
//end of configuration pins section
//addressable LED section
#include "driver/rmt_tx.h"
//#include "led_strip_encoder.h"
#define RMT_LED_STRIP_RESOLUTION_HZ 10000000 // 10MHz resolution, 1 tick = 0.1us (led strip needs a high resolution)
#define RMT_LED_STRIP_GPIO_NUM 0
#define EXAMPLE_LED_NUMBERS 24
extern uint8_t led_strip_pixels[EXAMPLE_LED_NUMBERS * 3];
//end of addressable LED section
//motor section
#include "driver/ledc.h"
#define LEDC_HS_TIMER LEDC_TIMER_0
#define LEDC_HS_MODE LEDC_HIGH_SPEED_MODE
#define LEDC_HS_CH0_GPIO (25)
#define LEDC_HS_CH0_CHANNEL LEDC_CHANNEL_0
#define LEDC_HS_CH1_GPIO (32)
#define LEDC_HS_CH1_CHANNEL LEDC_CHANNEL_1
#define LEDC_LS_TIMER LEDC_TIMER_1
#define LEDC_LS_MODE LEDC_LOW_SPEED_MODE
#define LEDC_LS_CH2_GPIO (27)
#define LEDC_LS_CH2_CHANNEL LEDC_CHANNEL_2
#define LEDC_LS_CH3_GPIO (26)
#define LEDC_LS_CH3_CHANNEL LEDC_CHANNEL_3
#define MOTOR_MAX_VALUE 1023
#define SEUIL_MOTEUR 200
#define LEDC_TEST_CH_NUM (4)
#define LEDC_TEST_DUTY (4000)
#define LEDC_TEST_FADE_TIME (3000)
//end of motor section
//adc section
#include "esp_adc/adc_oneshot.h"
//#include "esp_adc/adc_cali.h"
//#include "esp_adc/adc_cali_scheme.h"
#define BATT_ADC ADC_CHANNEL_5
#define THR_ADC ADC_CHANNEL_6
#define DIR_ADC ADC_CHANNEL_7
#define EXAMPLE_ADC_ATTEN ADC_ATTEN_DB_11
//end of adc section
//FinistRC section
// URL des broker, pour l'instant ce sont les memes
#define CONFIG_BROKER_URL_BATEAU "mqtt://openwrt.lan"
#define CONFIG_BROKER_URL_VOITURE "mqtt://openwrt.lan"
#define DEFAULT_TIMER_VALUE 180 // 3 minutes = 180 secondes
#define TRANSMIT_PERIOD_INTERVAL 100 // 100 millisecondes entre les trames
#define SIZE_TOPIC 25 // longueur des noms des topic
#define TOPIC_TIMER_BATEAU "/B/timer"
typedef enum {
BATEAU,
RADIO_BATEAU,
VOITURE,
RADIO_VOITURE,
STARTER_VOITURE,
STARTER_BATEAU
} model_t;
typedef enum {
BATEAU_RECEIVING,
BATEAU_SLEEP
} state_bateau_t;
typedef enum {
RADIO_BATEAU_TRANSMITTING,
RADIO_BATEAU_SLEEP
} state_radio_bateau_t;
typedef enum {
VOITURE_RECEIVING,
VOITURE_SLEEP
} state_voiture_t;
typedef enum {
RADIO_VOITURE_TRANSMITTING,
RADIO_VOITURE_SLEEP
} state_radio_voiture_t;
extern model_t QUISUISJE;
extern int idModele;
extern int idGroup;
extern networkType_t networkType;
extern state_bateau_t state_bateau;
extern state_radio_bateau_t state_radio_bateau;
extern state_voiture_t state_voiture;
extern state_radio_voiture_t state_radio_voiture;
extern int timerGlobal;
extern bool voitureGO;
extern bool bateauGO;
extern int dataReceived,gazReceived,dirReceived;
extern esp_mqtt_client_handle_t clientMqtt;
// End of FinistRC section
void boardInit(void);
void initWS2812(void);
void initMotor(void);
void initAdc(void);
void setMotor(uint32_t speedA, bool directionA,uint32_t speedB, bool directionB);
void getBatt(int *value);
void getDir(int *value);
void getThr(int *value);
#endif