The software for Ed's Composter is written entirely in C using the Events and Services framework which provides the infrastructure needed to execute the the state machines and that control our smart product.
State Machines
ComposterFSM
ComposterFSM is the state machine that controls the bulk of the composter functions. This FSM has three states: Welcome, Composting, and Emptying. In the welcome state the FSM is not doing much, it is mostly just waiting for inputs. Once the start button is pressed it goes into composting mode, which is the busiest state of the FSM. Here the FSM is responding to timeouts, user inputs, updating the display, and driving the aerator motor. The final state is Emptying, which is when the composter opens the floor to release its contents. This state is very simple: it only responds to timeouts to to drive the motor. The composter is busy while emptying; it can register no other interactions.
LEDFSM
LEDFSM is the state machine that controls writing characters to the display. It has two states: Idling and Updating. The FSM typically sits in Idling, waiting for one of two events to be posted: ES_NEW_KEY and ES_NEW_DOT. ES_NEW_KEY kicks of the process of writing a character to the dot-matrix display, calling functions from the DM_Display HAL. The FSM is put into the updating state as it writes the charcter to the display row by row. Once all of the rows have been updated, the FSM returns to Idling. The ES_NEW_DOT event has a more simple output since there are not multiple rows to update; it calls the appropriate DM_Display functions and stays in Idling, ready to recieve new events.
Services
StringService
String service is a simple service that writes strings to the display by posting events to LEDFSM. An ES_INIT event is posted to it everytime a new string is to be printed. In response, it uses getter functions written in ComposterFSM to retrieve the string that it is printing, the length of that string, and start a timer. Then at every timeout of the timer it posts a character to LEDFSM, writing the string at a speed of one charcter per timer length. Once the entire string is written, the service resets and is ready to print again.
DebounceService
DebounceService debounces the buttons. After an initial button press it uses a timer to acknowladge that a specific button was pressed for some amount of time. This function is used in the button event checkers in EventCheckers.c to limit any buttons to posting one event per press.
Event Checkers
EventCheckers
EventCheckers houses the majority of the event checkers for the composter. Inside EventCheckers we check for keystrokes, start/compostable/noncompostable buttons, and beam breaks.
CheckADPotEvents
CheckADPotEvents houses the event checker for the potentiometer, posting a POT_CHANGE event whenever the potentiometer values changes.
Framework Files
main.c
The main.c module houses the initial hardware setup for the composter as well as kicks off the initialization and run of the framework.
ES_Configure.h
ES_Configure.h houses the declarations of used services, events, eventcheckers, distribution lists, and timers for the framework.
Hardware Abstraction Layers
DM_Display
The DM_Display HAL simplifies the process of updating the dot-matrix display.
PIC32_SPI
The PIC32_SPI HAL simplifies the process of setting up the PIC32 to use SPI protocols.
PWM_PIC32
The PWM_PIC32 HAL simplifies the process of controlling motors with PWM.
Libraries
PIC32_AD_Lib
The PIC32_AD_Lib is a library which enables the use of analog inputs with the PIC32.
FontStuff
The FontStuff library is a module which easiliy enables the translation from keyboard characters to the commands needed to write those characters to the dot-matrix display.