Compare commits
	
		
			4 commits
		
	
	
		
			main
			...
			smart-meet
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 790f176d51 | |||
| 132aa86d89 | |||
| bbb6278c51 | |||
| ac4213de4d | 
					 3 changed files with 156 additions and 31 deletions
				
			
		| 
						 | 
				
			
			@ -22,4 +22,6 @@ lib_deps = siwats/ESPMegaPROR3@^1.3.0
 | 
			
		|||
           seithan/Easy Nextion Library@^1.0.6
 | 
			
		||||
           robtillaart/FRAM_I2C@^0.6.1
 | 
			
		||||
           esphome/ESPAsyncWebServer-esphome@^3.1.0
 | 
			
		||||
           bblanchon/ArduinoJson@^6.21.3
 | 
			
		||||
monitor_speed = 115200
 | 
			
		||||
monitor_port = COM26
 | 
			
		||||
| 
						 | 
				
			
			@ -1,20 +1,85 @@
 | 
			
		|||
#include <user_code.hpp>
 | 
			
		||||
 | 
			
		||||
//Timer Components
 | 
			
		||||
ESPMega_Timer timer1(0, 50, timer1_callback, 15001);
 | 
			
		||||
char MEETING_STATE_REPORT_TOPIC[75];
 | 
			
		||||
char MEETING_STATE_REQUEST_TOPIC[75];
 | 
			
		||||
char MEETING_ROOM_NAME[50] = "Meeting Room 04";
 | 
			
		||||
 | 
			
		||||
StaticJsonDocument<2048> meeting_info;
 | 
			
		||||
#define TOTAL_SLOT 22 // max init cycle 17
 | 
			
		||||
uint8_t selected_slot = 1;
 | 
			
		||||
uint8_t cycle_slot_start = 1;
 | 
			
		||||
uint8_t slot_hours[TOTAL_SLOT + 1] = {8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19};
 | 
			
		||||
uint8_t slot_minutes[TOTAL_SLOT + 1] = {0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0, 30, 0};
 | 
			
		||||
// Display Componets
 | 
			
		||||
#define elcd ESPMega_EXTLCD
 | 
			
		||||
// Link with Dual state button object with id 2 on page 1 named bt0
 | 
			
		||||
NexDSButton bt0 = NexDSButton(1, 2, "bt0");
 | 
			
		||||
NexPicture lt_bt = NexPicture(1, 1, "lt_bt");
 | 
			
		||||
NexPicture av_bt = NexPicture(1, 3, "av_bt");
 | 
			
		||||
NexButton left_bt = NexButton(1, 5, "left_bt");
 | 
			
		||||
NexButton right_bt = NexButton(1, 6, "right_bt");
 | 
			
		||||
NexPicture slot1 = NexPicture(1, 7, "slot1");
 | 
			
		||||
NexPicture slot2 = NexPicture(1, 8, "slot2");
 | 
			
		||||
NexPicture slot3 = NexPicture(1, 9, "slot3");
 | 
			
		||||
NexPicture slot4 = NexPicture(1, 10, "slot4");
 | 
			
		||||
NexPicture slot5 = NexPicture(1, 11, "slot5");
 | 
			
		||||
 | 
			
		||||
// Lights on 0,1,2,3,4,5
 | 
			
		||||
// A/V on 6
 | 
			
		||||
 | 
			
		||||
// List of Component ID Message to listen to
 | 
			
		||||
NexTouch *nex_listen_list[] =
 | 
			
		||||
    {
 | 
			
		||||
        &bt0,
 | 
			
		||||
        <_bt,
 | 
			
		||||
        &av_bt,
 | 
			
		||||
        &slot1,
 | 
			
		||||
        &slot2,
 | 
			
		||||
        &slot3,
 | 
			
		||||
        &slot4,
 | 
			
		||||
        &slot5,
 | 
			
		||||
        &left_bt,
 | 
			
		||||
        &right_bt,
 | 
			
		||||
        NULL};
 | 
			
		||||
 | 
			
		||||
void bt0PopCallback(void *ptr)
 | 
			
		||||
bool light_group_state()
 | 
			
		||||
{
 | 
			
		||||
    pwm_toggle(2);
 | 
			
		||||
    for (int i = 0; i <= 5; i++)
 | 
			
		||||
    {
 | 
			
		||||
        if (pwm_get_state(i))
 | 
			
		||||
            return true;
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void lt_bt_cb(void *ptr)
 | 
			
		||||
{
 | 
			
		||||
    Serial.println("ltcb");
 | 
			
		||||
    bool state = !light_group_state();
 | 
			
		||||
    for (int i = 0; i++; i <= 5)
 | 
			
		||||
        pwm_set_state(i, state);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void av_bt_cb(void *ptr)
 | 
			
		||||
{
 | 
			
		||||
    Serial.println("avcb");
 | 
			
		||||
    pwm_toggle(3);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void left_bt_cb(void *ptr)
 | 
			
		||||
{
 | 
			
		||||
    Serial.println("leftcb");
 | 
			
		||||
    if(cycle_slot_start>0){
 | 
			
		||||
        cycle_slot_start--;
 | 
			
		||||
        write_time_slot();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void right_bt_cb(void *ptr)
 | 
			
		||||
{
 | 
			
		||||
    Serial.println("rightcb");
 | 
			
		||||
    if(cycle_slot_start<TOTAL_SLOT-5){
 | 
			
		||||
        cycle_slot_start++;
 | 
			
		||||
        write_time_slot();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			@ -24,6 +89,10 @@ Peripheral Initialization Routine
 | 
			
		|||
void user_pre_init()
 | 
			
		||||
{
 | 
			
		||||
    nexInit();
 | 
			
		||||
    memcpy(MEETING_STATE_REPORT_TOPIC, MQTT_BASE_TOPIC, 20);
 | 
			
		||||
    strcat(MEETING_STATE_REPORT_TOPIC, "/meeting/report");
 | 
			
		||||
    memcpy(MEETING_STATE_REQUEST_TOPIC, MQTT_BASE_TOPIC, 20);
 | 
			
		||||
    strcat(MEETING_STATE_REQUEST_TOPIC, "/meeting/request");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			@ -31,12 +100,13 @@ This code will run after every component is initialized
 | 
			
		|||
*/
 | 
			
		||||
void user_init()
 | 
			
		||||
{
 | 
			
		||||
    timer1.begin();
 | 
			
		||||
    ESPMega_EXTLCD.print("page home");
 | 
			
		||||
    ESPMega_EXTLCD.write(0xFF);
 | 
			
		||||
    ESPMega_EXTLCD.write(0xFF);
 | 
			
		||||
    ESPMega_EXTLCD.write(0xFF);
 | 
			
		||||
    bt0.attachPop(bt0PopCallback, &bt0);
 | 
			
		||||
    send_stop_bit();
 | 
			
		||||
    ESPMega_EXTLCD.print("page dashboard");
 | 
			
		||||
    send_stop_bit();
 | 
			
		||||
    left_bt.attachPop(left_bt_cb, &left_bt);
 | 
			
		||||
    right_bt.attachPop(right_bt_cb, &right_bt);
 | 
			
		||||
    lt_bt.attachPop(lt_bt_cb, <_bt);
 | 
			
		||||
    av_bt.attachPop(av_bt_cb, &av_bt);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			@ -56,10 +126,31 @@ void virtual_interrupt_user_callback(int pin, int state)
 | 
			
		|||
 | 
			
		||||
void pwm_changed_user_callback(int pin)
 | 
			
		||||
{
 | 
			
		||||
    if (pin == 2)
 | 
			
		||||
    if (pin >= 0 && pin <= 5)
 | 
			
		||||
    {
 | 
			
		||||
        // inform the lcd when pwm 2 changed
 | 
			
		||||
        bt0.setValue(pwm_get_state(2));
 | 
			
		||||
        if (light_group_state())
 | 
			
		||||
        {
 | 
			
		||||
            elcd.write("lt_bt.pic=6");
 | 
			
		||||
            send_stop_bit();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            elcd.write("lt_bt.pic=5");
 | 
			
		||||
            send_stop_bit();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else if (pin == 6)
 | 
			
		||||
    {
 | 
			
		||||
        if (pwm_get_state(6))
 | 
			
		||||
        {
 | 
			
		||||
            elcd.write("av_bt.pic=8");
 | 
			
		||||
            send_stop_bit();
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            elcd.write("av_bt.pic=7");
 | 
			
		||||
            send_stop_bit();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -68,28 +159,51 @@ This code will run every 15 seconds
 | 
			
		|||
*/
 | 
			
		||||
void timer_tick_callback()
 | 
			
		||||
{
 | 
			
		||||
    if (standalone)
 | 
			
		||||
    {
 | 
			
		||||
        timer1.loop();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void timer1_callback()
 | 
			
		||||
void ac_changed_user_callback(int mode, int temperature, int fan_speed)
 | 
			
		||||
{
 | 
			
		||||
    for (int i = 0; i < 16; i++)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void meeting_state_callback(String topic, String payload)
 | 
			
		||||
{
 | 
			
		||||
    DeserializationError error = deserializeJson(meeting_info, payload);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void mqtt_connected_user_callback()
 | 
			
		||||
{
 | 
			
		||||
    mqtt.subscribe(MEETING_STATE_REPORT_TOPIC, meeting_state_callback);
 | 
			
		||||
    mqtt.publish(MEETING_STATE_REQUEST_TOPIC, "request");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void user_state_request_callback()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void write_time_slot()
 | 
			
		||||
{
 | 
			
		||||
    for (int i = 1; i <= 5; i++)
 | 
			
		||||
    {
 | 
			
		||||
        pwm_set_state(i, 1);
 | 
			
		||||
        elcd.printf("slot%d_time.txt=%02d:%02d\n%02d:%02d", i, slot_hours[cycle_slot_start + i - 1],
 | 
			
		||||
                    slot_minutes[cycle_slot_start + i - 1], slot_hours[cycle_slot_start + i],
 | 
			
		||||
                    slot_minutes[cycle_slot_start + i]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ac_changed_user_callback(int mode, int temperature, int fan_speed) {
 | 
			
		||||
    
 | 
			
		||||
void send_stop_bit()
 | 
			
		||||
{
 | 
			
		||||
    ESPMega_EXTLCD.write(0xFF);
 | 
			
		||||
    ESPMega_EXTLCD.write(0xFF);
 | 
			
		||||
    ESPMega_EXTLCD.write(0xFF);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void mqtt_connected_user_callback() {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void user_state_request_callback() {
 | 
			
		||||
 | 
			
		||||
uint8_t get_current_time_slot()
 | 
			
		||||
{
 | 
			
		||||
    rtctime_t curtime = ESPMega_getTime();
 | 
			
		||||
    for(uint8_t i=0;i<=TOTAL_SLOT;i++) {
 | 
			
		||||
        if(slot_hours[i]>curtime.hours || (slot_hours[i]==curtime.hours && slot_minutes[i]>curtime.hours)) {
 | 
			
		||||
            return i;
 | 
			
		||||
        }
 | 
			
		||||
    } 
 | 
			
		||||
    return 255;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -3,6 +3,7 @@
 | 
			
		|||
#include <Nextion.h>
 | 
			
		||||
#include <PubSubClient.h>
 | 
			
		||||
#include <PubSubClientTools.h>
 | 
			
		||||
#include <ArduinoJson.h>
 | 
			
		||||
#include "espmega_iot_timer.hpp"
 | 
			
		||||
#include "espmega_iot_external_lcd.hpp"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -41,6 +42,14 @@ void timer1_callback();
 | 
			
		|||
void mqtt_connected_user_callback();
 | 
			
		||||
void bt0PopCallback(void *ptr);
 | 
			
		||||
void user_state_request_callback();
 | 
			
		||||
void meeting_state_callback(String topic, String payload);
 | 
			
		||||
void send_stop_bit();
 | 
			
		||||
void write_time_slot();
 | 
			
		||||
void av_bt_cb(void *ptr);
 | 
			
		||||
void lt_bt_cb(void *ptr);
 | 
			
		||||
void left_bt_cb(void *ptr);
 | 
			
		||||
void right_bt_cb(void *ptr);
 | 
			
		||||
extern char MQTT_BASE_TOPIC[];
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// ESPMega IoT Core Build-in Functions
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue