01-26-2012 04:47 PM
Can get acceleration, azimuth, pitch, roll, and gps information.
But,
Could not get temperature, light intensity, altitude height, proximity, rotation_matrix, and rotation vector.
Can you help me to figure out that it is supposed to work or not?
Whenever tried to get these values, always show "zero".
My code is at below. Does something wrong or just these valuses do not support in the Native SDK 2.0 beta 3?
if (sensor_is_supported(SENSOR_TYPE_TEMPERATURE)) {
/*
* If the device does not support accelerometer then notify the user,
* clean up and exit
*/
sensor_set_rate(SENSOR_TYPE_TEMPERATURE, SENSOR_RATE);
sensor_request_events(SENSOR_TYPE_TEMPERATURE);
}
temperature= sensor_event_get_temperature(event);
fprintf(f,"%7.3f\n", temperature);
fprintf(f,"%ld%d, %7.3f
Thank your attention.
sensor_event_get_rotation_vector
sensor_event_get_illuminance
sensor_event_get_rotation_matrix
sensor_event_get_proximity
sensor_event_get_altitude
SENSOR_TYPE_MAGNETOMETER = 1 SENSOR_TYPE_GYROSCOPE = 2 SENSOR_TYPE_ALTIMETER = 4 SENSOR_TYPE_TEMPERATURE = 5 SENSOR_TYPE_PROXIMITY = 6 SENSOR_TYPE_LIGHT = 7 SENSOR_TYPE_GRAVITY = 8 SENSOR_TYPE_LINEAR_ACCEL = 9 SENSOR_TYPE_ROTATION_VECTOR = 10 SENSOR_TYPE_ROTATION_MATRIX = 11
Solved! Go to Solution.
01-26-2012 06:04 PM
Is this post even supposed to make sense? It's formatted terribly, and I don't see the point of it.
What is the actual problem you see, what is the behavior you see, what is the behavior you expect to see, what is the most minimal test case you can give that demonstrates it?
Those of us who lurk here aren't likely to answer threads that make as little sense as this, but I felt charitable. Also, the Native SDK is kind of targeted for those people who already have a clue what they're doing.
01-27-2012 09:45 AM
01-27-2012 10:31 AM - edited 01-27-2012 10:37 AM
OS 2.0 beta 3.
Expected temperature will be a number, which is 10 ~ 50.
But, the result always shows "zero".
I don't know why.
I will continuously try to get a number.
Hopefully, can get values.
01-27-2012 10:36 AM
The code is at below.
#include <bps/bps.h>
#include <bps/navigator.h>
#include <screen/screen.h>
#include <stdio.h>
#include <stdlib.h>
#include <bps/dialog.h>
#include <string.h>
#include <errno.h>
#include <bps/sensor.h>
#include <sys/platform.h>
#include <sys/timeb.h>
#include <sys/types.h>
#include <stdbool.h>
#include "png.h"
#include "bbutil.h"
static screen_context_t screen_ctx;
static screen_window_t screen_win;
dialog_instance_t main_dialog = 0;
bool exit_application = false;
int paused = 0;
//Sensor data
float temperature;
int i, a;
static const int SENSOR_RATE = 50;
//file elements
int _logcounter=0;
char fullname[256];
FILE* f;
//time
struct timeb tmb[2];
static char *
get_window_group_id()
{
static char s_window_group_id[16] = "";
if (s_window_group_id[0] == '\0') {
snprintf(s_window_group_id, sizeof(s_window_group_id), "%d", getpid());
}
return s_window_group_id;
}
static int
setup_screen()
{
if (screen_create_context(&screen_ctx, SCREEN_APPLICATION_CONTEXT) != 0) {
return EXIT_FAILURE;
}
if (screen_create_window(&screen_win, screen_ctx) != 0) {
screen_destroy_context(screen_ctx);
return EXIT_FAILURE;
}
int usage = SCREEN_USAGE_NATIVE;
if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_USAGE, &usage) != 0) goto fail;
if (screen_create_window_buffers(screen_win, 1) != 0) goto fail;
if (screen_create_window_group(screen_win, get_window_group_id()) != 0) goto fail;
screen_buffer_t buff;
if (screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void*)&buff) != 0) goto fail;
int buffer_size[2];
if (screen_get_buffer_property_iv(buff, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size) != 0) goto fail;
int attribs[1] = {SCREEN_BLIT_END};
if (screen_fill(screen_ctx, buff, attribs) != 0) goto fail;
int dirty_rects[4] = {0, 0, buffer_size[0], buffer_size[1]};
if (screen_post_window(screen_win, buff, 1, (const int*)dirty_rects, 0) != 0) goto fail;
return EXIT_SUCCESS;
fail:
screen_destroy_window(screen_win);
screen_destroy_context(screen_ctx);
return EXIT_FAILURE;
}
static int
rotate_screen(int angle)
{
if ((angle != 0) && (angle != 90) && (angle != 180) && (angle != 270)) {
fprintf(stderr, "Invalid angle\n");
return EXIT_FAILURE;
}
int rc;
int rotation;
rc = screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &rotation);
if (rc != 0) {
fprintf(stderr, "screen error getting window rotation: %d\n", rc);
return EXIT_FAILURE;
}
int size[2];
rc = screen_get_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);
if (rc != 0) {
fprintf(stderr, "screen error getting window buffer size: %d\n", rc);
return EXIT_FAILURE;
}
int temp;
switch (angle - rotation) {
case -270:
case -90:
case 90:
case 270:
temp = size[0];
size[0] = size[1];
size[1] = temp;
break;
default:
break;
}
rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ROTATION, &angle);
if (rc != 0) {
fprintf(stderr, "screen error setting window rotation: %d\n", rc);
return EXIT_FAILURE;
}
rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_SIZE, size);
if (rc != 0) {
fprintf(stderr, "screen error setting window size: %d\n", rc);
return EXIT_FAILURE;
}
rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_SOURCE_SIZE, size);
if (rc != 0) {
fprintf(stderr, "screen error setting window size: %d\n", rc);
return EXIT_FAILURE;
}
rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);
if (rc != 0) {
fprintf(stderr, "screen error setting window buffer size: %d\n", rc);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
static bool
handle_navigator_event(bps_event_t *event)
{
bool should_exit = false;
switch (bps_event_get_code(event)) {
case NAVIGATOR_EXIT:
should_exit = true;
break;
case NAVIGATOR_ORIENTATION_CHECK:
navigator_orientation_check_response(event, true);
break;
case NAVIGATOR_ORIENTATION:
{
int angle = navigator_event_get_orientation_angle(event);
if (rotate_screen(angle) == EXIT_FAILURE) {
should_exit = true;
}
navigator_done_orientation(event);
break;
}
}
return should_exit;
}
/**
* Show an alert dialog that will contain the geolocation data.
*/
static void
show_main_dialog()
{
if (main_dialog) {
return;
}
dialog_create_alert(&main_dialog);
dialog_set_title_text(main_dialog, "Data Logger");
dialog_set_alert_message_text(main_dialog, "The BlackBerry Data Logger will record acceleration, GPS from the Playbook. Data is stored to the memory card.");
dialog_set_size(main_dialog, DIALOG_SIZE_FULL);
dialog_set_group_id(main_dialog, get_window_group_id());
dialog_set_cancel_required(main_dialog, true);
dialog_add_button(main_dialog, "Stop", true, 0, true);
dialog_add_button(main_dialog, "Start", true, createafile(), true);
dialog_show(main_dialog);
if(paused==2){
f = fopen(fullname, "w");
fprintf(f,"SystemTime (ms), Temp (C)\n");
}
}
void createafile(){
sprintf(fullname, "shared/documents/Raw-%d.txt",_logcounter);
if(f==NULL){
//file not exist
f = fopen(fullname, "r");
while(f!=NULL){
//file exists
fclose(f);
++_logcounter;
sprintf(fullname, "shared/documents/Raw-%d.txt",_logcounter);
f = fopen(fullname, "r");
}
}
paused = 2;
}
int main(int argc, char *argv[]){
bps_initialize();
navigator_request_events(0);
dialog_request_events(0);
if (setup_screen() != EXIT_SUCCESS) {
fprintf(stderr, "Unable to initialize screen.");
exit(-1);
}
if (BPS_SUCCESS != navigator_request_events(0)) {
fprintf(stderr, "Error requesting navigator events: %s", strerror(errno));
exit(-1);
}
if (BPS_SUCCESS != dialog_request_events(0)) {
fprintf(stderr, "Error requesting dialog events: %s", strerror(errno));
exit(-1);
}
if (sensor_is_supported(SENSOR_TYPE_TEMPERATURE)) {
sensor_request_events(SENSOR_TYPE_TEMPERATURE);
}
show_main_dialog();
while (!exit_application) {
bps_event_t *event = NULL;
bps_get_event(&event, 10);
if (event) {
if (bps_event_get_domain(event) == sensor_get_domain()) {
//sensor_temperature_reading doesn't work
if (SENSOR_TEMPERATURE_READING== bps_event_get_code(event)){
a =1;
temperature= sensor_event_get_temperature(event);
}
}else if (bps_event_get_domain(event) == dialog_get_domain()) {
;
}
else if (bps_event_get_domain(event) == navigator_get_domain()) {
exit_application = handle_navigator_event(event);
}
}//if event
for (i =0; i < 2; i++){
delay( 20 ); /* delay for 50 Hz */
ftime(&tmb[i]);
}
if (tmb[0].millitm > 99){
fprintf(f,"%ld%d, %7.3f, %d\n", tmb[0].time, tmb[0].millitm, temperature, a );
}else if (tmb[0].millitm <= 99 && tmb[0].millitm >= 10){
fprintf(f,"%ld0%d, %7.3f, %d\n", tmb[0].time, tmb[0].millitm, temperature, a );
}else if (tmb[0].millitm >= 1 && tmb[0].millitm < 10){
fprintf(f,"%ld00%d, %7.3f, %d\n", tmb[0].time, tmb[0].millitm, temperature,a );
}else if (tmb[0].millitm ==0){
fprintf(f,"%ld000%d, %7.3f, %d\n", tmb[0].time, tmb[0].millitm, temperature, a );
}
if (tmb[1].millitm > 99){
fprintf(f,"%ld%d, %7.3f, %d\n", tmb[1].time, tmb[1].millitm, temperature, a );
}else if (tmb[1].millitm <= 99 && tmb[1].millitm >= 10){
fprintf(f,"%ld0%d, %7.3f, %d\n", tmb[1].time, tmb[1].millitm, temperature, a );
}else if (tmb[1].millitm >= 1 && tmb[1].millitm < 10){
fprintf(f,"%ld00%d, %7.3f, %d\n", tmb[1].time, tmb[1].millitm, temperature, a );
}else if (tmb[1].millitm ==0){
fprintf(f,"%ld000%d, %7.3f, %d\n", tmb[1].time, tmb[1].millitm, temperature, a );
}
}//while
if (main_dialog) {
dialog_destroy(main_dialog);
}
fclose(f);
sensor_stop_events(SENSOR_TYPE_TEMPERATURE);
bps_shutdown();
screen_destroy_window(screen_win);
screen_destroy_context(screen_ctx);
return 0;
}//main
01-27-2012 10:42 AM
01-27-2012 10:44 AM
I requested a minimal test, not the whole thing. Often, you can squash bugs yourself by trying to narrow it down to a dozen-line test case app.
Also, you didn't address any of the questions I asked.
01-27-2012 11:11 AM - edited 01-27-2012 12:42 PM
OS: 2.0.0.7111.
Device-Release:
Problem: always get zero value for temperature, light intensity, proximity value.
Problem:When getting temperature sensor information, always fail.
if (info){ fail
But I can get accelerometer information.
Expected result: should be have values intead of "zero or 0".\
Device-Debug mode:
Problem: always skip this line.
if (SENSOR_TEMPERATURE_READING== bps_event_get_code(event)){
Problem:always do not accept this line.
if (sensor_is_supported(SENSOR_TYPE_TEMPERATURE)) {
Minimal test: ??
Hopefully, the problem is clearly addressed.
In my opinion:
1.Possible reason: OS 2.0 7111 or Playbook OS 2.0 beta 3 does not support temperature sensor yet.
Next step:
1.Give up temperature sensor application development.
2.Continuouly test on other sensors, such as light senosr, proximity sensor, and so on.
Thank your attention.
01-27-2012 01:35 PM
01-27-2012 01:39 PM
lyon819 wrote:Minimal test: ??
That would be the smallest possible program you can write to demonstrate the behavior. That means as few lines of code as possible (ideally less than 2 dozen), and as few includes as you can get away with. Also, if it requires any special compilation flags, note those as well.