|
|
|
@ -63,6 +63,7 @@ export struct AutoMode {
|
|
|
|
|
|
|
|
|
|
|
|
refreshData() {
|
|
|
|
refreshData() {
|
|
|
|
this.isLoading = true;
|
|
|
|
this.isLoading = true;
|
|
|
|
|
|
|
|
this.fetchSunRiseTime(() => {
|
|
|
|
// 1. Get Mode
|
|
|
|
// 1. Get Mode
|
|
|
|
this.m9zService.getDeviceMode({
|
|
|
|
this.m9zService.getDeviceMode({
|
|
|
|
onSuccess: (mode: number): void => {
|
|
|
|
onSuccess: (mode: number): void => {
|
|
|
|
@ -75,10 +76,11 @@ export struct AutoMode {
|
|
|
|
this.getTasksForMode(this.selectedViewMode);
|
|
|
|
this.getTasksForMode(this.selectedViewMode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
getTasksForMode(modeIndex: number) {
|
|
|
|
getTasksForMode(modeIndex: number) {
|
|
|
|
this.isLoading = true;
|
|
|
|
// this.isLoading = true; // Already loading
|
|
|
|
|
|
|
|
|
|
|
|
// 1. Start Task
|
|
|
|
// 1. Start Task
|
|
|
|
this.m9zService.getTask(M9zCmd.StartTask, modeIndex, {
|
|
|
|
this.m9zService.getTask(M9zCmd.StartTask, modeIndex, {
|
|
|
|
@ -120,24 +122,37 @@ export struct AutoMode {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fetchSunRiseTime() {
|
|
|
|
fetchSunRiseTime(callback?: () => void) {
|
|
|
|
|
|
|
|
console.info('AutoMode: Fetching SunRiseTime...');
|
|
|
|
this.m9zService.getSunRiseTime({
|
|
|
|
this.m9zService.getSunRiseTime({
|
|
|
|
onSuccess: (data: SunRiseTimeData): void => {
|
|
|
|
onSuccess: (data: SunRiseTimeData): void => {
|
|
|
|
|
|
|
|
console.info(`AutoMode: fetchSunRiseTime success. Sunrise: ${data.sunrise}, Sunset: ${data.sunset}`);
|
|
|
|
if (data.sunrise) this.sunriseTime = this.formatTimeOnly(data.sunrise);
|
|
|
|
if (data.sunrise) this.sunriseTime = this.formatTimeOnly(data.sunrise);
|
|
|
|
if (data.sunset) this.sunsetTime = this.formatTimeOnly(data.sunset);
|
|
|
|
if (data.sunset) this.sunsetTime = this.formatTimeOnly(data.sunset);
|
|
|
|
this.isLoading = false;
|
|
|
|
console.info(`AutoMode: Updated times - Sunrise: ${this.sunriseTime}, Sunset: ${this.sunsetTime}`);
|
|
|
|
|
|
|
|
// this.isLoading = false; // Don't stop loading here
|
|
|
|
|
|
|
|
if (callback) callback();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onError: (err: string): void => {
|
|
|
|
onError: (err: string): void => {
|
|
|
|
this.isLoading = false;
|
|
|
|
console.error('AutoMode: fetchSunRiseTime failed:', err);
|
|
|
|
|
|
|
|
// this.isLoading = false; // Don't stop loading here
|
|
|
|
|
|
|
|
if (callback) callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
formatTimeOnly(date: Date): string {
|
|
|
|
formatTimeOnly(date: Date): string {
|
|
|
|
|
|
|
|
console.info('AutoMode: formatTimeOnly input:', date);
|
|
|
|
|
|
|
|
try {
|
|
|
|
const h = String(date.getHours()).padStart(2, '0');
|
|
|
|
const h = String(date.getHours()).padStart(2, '0');
|
|
|
|
const min = String(date.getMinutes()).padStart(2, '0');
|
|
|
|
const min = String(date.getMinutes()).padStart(2, '0');
|
|
|
|
const s = String(date.getSeconds()).padStart(2, '0');
|
|
|
|
const s = String(date.getSeconds()).padStart(2, '0');
|
|
|
|
return `${h}:${min}:${s}`;
|
|
|
|
const result = `${h}:${min}:${s}`;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
console.error('AutoMode: formatTimeOnly error:', e);
|
|
|
|
|
|
|
|
return '00:00:00';
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
changeViewMode(index: number) {
|
|
|
|
changeViewMode(index: number) {
|
|
|
|
@ -159,7 +174,7 @@ export struct AutoMode {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Compiler Logic
|
|
|
|
// Compiler Logic
|
|
|
|
compileTask(task: ControlTask): TaskProgram {
|
|
|
|
compileTask(task: ControlTask, isMiddle: boolean = false): TaskProgram {
|
|
|
|
const instructions: TaskInstruction[] = [];
|
|
|
|
const instructions: TaskInstruction[] = [];
|
|
|
|
|
|
|
|
|
|
|
|
// 1. Time Instruction
|
|
|
|
// 1. Time Instruction
|
|
|
|
@ -188,7 +203,15 @@ export struct AutoMode {
|
|
|
|
if (true) { // Always generate instruction if we have time
|
|
|
|
if (true) { // Always generate instruction if we have time
|
|
|
|
const ins1: TaskInstruction = new TaskInstruction();
|
|
|
|
const ins1: TaskInstruction = new TaskInstruction();
|
|
|
|
ins1.type = 0x01;
|
|
|
|
ins1.type = 0x01;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (isMiddle) {
|
|
|
|
|
|
|
|
// Middle Task: Timer=0x05, Sun=0x04
|
|
|
|
|
|
|
|
ins1.param = task.timeType === 0 ? 0x05 : 0x04;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Start/Stop Task: Timer=0x01, Sun=0x02
|
|
|
|
ins1.param = task.timeType === 0 ? 0x01 : 0x02;
|
|
|
|
ins1.param = task.timeType === 0 ? 0x01 : 0x02;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ins1.value = minutes;
|
|
|
|
ins1.value = minutes;
|
|
|
|
instructions.push(ins1);
|
|
|
|
instructions.push(ins1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -251,7 +274,7 @@ export struct AutoMode {
|
|
|
|
// Sort tasks by time? The user should ensure order, simplified here.
|
|
|
|
// Sort tasks by time? The user should ensure order, simplified here.
|
|
|
|
|
|
|
|
|
|
|
|
tasks.forEach((task: ControlTask) => {
|
|
|
|
tasks.forEach((task: ControlTask) => {
|
|
|
|
const prog: TaskProgram = this.compileTask(task);
|
|
|
|
const prog: TaskProgram = this.compileTask(task, true);
|
|
|
|
prog.instructions.forEach((ins: TaskInstruction) => { allInstructions.push(ins); });
|
|
|
|
prog.instructions.forEach((ins: TaskInstruction) => { allInstructions.push(ins); });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
@ -471,6 +494,8 @@ export struct AutoMode {
|
|
|
|
TaskItem({
|
|
|
|
TaskItem({
|
|
|
|
title: '开始任务',
|
|
|
|
title: '开始任务',
|
|
|
|
task: this.startTask,
|
|
|
|
task: this.startTask,
|
|
|
|
|
|
|
|
sunriseTime: this.sunriseTime,
|
|
|
|
|
|
|
|
sunsetTime: this.sunsetTime,
|
|
|
|
onEdit: (): void => { this.openEditDialog('start', -1); }
|
|
|
|
onEdit: (): void => { this.openEditDialog('start', -1); }
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -480,6 +505,8 @@ export struct AutoMode {
|
|
|
|
TaskItem({
|
|
|
|
TaskItem({
|
|
|
|
title: `中间任务 ${index+1}`,
|
|
|
|
title: `中间任务 ${index+1}`,
|
|
|
|
task: task,
|
|
|
|
task: task,
|
|
|
|
|
|
|
|
sunriseTime: this.sunriseTime,
|
|
|
|
|
|
|
|
sunsetTime: this.sunsetTime,
|
|
|
|
onEdit: (): void => { this.openEditDialog('middle', index); },
|
|
|
|
onEdit: (): void => { this.openEditDialog('middle', index); },
|
|
|
|
isDeletable: true,
|
|
|
|
isDeletable: true,
|
|
|
|
onDelete: (): void => { this.deleteMiddleTask(index); }
|
|
|
|
onDelete: (): void => { this.deleteMiddleTask(index); }
|
|
|
|
@ -500,6 +527,8 @@ export struct AutoMode {
|
|
|
|
TaskItem({
|
|
|
|
TaskItem({
|
|
|
|
title: '结束任务',
|
|
|
|
title: '结束任务',
|
|
|
|
task: this.stopTask,
|
|
|
|
task: this.stopTask,
|
|
|
|
|
|
|
|
sunriseTime: this.sunriseTime,
|
|
|
|
|
|
|
|
sunsetTime: this.sunsetTime,
|
|
|
|
onEdit: (): void => { this.openEditDialog('stop', -1); }
|
|
|
|
onEdit: (): void => { this.openEditDialog('stop', -1); }
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -571,7 +600,14 @@ export struct AutoMode {
|
|
|
|
Button('经纬度时间')
|
|
|
|
Button('经纬度时间')
|
|
|
|
.backgroundColor(this.editingTask.timeType === 1 ? '#22fdc8' : '#333')
|
|
|
|
.backgroundColor(this.editingTask.timeType === 1 ? '#22fdc8' : '#333')
|
|
|
|
.fontColor(this.editingTask.timeType === 1 ? '#000' : '#fff')
|
|
|
|
.fontColor(this.editingTask.timeType === 1 ? '#000' : '#fff')
|
|
|
|
.onClick(() => { this.editingTask.timeType = 1; })
|
|
|
|
.onClick(() => {
|
|
|
|
|
|
|
|
this.editingTask.timeType = 1;
|
|
|
|
|
|
|
|
if (this.editingTaskType === 'start' && this.sunsetTime !== '--:--:--') {
|
|
|
|
|
|
|
|
this.editingTask.execTime = this.sunsetTime.substring(0, 5);
|
|
|
|
|
|
|
|
} else if (this.editingTaskType === 'stop' && this.sunriseTime !== '--:--:--') {
|
|
|
|
|
|
|
|
this.editingTask.execTime = this.sunriseTime.substring(0, 5);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
.height(30).fontSize(12)
|
|
|
|
.height(30).fontSize(12)
|
|
|
|
}.width('100%').justifyContent(FlexAlign.Start)
|
|
|
|
}.width('100%').justifyContent(FlexAlign.Start)
|
|
|
|
|
|
|
|
|
|
|
|
@ -607,6 +643,10 @@ export struct AutoMode {
|
|
|
|
.margin({left: 10}).fontSize(12).height(30).backgroundColor('#2d3a51')
|
|
|
|
.margin({left: 10}).fontSize(12).height(30).backgroundColor('#2d3a51')
|
|
|
|
.fontColor('#22fdc8').border({width:1, color: '#22fdc8'})
|
|
|
|
.fontColor('#22fdc8').border({width:1, color: '#22fdc8'})
|
|
|
|
}.width('100%').justifyContent(FlexAlign.Start)
|
|
|
|
}.width('100%').justifyContent(FlexAlign.Start)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Text('执行时间').fontColor('#b2ebf2').margin({top: 15, bottom: 5}).alignSelf(ItemAlign.Start).fontSize(14)
|
|
|
|
|
|
|
|
Text(this.editingTask.execTime)
|
|
|
|
|
|
|
|
.fontColor('#22fdc8').fontSize(16).margin({top: 5})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 3. Loop Selection
|
|
|
|
// 3. Loop Selection
|
|
|
|
@ -691,10 +731,21 @@ export struct AutoMode {
|
|
|
|
struct TaskItem {
|
|
|
|
struct TaskItem {
|
|
|
|
@Prop title: string;
|
|
|
|
@Prop title: string;
|
|
|
|
@ObjectLink task: ControlTask;
|
|
|
|
@ObjectLink task: ControlTask;
|
|
|
|
|
|
|
|
@Prop sunriseTime: string = '--:--:--';
|
|
|
|
|
|
|
|
@Prop sunsetTime: string = '--:--:--';
|
|
|
|
onEdit: () => void = () => {};
|
|
|
|
onEdit: () => void = () => {};
|
|
|
|
@Prop isDeletable: boolean = false;
|
|
|
|
@Prop isDeletable: boolean = false;
|
|
|
|
onDelete: () => void = () => {};
|
|
|
|
onDelete: () => void = () => {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
getDisplayTime(): string {
|
|
|
|
|
|
|
|
const rawTime = (this.task.execTime.includes(' ') ? this.task.execTime.split(' ')[1] : this.task.execTime).substring(0, 5);
|
|
|
|
|
|
|
|
if (this.task.timeType === 1) {
|
|
|
|
|
|
|
|
if (this.title === '开始任务' && this.sunsetTime !== '--:--:--') return this.sunsetTime.substring(0, 5);
|
|
|
|
|
|
|
|
if (this.title === '结束任务' && this.sunriseTime !== '--:--:--') return this.sunriseTime.substring(0, 5);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return rawTime;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
build() {
|
|
|
|
build() {
|
|
|
|
Column() {
|
|
|
|
Column() {
|
|
|
|
Row() {
|
|
|
|
Row() {
|
|
|
|
@ -705,7 +756,7 @@ struct TaskItem {
|
|
|
|
.fontSize(10)
|
|
|
|
.fontSize(10)
|
|
|
|
.fontColor('#aaa')
|
|
|
|
.fontColor('#aaa')
|
|
|
|
.alignSelf(ItemAlign.End)
|
|
|
|
.alignSelf(ItemAlign.End)
|
|
|
|
Text((this.task.execTime.includes(' ') ? this.task.execTime.split(' ')[1] : this.task.execTime).substring(0, 5))
|
|
|
|
Text(this.getDisplayTime())
|
|
|
|
.fontColor('#fff')
|
|
|
|
.fontColor('#fff')
|
|
|
|
.alignSelf(ItemAlign.End)
|
|
|
|
.alignSelf(ItemAlign.End)
|
|
|
|
.onAppear(() => {
|
|
|
|
.onAppear(() => {
|
|
|
|
|