ammolytics / projects

Source code and instructions for do-it-yourself projects.
https://blog.ammolytics.com
MIT License
52 stars 20 forks source link

Mock interface does not work #43

Closed alien2108 closed 1 year ago

alien2108 commented 4 years ago

https://github.com/ammolytics/projects/blob/c9a3dc6b3b893de39ef160e6f5b9179b719764e2/trickler/peripheral/lib/mock-scale.js#L165

/home/pi/trickler/peripheral/lib/mock-scale.js:165 this._unit = trickler.TricklerUnits.GRAINS ^ TypeError: Cannot read property 'GRAINS' of undefined at new MockScale (/home/pi/trickler/peripheral/lib/mock-scale.js:165:41) at new SerialPort (/home/pi/trickler/peripheral/node_modules/@serialport/stream/lib/index.js:145:19)

Indeed nowhere in code TricklerUnits is even defined:

pi@raspberrypi:~/trickler/peripheral/lib $ grep TricklerUnits * grep: build: Is a directory mock-scale.js: this._unit = trickler.TricklerUnits.GRAINS mock-scale.js: this._unit = trickler.TricklerUnits.GRAINS === this._unit ? trickler.TricklerUnits.GRAMS : trickler.TricklerUnits.GRAINS mock-scale.js: case trickler.TricklerUnits.GRAINS: mock-scale.js: case trickler.TricklerUnits.GRAMS:

erichiggins commented 4 years ago

This is my fault. I added this mock interface so the developer who helped create the mobile app had something to work with (because they don't own a scale). I have not maintained the mock interface, so I'm not entirely surprised that it broke.

I've been rethinking the workflow though, so I'd like to hear your thoughts.

Right now, Bluetooth doesn't advertise unless the scale is working. Seemed like a good idea at the time, but now I think it causes more confusion than it prevents. I think I might change that -- advertise on BT and just surface the scale status to app so users know where the issue is.

Additionally, there are other brands/models of scales that folks would like to use instead. To make it easier to develop a new scale adapter, I might write a generic/boilerplate one that simply logs whatever it reads from the serial port and has stubs that can be filled in to make it functional.

Neither of these solve the mock scale being broken, of course. I'm wondering if it's still needed or useful if I made the two changes suggested above.

alien2108 commented 4 years ago

I would rather suggest you do the following:

Basically all you display on bluetooth phone I would like to display on a simple Pi Zero Display HAT as https://www.waveshare.com/wiki/1.44inch_LCD_HAT

It has joystick (up/down +-1gr, left/right +-0.1gr), three buttons (1 - get default weight, 2 - set default weight, 3 ...) and a cool display. No bluetooth, no phone...

I tried to implement it, but your code currently is too interlinked with bluetooth.

erichiggins commented 4 years ago

I see. Does this relate to the mock scale issue somehow? If you're not planning on using Bluetooth, then this falls a bit further outside of the Open Trickler intended design.

Since it's an open source project, you're welcome to fork and modify the code to meet your use case. A lot of folks have different design ideas that they share with me, but I cannot commit to writing several different versions of this project to support them.

We have a lot of folks discussing their designs and ideas over on Discord. Perhaps you can discuss it there and get some support from the community!

erichiggins commented 1 year ago

Closing this out since the code has changed significantly.