mirror of
https://github.com/korneliuszo/lumiax-controller.git
synced 2026-03-28 19:22:33 +01:00
ON/OFF switch
This commit is contained in:
23
scripts/onoff.py
Executable file
23
scripts/onoff.py
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import tlay2_client
|
||||
import struct
|
||||
|
||||
def send_onoff(state):
|
||||
a=tlay2_client.Tlay2_msg(1)
|
||||
a.msg(struct.pack("?",state))
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser(description='Control power')
|
||||
|
||||
group = parser.add_mutually_exclusive_group()
|
||||
group.add_argument('-0', '--on', action='store_true')
|
||||
group.add_argument('-1', '--off', action='store_true')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.on:
|
||||
send_onoff(True)
|
||||
if args.off:
|
||||
send_onoff(False)
|
||||
@@ -61,7 +61,7 @@ void bt_enabled(int err)
|
||||
barrot_init();
|
||||
}
|
||||
|
||||
#define DISPLAY_STACK_SIZE 500
|
||||
#define DISPLAY_STACK_SIZE 1000
|
||||
K_THREAD_STACK_DEFINE(display_stack_area, DISPLAY_STACK_SIZE);
|
||||
struct k_thread display_thread_data;
|
||||
|
||||
@@ -153,12 +153,11 @@ int main(void)
|
||||
}
|
||||
|
||||
uint16_t onoff;
|
||||
if(modbus_read_holding_regs(client_iface, 1, 0x902C, &onoff,1)!=0)
|
||||
if(modbus_read_input_regs(client_iface, 1, 0x3035, &onoff,1)!=0)
|
||||
{
|
||||
printt("Read fail3");
|
||||
continue;
|
||||
}
|
||||
printt("%d", onoff);
|
||||
k_mutex_lock(®_data.mut, K_FOREVER);
|
||||
reg_data.d.b_soc = holding_reg[0];
|
||||
reg_data.d.b_v = holding_reg[1];
|
||||
@@ -167,7 +166,7 @@ int main(void)
|
||||
reg_data.d.l_a = holding_reg[6];
|
||||
reg_data.d.s_v = holding_reg[9];
|
||||
reg_data.d.s_a = holding_reg[10];
|
||||
reg_data.d.on = onoff == 0;
|
||||
reg_data.d.on = (onoff&1) == 1;
|
||||
k_mutex_unlock(®_data.mut);
|
||||
k_sem_give(®_data.new_sample);
|
||||
printt("Read ok");
|
||||
|
||||
@@ -37,6 +37,7 @@ extern Tlay2<128> tlay2;
|
||||
|
||||
extern Display display;
|
||||
|
||||
extern int client_iface;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -96,7 +96,8 @@ public:
|
||||
ret = uart.Init();
|
||||
if(!ret)
|
||||
return ret;
|
||||
k_thread_create(&rx_thread,rx_stack, rx_stack_size,rx_thread_c,this,NULL,NULL,5,0,K_NO_WAIT);
|
||||
k_tid_t tid = k_thread_create(&rx_thread,rx_stack, rx_stack_size,rx_thread_c,this,NULL,NULL,5,0,K_NO_WAIT);
|
||||
k_thread_name_set(tid,"Tlay2");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
11
src/uart.cpp
11
src/uart.cpp
@@ -1,7 +1,8 @@
|
||||
#include "main_modules.hpp"
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/modbus/modbus.h>
|
||||
|
||||
K_KERNEL_STACK_DEFINE(tlay2_stack,300);
|
||||
K_KERNEL_STACK_DEFINE(tlay2_stack,1000);
|
||||
|
||||
|
||||
void process_packet(Tlay2<128>* obj, uint8_t*data,size_t len);
|
||||
@@ -18,6 +19,14 @@ void process_packet(Tlay2<128>* obj, uint8_t*data,size_t len)
|
||||
obj->tx_byte(data[i]);
|
||||
obj->tx_end();
|
||||
break;
|
||||
case 1: // set power
|
||||
{
|
||||
int ret = modbus_write_coil(client_iface, 1, 0x0000, !data[2]);
|
||||
obj->tx_init_reply();
|
||||
obj->tx_u32(ret);
|
||||
obj->tx_end();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user