AWS IoT Firmware
Firmware code for AWS IoT Devices
Files | Classes | Macros | Functions
Speaker Controller

Files

file  speaker_ctrl_handler.cpp
 implemntation file for speaker handler
 
file  speaker_ctrl_handler.hpp
 header file for speaker handler
 

Classes

class  SpeakerCtrlHandler
 

Macros

#define SUBSCRIBE_TOPIC   "/speakerReq"
 topic that the speaker controller subscribe to
 
#define PUBLISH_TOPIC   "/speakerRes"
 topic that the speaker controller will publish replies to
 
#define SPKR_PWR_PIN   14
 pins for controlling the power source to the speaker, probably controlling through a relay instead of directly to the speaker
 
#define SPKR_PWR_ON_STATE   1
 the state of the power control pin if the speaker is powered on
 
#define SPKR_INC_PIN   5
 pins that interact witht the INC pin of the digital pot, negative edge on this pin will move the digital pot wiper
 
#define SPKR_DIR_PIN   4
 pins that controls the DIR pin of the digital pot, used for controlling whether the negative edge on the INC pin result in increase or decrease in resistance
 
#define SPKR_SELECT_PIN   12
 pin that controls the CS line of the digital pot, the digital pot will only changes its resistance if the CS pin is active
 
#define VOLUME_UP_LIMIT   100
 Max possible volume set by the user.
 
#define VOLUME_DOWN_LIMIT   0
 Min possible volume set by the user.
 
#define SPKR_VOLUME_DELAY_MS   1
 delay between toggling the INC pin to make sure the edge is registered by the digital pot
 
#define SPKR_INC_ACTIVATED_STATE   0
 the state that the INC pin is activated, the pin triggers on negative edge so its activated state is low
 
#define SPKR_PIN_UP_STATE   1
 the state of the pin that controls the DIR pin of the digital pot when the pot is in moving up resistance mode
 
#define SPKR_SELECT_ACTIVATED   0
 the state of the pin that controls the CS pin of the digital pot when the pot is activated
 
#define SPKR_VOL_LEVEL_INPUT_PIN   0
 pins for sensing analog voltage of the physical pot
 
#define SPKR_VOL_LEVEL_INPUT_THRESHOLD   15
 minimum change in adc voltage before it's considered that the user moved the pot
 
#define SPKR_VOL_LEVEL_MAX_COUNT   1024
 max value returned by the adc read function of mongoose
 
#define SPKR_PWR_INPUT_PIN   13
 pins for sensing user turning on/off the speaker using the physical pot
 
#define SPKR_PWR_INPUT_OFF_STATE   1
 the state the the input pin will be at if it's off, since it's pulled up so the off state will be one
 
#define REGISTER_INTERRUPT()
 dummy function, interrupts are registered in the handler constructor for this device More...
 
#define TOTAL_HANDLER   1
 device only needs to handle speaker type interface
 
#define SPKR_HANDLER_INDEX   0
 index of the pointer to the speaker handler
 
#define INITIALIZE_HANDLER()
 initialize list of handler More...
 

Functions

void handlePolling (struct mg_connection *mgCon, ParentHandler *handlerList[], char *jsonBuf)
 poll the voltage on the potentiometer and change the volume if there is a change in voltage More...
 
static void SpeakerCtrlHandler::pwrInputIntHandler (int pin, void *arg)
 handler function for when the user turn on/off the physical pot on the speaker This function will either turn on/off the speaker based on the user interaction with the physical potentiometer More...
 
 SpeakerCtrlHandler::SpeakerCtrlHandler (void)
 Construct a new Speaker Ctrl Handler:: Speaker Ctrl Handler object create a new spekaer handler, intialize the namespace argument, prepare analog, and interrupt pins, set speaker to mute.
 
HandlerError SpeakerCtrlHandler::handleRequest (struct mg_connection *mgCon, struct mg_str *message, char *commandName, char *response)
 function to handle request passed by aws mqtt Depending on the reques type, the handler will either mute the device, adjust volume or set new volume entirely More...
 
HandlerError SpeakerCtrlHandler::handleReport (char *stateReport)
 handle preparing report for the speaker handler used when the handler needs to respond to the , will report whether the speaker is muted and what the volume is More...
 
void SpeakerCtrlHandler::checkPotVoltage (void)
 called by the main polling function to check and update the pot voltage if necessary read the adc voltage and if the voltage changes over a certain threshold, which indicates that the user has moved the pot, then the volume will be adjusted accordingly
 

Detailed Description

Macro Definition Documentation

#define INITIALIZE_HANDLER ( )
Value:
static SpeakerCtrlHandler spkrController; \
static ParentHandler* _handlerList[TOTAL_HANDLER] = {&spkrController};
Definition: speaker_ctrl_handler.hpp:26
#define TOTAL_HANDLER
device only needs to handle speaker type interface
Definition: device_config.hpp:151
the parent handler class that is the blueprint for other child handlers to implement, it also defines a couple functions that child handler can use
Definition: parent_handler.hpp:31

initialize list of handler

#define REGISTER_INTERRUPT ( )
Value:
do { \
} while (0)

dummy function, interrupts are registered in the handler constructor for this device

Register an interrupt before handling any events, usually you would register interrupt inside the constructor of the handler but this is provided to register interrupt early in the program if needed

Function Documentation

void handlePolling ( struct mg_connection *  mgCon,
ParentHandler handlerList[],
char *  jsonBuf 
)

poll the voltage on the potentiometer and change the volume if there is a change in voltage

dummy empty function since bed room light controller has no polling need

Parameters
mgConobject representing connection to the internet
_handlerListthe list of handler that user defined
jsonBufif you write something to this buffer, it will be published to the mqtt server of the device
HandlerError SpeakerCtrlHandler::handleReport ( char *  stateReport)
virtual

handle preparing report for the speaker handler used when the handler needs to respond to the , will report whether the speaker is muted and what the volume is

Parameters
stateReportthe buffer to write the report to
Returns
HandlerError return problem error

Implements ParentHandler.

HandlerError SpeakerCtrlHandler::handleRequest ( struct mg_connection *  mgCon,
struct mg_str *  message,
char *  commandName,
char *  response 
)
virtual

function to handle request passed by aws mqtt Depending on the reques type, the handler will either mute the device, adjust volume or set new volume entirely

Parameters
mgConmongoose OS connection to the internet
messagemessage received by mongoose OS
commandNamethe command extracted from the message
responsethe buffer to write the response to, which will be published to the mqtt response server
Returns
HandlerError return errors reported by function inside the handler

Implements ParentHandler.

void SpeakerCtrlHandler::pwrInputIntHandler ( int  pin,
void *  arg 
)
static

handler function for when the user turn on/off the physical pot on the speaker This function will either turn on/off the speaker based on the user interaction with the physical potentiometer

Parameters
pinthe pin that triggered the handler
argpointer to things passed by mongoose OS to the handler, in this case, the pointer to the speaker handler is registered to be the argument passed