feat: edit value & send to brew
- edited value is now sent to brew Signed-off-by: pakintada@gmail.com <Pakin>
This commit is contained in:
parent
dc327e7779
commit
4cb98f8672
7 changed files with 141 additions and 4 deletions
|
|
@ -326,7 +326,7 @@
|
|||
<Sheet.Header>
|
||||
<Sheet.Title>Value Editor</Sheet.Title>
|
||||
<Sheet.Description>
|
||||
Make changes to current order of material. Click save when you're done.
|
||||
Make changes to current order of material. Click <b>Apply</b> when you're done editing.
|
||||
</Sheet.Description>
|
||||
</Sheet.Header>
|
||||
|
||||
|
|
@ -606,6 +606,7 @@
|
|||
<!-- <Button variant="outline" type="button" onclick={() => (sheetOpenState = false)}
|
||||
>{warnUserNotSaveChange ? 'Discard Changes' : 'Cancel'}</Button
|
||||
> -->
|
||||
<Field.Description></Field.Description>
|
||||
</Field.Field>
|
||||
</Field.Group>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -267,6 +267,35 @@
|
|||
console.log('topping applying', topping_change);
|
||||
currentToppings[getToppingSlot()] = topping_change;
|
||||
} else {
|
||||
console.log('apply change on recipelist value', key);
|
||||
|
||||
if (key.startsWith('powder')) {
|
||||
if (key.endsWith('gram')) {
|
||||
powder.gram = parseInt(value[key]);
|
||||
} else if (key.endsWith('time')) {
|
||||
powder.time = parseInt(value[key]);
|
||||
}
|
||||
} else if (key.startsWith('syrup')) {
|
||||
if (key.endsWith('gram')) {
|
||||
syrup.gram = parseInt(value[key]);
|
||||
} else if (key.endsWith('time')) {
|
||||
syrup.time = parseInt(value[key]);
|
||||
}
|
||||
} else if (key.startsWith('water')) {
|
||||
if (key.endsWith('yield')) {
|
||||
water.yield = parseInt(value[key]);
|
||||
} else if (key.endsWith('cold')) {
|
||||
water.cold = parseInt(value[key]);
|
||||
}
|
||||
} else if (key.startsWith('feed')) {
|
||||
if (key.endsWith('pattern')) {
|
||||
feed.pattern = parseInt(value[key]);
|
||||
} else if (key.endsWith('parameter')) {
|
||||
feed.parameter = parseInt(value[key]);
|
||||
}
|
||||
} else if (key == 'stir_time') {
|
||||
stir_time = parseInt(value[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,6 +88,34 @@
|
|||
// get(currentEditingRecipeProductCode)
|
||||
// );
|
||||
|
||||
console.log('accepting changes');
|
||||
let current_data_to_brew =
|
||||
ready_to_send_brew.length == 0 ? $state.snapshot(currentData) : ready_to_send_brew.shift();
|
||||
|
||||
if (
|
||||
new_topping_value_for_save != undefined &&
|
||||
new_topping_value_for_save != null &&
|
||||
new_topping_value_for_save.length > 0
|
||||
) {
|
||||
current_data_to_brew['ToppingSet'] = new_topping_value_for_save;
|
||||
} else if (
|
||||
topping_value_for_revert != undefined &&
|
||||
topping_value_for_revert != null &&
|
||||
topping_value_for_revert.length > 0
|
||||
) {
|
||||
current_data_to_brew['ToppingSet'] = topping_value_for_revert;
|
||||
}
|
||||
|
||||
// if (current_data_to_brew['ToppingSet'].length == 0) {
|
||||
// // rollback if empty
|
||||
// current_data_to_brew['ToppingSet'] = topping_value_for_revert;
|
||||
// }
|
||||
|
||||
// apply changes now
|
||||
let new_change = applyChangeToRecipeForBrewing(latest_event, current_data_to_brew);
|
||||
|
||||
ready_to_send_brew.push(new_change);
|
||||
|
||||
callback_revert_value_if_not_save = (save: any) => {
|
||||
if (!save) {
|
||||
latestRecipeToppingData.set(topping_value_for_revert);
|
||||
|
|
@ -136,16 +164,77 @@
|
|||
//
|
||||
}
|
||||
|
||||
function getRecipeListKeyName(name: string) {
|
||||
switch (name) {
|
||||
case 'powder_gram':
|
||||
return 'powderGram';
|
||||
case 'powder_time':
|
||||
return 'powderTime';
|
||||
case 'syrup_gram':
|
||||
return 'syrupGram';
|
||||
case 'syrup_time':
|
||||
return 'syrupTime';
|
||||
case 'water_cold':
|
||||
return 'waterCold';
|
||||
case 'water_yield':
|
||||
return 'waterYield';
|
||||
case 'feed_parameter':
|
||||
return 'FeedParameter';
|
||||
case 'feed_pattern':
|
||||
return 'FeedPattern';
|
||||
case 'stir_time':
|
||||
return 'stirTime';
|
||||
default:
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
function applyChangeToRecipeForBrewing(latest_event: any, current_data_to_brew: any) {
|
||||
console.log('applyChangeToRecipeForBrewing', Object.keys(latest_event?.payload));
|
||||
|
||||
let changes = latest_event?.payload.change;
|
||||
|
||||
let apply_to_index = latest_event?.index;
|
||||
let apply_to_keys = Object.keys(changes);
|
||||
|
||||
console.log('applying', apply_to_index, apply_to_keys, current_data_to_brew['recipes'].length);
|
||||
|
||||
console.log('topping before apply', current_data_to_brew['ToppingSet']);
|
||||
for (const key of apply_to_keys) {
|
||||
if (key == 'toppings') {
|
||||
current_data_to_brew['ToppingSet'][apply_to_index - 1] = changes[key][apply_to_index - 1];
|
||||
console.log('applying topping', apply_to_index - 1);
|
||||
} else {
|
||||
// get actual key
|
||||
|
||||
current_data_to_brew['recipes'][apply_to_index][getRecipeListKeyName(key)] = parseInt(
|
||||
changes[key]
|
||||
);
|
||||
console.log('applying ', key, current_data_to_brew['recipes'][apply_to_index]);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('topping after apply', current_data_to_brew['ToppingSet']);
|
||||
|
||||
return current_data_to_brew;
|
||||
}
|
||||
|
||||
async function sendBrewNow() {
|
||||
try {
|
||||
while (ready_to_send_brew.length > 1) {
|
||||
ready_to_send_brew.shift();
|
||||
}
|
||||
|
||||
console.log('sending brewing payload', ready_to_send_brew);
|
||||
|
||||
await sendToAndroid({
|
||||
type: 'brew',
|
||||
payload: {
|
||||
start: new Date().toLocaleTimeString(),
|
||||
// use this field for unchanged data
|
||||
target: ready_to_send_brew.length == 1 ? '-' : currentData.productCode,
|
||||
target: ready_to_send_brew.length >= 1 ? '-' : currentData.productCode,
|
||||
// use this field for new or modified data
|
||||
data: ready_to_send_brew.length == 1 ? ready_to_send_brew[0][1] : null
|
||||
data: ready_to_send_brew.length >= 1 ? ready_to_send_brew[0] : {}
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
|
|
|
|||
|
|
@ -223,11 +223,20 @@ async function connectToAndroidServer() {
|
|||
console.warn('adb instance not found');
|
||||
return;
|
||||
}
|
||||
|
||||
await push('/sdcard/coffeevending/enable_adb_block_watch', '1');
|
||||
|
||||
const stream = await inst.transport.connect(env.PUBLIC_BREW_CONN_PORT);
|
||||
const writer = stream.writable.getWriter();
|
||||
const reader = stream.readable.getReader();
|
||||
|
||||
console.log('checking on writer ', writer);
|
||||
adbWriter.set(writer);
|
||||
if (writer) {
|
||||
addNotification('INFO:Enable Brewing Mode T on machine');
|
||||
} else {
|
||||
addNotification('WARN:Brewing Mode T unavailable');
|
||||
}
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
|
|
@ -240,10 +249,12 @@ async function connectToAndroidServer() {
|
|||
console.error('read error', e);
|
||||
} finally {
|
||||
adbWriter.set(null);
|
||||
addNotification('WARN:Brewing Mode T Offline ...');
|
||||
}
|
||||
})();
|
||||
} catch (err) {
|
||||
console.error('Connection failed. Suspect java running or not', err);
|
||||
addNotification('ERR:Fail to enable brewing mode T');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,6 +34,8 @@ async function handleAdbPayload(raw_payload: string) {
|
|||
let next = states[1].replace('MACHINE_STATE_', '');
|
||||
|
||||
console.log('current state', curr, 'next state', next);
|
||||
|
||||
addNotification('INFO:Machine Status Updated, ' + next);
|
||||
}
|
||||
break;
|
||||
case 'error':
|
||||
|
|
|
|||
|
|
@ -51,6 +51,11 @@ export function sendMessage(msg: OutMessage): boolean {
|
|||
console.warn('WebSocket not connected, put to queue');
|
||||
|
||||
let currentQueue = get(queue);
|
||||
if (currentQueue.length >= 10) {
|
||||
while (currentQueue.length >= 10) {
|
||||
currentQueue.shift();
|
||||
}
|
||||
}
|
||||
currentQueue.push(data);
|
||||
queue.set(currentQueue);
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ async function sendToAndroid(message: any) {
|
|||
const encoder = new TextEncoder();
|
||||
console.log(writer);
|
||||
await writer.write(encoder.encode(JSON.stringify(message) + '\n'));
|
||||
console.log('sent!');
|
||||
console.log('sent! ', JSON.stringify(message));
|
||||
} catch (error) {
|
||||
console.error('write failed', error);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue