Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
trade: Fixes, features, and improvements
This commit wraps up a number of changes that aim to improve the trade process, its robustness, add some features, and fix some bugs. Change list in rough order of importance: Better pattern matching of incoming data for each trade step, provides more robust logic during trading and more correctly sync's states between the Flipper and gameboy. Fixes #20 as a side effect. Implement trade patch list. This allows for the Flipper to both send and receive patch data. The patch list is used by Pokemon to patch what is considered to be a NO_DATA_BYTE (e.g. data from the follower was not yet ready) with another byte, and then track that byte's index. The other side then restores that byte to what it should be. Fixes #18 Ability for the Flipper to correctly receive the Pokemon traded to it and put that Pokemon in the Flipper's trade buffer. This allows for trading back and forth (e.g. in the case of a Pokemon that evolves with trade, trading to the Flipper and back will trigger an evolution on the Gameboy), as well as the following feature. Ability for the Flipper to back out of the trade menu, modify the current Pokemon, and re-enter the trade menu without having to completely reset the Gameboy and re-enter the Cable Club. Fixes #19 Completely isolates Trade's context and scope. The _alloc() function now returns an anonymous pointer that means nothing to the rest of the application. However, this does require a bit of juggling as the main application is responsible for setting up the View at the start. Adds a huge comment block in the trade source outlining the current understanding of the actual trade data protocol. Also adds specific comments for more context specific details through various trade states. Changes to how the draw callback is called. In order to correctly update the canvas during the actual trading with a graphic and LED changed every 250 ms, the timer to call the update was changed to only run every 250 ms. However, Flipper OS does not guarantee that this is the only draw update call, and may issue a draw update at any time. The view model now tracks what the LED state should be, and our timed update routine callback is the only place this LED state is toggled. This forces the trade animation to always be sync'ed correctly no matter how often the Flipper OS calls it. Clean up state tracking overall. There are now two states that are tracked, the Gameboy/link state, and the actual trade states. The Gameboy state still has a bit of overlap with the trade states, however, it combines what was the link state in to this. This also allows elimination of additional bools that were used for state tracking in parallel. State transitions and meanings should now be a bit more straightforward. CLK pin now implements an interrupt on either edge. The ISR was updated to shift data out on the falling edge, and read data in on the rising edge. This eliminates any need for delays while in an interrupt context as well as mimics Gameboy behavior by matching the setup/hold times. Remove use of magic numbers as much as possible. Bytes to/from the Pokemon game now use macros for most of the bytes. Many of these were pulled from https://github.com/pret/pokered defines. Clean up cycle counter to real-time maths. Copied general paradigms from Flipper onewire code. This also includes the bit counter timeout and now ensures correct timeouts are measured between transmitted bytes.
- Loading branch information