Skip to content

Commit

Permalink
adc CLI command
Browse files Browse the repository at this point in the history
(cherry picked from commit a8821b8)
  • Loading branch information
Miceuz committed Feb 19, 2013
1 parent a93cde1 commit d84f011
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ OBJS += cmd_chibi_addr.o cmd_chibi_tx.o
OBJS += cmd_i2ceeprom_read.o cmd_i2ceeprom_write.o cmd_lm75b_gettemp.o
OBJS += cmd_reset.o cmd_sd_dir.o cmd_sysinfo.o cmd_uart.o
OBJS += cmd_roundedcorner.o cmd_pwm.o
OBJS += cmd_adc.o

VPATH += project/commands/drawing
OBJS += cmd_backlight.o cmd_bmp.o cmd_button.o cmd_calibrate.o
Expand Down
4 changes: 3 additions & 1 deletion project/cmd_tbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ void cmd_sd_dir(uint8_t argc, char **argv);
void cmd_pwm(uint8_t argc, char **argv);
#endif

void cmd_adc_read(uint8_t argc, char **argv);

#define CMD_NOPARAMS "This command has no parameters"

/**************************************************************************/
Expand All @@ -114,7 +116,7 @@ cmd_t cmd_tbl[] =
{ "?", 0, 0, 0, cmd_help , "Help" , CMD_NOPARAMS },
{ "V", 0, 0, 0, cmd_sysinfo , "System Info" , CMD_NOPARAMS },
{ "Z", 0, 0, 0, cmd_reset , "Reset" , CMD_NOPARAMS },

{ "adc", 1, 2, 0, cmd_adc_read , "ADC read" , "adc <channel> <num reads>" },
#ifdef CFG_I2CEEPROM
{ "e", 1, 1, 0, cmd_i2ceeprom_read , "EEPROM Read" , "'e <addr>'" },
{ "w", 2, 2, 0, cmd_i2ceeprom_write , "EEPROM Write" , "'w <addr> <val>'" },
Expand Down
78 changes: 78 additions & 0 deletions project/commands/cmd_adc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**************************************************************************/
/*!
@file cmd_sysinfo.c
@author Miceuz
@brief Code to execute for cmd_sysinfo in the 'core/cmd'
command-line interpretter.
@section LICENSE
Software License Agreement (BSD License)
Copyright (c) 2012, microBuilder SARL
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**************************************************************************/
#include <stdio.h>

#include "projectconfig.h"
#include "core/cmd/cmd.h"
#include "project/commands.h" // Generic helper functions

#include "core/adc/adc.h"

/**************************************************************************/
/*!
PWM command handler
*/
/**************************************************************************/

void cmd_adc_read(uint8_t argc, char **argv) {
int32_t channel = 0;
int32_t numReads = 1;

getNumber (argv[0], &channel);
if(channel < 0)
{
printf("Invalid duty channel, only channels [0..2] avalable%s", CFG_PRINTF_NEWLINE);
return;
}

if(argc > 1) {
getNumber (argv[1], &numReads);
if(numReads < 1)
{
printf("Invalid number of reads [1..65535]%s", CFG_PRINTF_NEWLINE);
return;
}
}
adcInit();
int i = 0;
for(i = 0; i < numReads; i++) {
uint32_t result = adcReadSingle(channel);
printf("%d%s", (uint16_t)result, CFG_PRINTF_NEWLINE);
}
}

0 comments on commit d84f011

Please sign in to comment.