[Armadeus-commitlog] armadeus branch, master, updated. armadeus-5.0-68-gbc1a898
Brought to you by:
sszy
|
From: jscheer <js...@us...> - 2012-10-02 14:52:52
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "armadeus".
The branch, master has been updated
via bc1a898b4580ff793a0b85953bdb7445f43ec569 (commit)
from a5a94697f443e1a2df4cffe398262478c677fa60 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit bc1a898b4580ff793a0b85953bdb7445f43ec569
Author: Jeremie Scheer <jer...@ar...>
Date: Tue Oct 2 16:52:11 2012 +0200
[PACKAGES][AS_DEVICES] Test scripts for backlight, eeprom and PWM C++ wrappers.
-----------------------------------------------------------------------
Summary of changes:
target/packages/as_devices/main.c | 3 +
target/packages/as_devices/test_c.h | 53 ++++
target/packages/as_devices/test_cpp.h | 454 ++++++++++++++++++++++++++++++++-
3 files changed, 507 insertions(+), 3 deletions(-)
diff --git a/target/packages/as_devices/main.c b/target/packages/as_devices/main.c
index fb778fd..b0debbf 100644
--- a/target/packages/as_devices/main.c
+++ b/target/packages/as_devices/main.c
@@ -45,6 +45,7 @@ int main(int argc, char ** argv)
printf(" 6) max1027\n");
printf(" 7) max5821\n");
printf(" 8) as1531\n");
+ printf(" 9) backlight\n");
printf("> ");
scanf("%s",buffer);
@@ -66,6 +67,8 @@ int main(int argc, char ** argv)
break;
case '8' : test_as1531();
break;
+ case '9' : test_backlight();
+ break;
default : break;
}
}
diff --git a/target/packages/as_devices/test_c.h b/target/packages/as_devices/test_c.h
index 6300126..3f9d8aa 100644
--- a/target/packages/as_devices/test_c.h
+++ b/target/packages/as_devices/test_c.h
@@ -30,6 +30,7 @@
#include "as_max5821.h"
#include "as_adc.h"
#include "as_dac.h"
+#include "as_backlight.h"
#include "as_helpers.h"
#define PWM_NUM 0
@@ -816,3 +817,55 @@ void test_as1531(void)
pressEnterToContinue();
}
+/* Backlight test */
+void test_backlight(void)
+{
+ int ret;
+ char buffer[20];
+ char buffer2[20];
+ int value;
+ struct as_backlight_device *backlight_dev;
+
+ backlight_dev = as_backlight_open();
+ if(backlight_dev == NULL){
+ printf("can't init backlight\n");
+ pressEnterToContinue();
+ return;
+ }
+ while(buffer[0] != 'q')
+ {
+ system("clear");
+ printf("*********************************\n");
+ printf("* Testing backlight menu *\n");
+ printf("*********************************\n");
+ printf("Choose ('q' to quit):\n");
+ printf(" 1) get actual brightness\n");
+ printf(" 2) get maximum brightness\n");
+ printf(" 3) set brightness\n");
+ printf("> ");
+ scanf("%s",buffer);
+
+ switch(buffer[0])
+ {
+ case '1' : printf("Actual brightness is %d\n",
+ as_backlight_get_actual_brightness(backlight_dev));
+ pressEnterToContinue();
+ break;
+ case '2' : printf("Maximum brightness is %d\n",
+ as_backlight_get_max_brightness(backlight_dev));
+ pressEnterToContinue();
+ break;
+ case '3' : printf("Give brightness :");
+ scanf("%d",&value);
+ as_backlight_set_brightness(backlight_dev,value);
+ pressEnterToContinue();
+ break;
+ default : break;
+ }
+ }
+ ret = as_backlight_close(backlight_dev);
+ if(ret < 0){
+ printf("can't close backlight\n");
+ return;
+ }
+}
diff --git a/target/packages/as_devices/test_cpp.h b/target/packages/as_devices/test_cpp.h
index 1814075..a3c0be1 100644
--- a/target/packages/as_devices/test_cpp.h
+++ b/target/packages/as_devices/test_cpp.h
@@ -23,12 +23,16 @@
#include <stdlib.h>
#include <iostream>
#include <limits>
+#include <math.h>
#include "as_i2c.hpp"
#include "as_gpio.hpp"
#include "as_adc.hpp"
#include "as_dac.hpp"
#include "as_spi.hpp"
+#include "as_pwm.hpp"
+#include "as_93lcxx.hpp"
+#include "as_backlight.hpp"
#define _STR(x) #x
@@ -438,15 +442,459 @@ void test_max5821()
/* PWM test */
void test_pwm(void)
{
- printf("TODO\n");
- pressEnterToContinue();
+ AsPwm *pwm_dev = NULL;
+ int ret;
+ char buffer[20];
+ char buffer2[20];
+ int value;
+ int devNumber = 0;
+ int initialized = 0;
+
+ while(buffer[0] != 'q')
+ {
+ system("clear");
+ printf("**************************\n");
+ printf(" Testing PWM *\n");
+ printf("**************************\n");
+ printf("Choose ('q' to quit):\n");
+
+ if (initialized == 0)
+ {
+ printf(" 1) Open PWM device\n");
+ printf(" 2) Change device number (%i)\n", devNumber);
+ }
+ else
+ {
+ printf(" 1) Close PWM device\n");
+ printf(" 2) Set Frequency\n");
+ printf(" 3) Get Frequency\n");
+ printf(" 4) Set Period\n");
+ printf(" 5) Get Period\n");
+ printf(" 6) Set Duty\n");
+ printf(" 7) Get Duty\n");
+ printf(" 9) Activate/desactivate\n");
+ printf(" 9) Get state\n");
+ }
+
+ printf("> ");
+ scanf("%s",buffer);
+
+ if (initialized == 0)
+ {
+ switch(buffer[0])
+ {
+ case '1' : printf("Open PWM device\n");
+ pwm_dev = new AsPwm(devNumber);
+ if (pwm_dev < 0)
+ {
+ printf("Error, can't open PWM device. Is PWM modprobed ?\n");
+ } else {
+ printf("PWM device opened\n");
+ initialized = 1;
+ }
+ pressEnterToContinue();
+ break;
+ case '2' : printf("Give device number:");
+ scanf("%i",&value);
+
+ if (value < 0)
+ {
+ printf(" Wrong value\n");
+ } else {
+ devNumber = value;
+ }
+ pressEnterToContinue();
+ default : break;
+ }
+ }
+ else
+ {
+ switch(buffer[0])
+ {
+ case '1' : printf("Close PWM device\n");
+ delete pwm_dev;
+ initialized = 0;
+ pressEnterToContinue();
+ break;
+ case '2' : printf("Give frequency: ");
+ scanf("%d",&value);
+
+ ret = pwm_dev->setFrequency(value);
+ if (ret < 0)
+ {
+ printf("Error, can't set frequency\n");
+ }
+ pressEnterToContinue();
+ break;
+
+ case '3' : ret = pwm_dev->getFrequency();
+ if (ret < 0) {
+ printf("Error reading frequency\n");
+ pressEnterToContinue();
+ break;
+ }
+ printf("Frequency read : %d\n", ret);
+ pressEnterToContinue();
+ break;
+ case '4' : printf("Give period: ");
+ scanf("%d",&value);
+
+ ret = pwm_dev->setPeriod(value);
+ if (ret < 0)
+ {
+ printf("Error, can't set period\n");
+ }
+ pressEnterToContinue();
+ break;
+
+ case '5' : ret = pwm_dev->getPeriod();
+ if (ret < 0) {
+ printf("Error reading period\n");
+ pressEnterToContinue();
+ break;
+ }
+ printf("Period read : %d\n", ret);
+ pressEnterToContinue();
+ break;
+ case '6' : printf("Give duty: ");
+ scanf("%d",&value);
+
+ ret = pwm_dev->setDuty(value);
+ if (ret < 0)
+ {
+ printf("Error, can't set duty\n");
+ }
+ pressEnterToContinue();
+ break;
+
+ case '7' : ret = pwm_dev->getDuty();
+ if (ret < 0) {
+ printf("Error reading period\n");
+ pressEnterToContinue();
+ break;
+ }
+ printf("Duty read : %d\n", ret);
+ pressEnterToContinue();
+ break;
+ case '8' : printf("Activate 'a' or Desactivate 'd' ?");
+ scanf("%s",buffer2);
+
+ if(buffer2[0] == 'a')
+ {
+ pwm_dev->setState(1);
+ printf("PWM activated\n");
+ pressEnterToContinue();
+ }
+ else if(buffer2[0] == 'd')
+ {
+ pwm_dev->setState(0);
+ printf("PWM desactivated\n");
+ pressEnterToContinue();
+ }else{
+ printf("Option %c unknown\n",buffer[0]);
+ pressEnterToContinue();
+ }
+ break;
+ case '9' : if(pwm_dev->getState())
+ {
+ printf("PWM is active\n");
+ pressEnterToContinue();
+ }
+ else
+ {
+ printf("PWM is inactive\n");
+ pressEnterToContinue();
+ }
+ break;
+ default : break;
+ }
+ }
+ }
}
/* EEPROM test */
+int address_size(int aType, int aWordSize)
+{
+ return (((aType-46)/10) + 6 + 2 - (aWordSize/8));
+}
+
+int max_address(int aType, int aWordSize)
+{
+ return (pow(2,address_size(aType, aWordSize))-1);
+}
+
void test_93LC(void)
{
- printf("TODO\n");
+ char buffer[50];
+ int i;
+
+ As93LCXX *eeprom_dev = NULL;
+ int type = 46;
+ char spidevpath[50];
+ /* defaults values */
+ int frequency = 1000000;
+ uint8_t word_size = 8;
+ int value, value2;
+ int initialized=0;
+ snprintf(spidevpath, 50, "%s", "/dev/spidev2.0");
+
+ while(buffer[0] != 'q')
+ {
+ system("clear");
+ printf("*********************************\n");
+ printf("* Testing 93LCxx menu *\n");
+ printf("*********************************\n");
+ printf("Choose ('q' to quit):\n");
+ if (initialized == 0)
+ {
+ printf(" 1) Change word size (%d)\n", word_size);
+ printf(" 2) Change bus frequency (%d)\n", frequency);
+ printf(" 3) Change eeprom type (%d)\n", type);
+ printf(" 4) Change spidev path (%s)\n", spidevpath);
+ printf(" 5) Initialize eeprom\n");
+ } else {
+ printf(" 1) Close eeprom\n");
+ printf(" 2) Read specific address\n");
+ printf(" 3) Erase specific address\n");
+ printf(" 4) Write specific address\n");
+ printf(" 5) Write all\n");
+ printf(" 6) Read all\n");
+ printf(" 7) Erase all\n");
+ printf(" 8) Unlock write\n");
+ printf(" 9) Lock write\n");
+ }
+
+ printf("> ");
+ scanf("%s",buffer);
+
+ if (initialized == 0)
+ {
+ switch(buffer[0])
+ {
+ case '1' : printf("Give new word size (8 or 16): ");
+ scanf("%d", &value);
+ if ( (value != 8) && (value != 16) )
+ {
+ printf("Wrong value\n");
+ pressEnterToContinue();
+ } else {
+ word_size = value;
+ }
+ break;
+ case '2' : printf("Give bus frequency: ");
+ scanf("%d", &value);
+ frequency = value;
+ printf("Frequency changed to %dHz\n",frequency);
+ break;
+ case '3' : printf("Give new type of eeprom (46, 56 or 66): ");
+ scanf("%d", &value);
+ if ( (value != 46) && (value != 56) && (value != 66) )
+ {
+ printf("Wrong value\n");
+ pressEnterToContinue();
+ } else {
+ type = value;
+ }
+ break;
+ case '4' : printf("Give new path for spidev: \n");
+ scanf("%s", spidevpath);
+ printf("New path is %s\n",spidevpath);
+ break;
+ case '5' : eeprom_dev = new As93LCXX((unsigned char *)spidevpath, type, frequency, word_size);
+ if (eeprom_dev < 0)
+ {
+ printf("Error, can't initialize eeprom. Have you modprobed spidev ?\n");
+ } else {
+ printf("93LCXX device initialized\n");
+ initialized = 1;
+ }
+ pressEnterToContinue();
+ break;
+ default : break;
+ }
+ } else {
+ switch(buffer[0])
+ {
+ case '1' : printf("EEPROM closed\n");
+ delete eeprom_dev;
+ initialized = 0;
+ pressEnterToContinue();
+ break;
+ case '2' : printf(" Read specific address\n");
+ printf("Give address in hexadecimal (max 0x%03X):",
+ max_address(type, word_size));
+ scanf("%x",&value);
+ if (value > max_address(type, word_size))
+ {
+ printf(" Error, wrong address\n");
+ } else {
+ value2 = eeprom_dev->read(value);
+ if (value2 < 0)
+ {
+ printf("Error, can't read value\n");
+ } else {
+ printf(" Read %02x at %02X", value2, value );
+ }
+ }
+ pressEnterToContinue();
+ break;
+ case '3' : printf("Erase specific address\n");
+ printf("Give address in hexadecimal (max 0x%03X):",
+ max_address(type, word_size));
+ scanf("%x",&value);
+ if (value > max_address(type, word_size))
+ {
+ printf(" Error, address wrong\n");
+ } else {
+ value2 = eeprom_dev->erase(value);
+ if (value2 < 0)
+ {
+ printf("Error, can't erase value\n");
+ } else {
+ printf("Value erased\n");
+ }
+ }
+ pressEnterToContinue();
+ break;
+ case '4' : printf("Write specific address\n");
+ printf("Give address in hexadecimal (max 0x%03X):",
+ max_address(type, word_size));
+ scanf("%x",&value);
+ if (value > max_address(type, word_size))
+ {
+ printf(" Error, address wrong\n");
+ pressEnterToContinue();
+ break;
+ }
+ printf("Give value in hexadecimal :");
+ scanf("%x",&value2);
+ value2 = eeprom_dev->write(value, value2);
+ if (value2 < 0)
+ {
+ printf("Error, can't write value\n");
+ }
+ pressEnterToContinue();
+ break;
+ case '5' : printf(" Write all\n");
+ printf("Give value in hexadecimal:");
+ scanf("%x",&value);
+ value2 = eeprom_dev->writeAll(value);
+ if (value2 < 0)
+ {
+ printf("Error, can't write value\n");
+ }
+ pressEnterToContinue();
+ break;
+ case '6' : printf(" Read all\n");
+ for(i = 0; i <= max_address(type, word_size); i++)
+ {
+ if (word_size == 8)
+ {
+ printf("%03X -> %02X\n",
+ i,eeprom_dev->read(i));
+ } else{
+ printf("%03X -> %04X\n",
+ i,eeprom_dev->read(i));
+ }
+ }
+ pressEnterToContinue();
+ break;
+ case '7' : printf(" Erase all\n");
+ value = eeprom_dev->eraseAll();
+ if (value < 0)
+ {
+ printf(" Error in erasing eeprom\n");
+ }
+ pressEnterToContinue();
+ break;
+ case '8' : printf("Unlock write\n");
+ if (eeprom_dev->ewen() < 0)
+ {
+ printf("Error can't unlock write\n");
+ }
+ pressEnterToContinue();
+ break;
+ case '9' : printf("lock write\n");
+ if (eeprom_dev->ewds() < 0)
+ {
+ printf("Error can't lock write\n");
+ }
+ pressEnterToContinue();
+ break;
+ default : break;
+ }
+ }
+ }
+}
+
+void test_backlight(void)
+{
+ int ret;
+ char buffer[20];
+ int value;
+ AsBacklight *backlight_dev = NULL;
+
+ backlight_dev = new AsBacklight();
+ if (backlight_dev == NULL)
+ {
+ printf("Error, can't open backlight device.\n");
+ pressEnterToContinue();
+ return ;
+ }
pressEnterToContinue();
+
+ while(buffer[0] != 'q')
+ {
+ system("clear");
+ printf("*********************************\n");
+ printf("* Testing backlight menu *\n");
+ printf("*********************************\n");
+ printf("Choose ('q' to quit):\n");
+ printf(" 1) get actual brightness\n");
+ printf(" 2) get maximum brightness\n");
+ printf(" 3) set brightness\n");
+
+ printf("> ");
+ scanf("%s",buffer);
+
+ switch(buffer[0])
+ {
+ case '1' : ret = backlight_dev->getActualBrightness();
+ if (ret < 0)
+ {
+ printf("Error reading actual brightness\n");
+ pressEnterToContinue();
+ break;
+ }
+ printf("Actual brightness is %d\n", ret);
+ pressEnterToContinue();
+ break;
+ case '2' : ret = backlight_dev->getMaxBrightness();
+ if (ret < 0)
+ {
+ printf("Error reading maximum brightness\n");
+ pressEnterToContinue();
+ break;
+ }
+ printf("Maximum brightness is %d\n", ret);
+ pressEnterToContinue();
+ break;
+ case '3' : printf("Give brightness :");
+ scanf("%d",&value);
+
+ ret = backlight_dev->setBrightness(value);
+ if (ret < 0)
+ {
+ printf("Error, can't set brightness\n");
+ }
+
+ pressEnterToContinue();
+ break;
+ default : break;
+ }
+ }
+
+ delete backlight_dev;
}
/* AS1531 test */
hooks/post-receive
--
armadeus
|