📄 sensors.c
字号:
simulate_keypress('x');
return D_USED_CHAR;
}
return D_O_K;
}
int inst_refresh_rate_proc(int msg, DIALOG *d, int c)
{
switch (msg)
{
case MSG_START:
if ((d->dp = calloc(64, sizeof(char))) == NULL)
fatal_error("Could not allocate enough memory for instantaneous refresh rate control");
// Fall through
case MSG_REFRESH:
case MSG_UPDATE:
if (inst_refresh_rate >= 0)
sprintf(d->dp, "Instantaneous: %.2fHz", inst_refresh_rate);
else
sprintf(d->dp, "Instantaneous: N/A");
d->flags |= D_DIRTY;
break;
case MSG_DRAW:
rectfill(screen, d->x, d->y, d->x+d->w-1, d->y+d->h-1, d->bg); // clear the element
break;
case MSG_END:
free(d->dp);
d->dp = NULL;
break;
}
return d_text_proc(msg, d, c);
}
int avg_refresh_rate_proc(int msg, DIALOG *d, int c)
{
switch (msg)
{
case MSG_START:
if ((d->dp = calloc(64, sizeof(char))) == NULL)
fatal_error("Could not allocate enough memory for average refresh rate control");
// Fall through
case MSG_REFRESH:
case MSG_UPDATE:
if (avg_refresh_rate >= 0)
sprintf(d->dp, "Average: %.2fHz", avg_refresh_rate);
else
sprintf(d->dp, "Average: N/A");
d->flags |= D_DIRTY;
break;
case MSG_DRAW:
rectfill(screen, d->x, d->y, d->x+d->w-1, d->y+d->h-1, d->bg); // clear the element
break;
case MSG_END:
free(d->dp);
d->dp = NULL;
break;
}
return d_text_proc(msg, d, c);
}
/* ---- DO NOT TRANSLATE FROM HERE ---- */
void load_sensor_states()
{
int i;
char temp_buf[64];
for (i = 0; sensors[i].formula; i++)
{
sprintf(temp_buf, "sensor%i", i);
sensors[i].enabled = get_config_int("sensors", temp_buf, TRUE);
}
}
void save_sensor_states()
{
int i;
char temp_buf[64];
for (i = 0; sensors[i].formula; i++)
{
sprintf(temp_buf, "sensor%i", i);
set_config_int("sensors", temp_buf, sensors[i].enabled);
}
}
/* ---- TO HERE ---- */
void fill_sensors(int page_number)
{
int i;
int index = 0;
for (i = 0; sensor_dialog[i].proc; i++)
{
if (sensor_dialog[i].proc == sensor_proc)
{
if (sensors[index + page_number * SENSORS_PER_PAGE].formula)
{
strcpy(sensors[index + page_number * SENSORS_PER_PAGE].screen_buf, "N/A");
sensor_dialog[i].dp3 = &sensors[index + page_number * SENSORS_PER_PAGE];
index++;
}
else
{
sensor_dialog[i].dp3 = NULL;
sensor_dialog[i].flags |= D_DIRTY;
}
}
}
sensors_on_page = index;
}
int page_number_proc(int msg, DIALOG *d, int c)
{
switch (msg)
{
case MSG_START:
if ((d->dp = calloc(64, sizeof(char))) == NULL)
fatal_error("Could not allocate enough memory for page number control"); // do not translate
case MSG_UPDATE:
sprintf(d->dp, "%i of %i", current_page + 1, ((num_of_sensors % SENSORS_PER_PAGE) ? num_of_sensors/SENSORS_PER_PAGE + 1 : num_of_sensors/SENSORS_PER_PAGE));
d->flags |= D_DIRTY;
break;
case MSG_DRAW:
rectfill(screen, d->x-d->w, d->y, d->x+d->w-1, d->y+d->h-1, d->bg); // clear the element
break;
case MSG_END:
free(d->dp);
d->dp = NULL;
break;
}
return st_ctext_proc(msg, d, c);
}
int page_flipper_proc(int msg, DIALOG *d, int c)
{
int ret;
int last_page = (num_of_sensors % SENSORS_PER_PAGE) ? num_of_sensors/SENSORS_PER_PAGE : num_of_sensors/SENSORS_PER_PAGE - 1;
switch (msg)
{
case MSG_START:
case MSG_UPDATE:
if (d->d1 == -1)
{
if (current_page <= 0)
d->flags |= D_DISABLED;
else
d->flags &= ~D_DISABLED;
}
else if (d->d1 == 1)
{
if (current_page >= last_page)
d->flags |= D_DISABLED;
else
d->flags &= ~D_DISABLED;
}
d->flags |= D_DIRTY;
break;
}
ret = d_button_proc(msg, d, c);
if (ret == D_CLOSE)
{
if (d->d1 == -1)
current_page--;
else if (d->d1 == 1)
current_page++;
if (current_page < 0)
current_page = 0;
else if (current_page > last_page)
current_page = last_page;
fill_sensors(current_page);
inst_refresh_rate = -1;
avg_refresh_rate = -1;
broadcast_dialog_message(MSG_UPDATE, 0);
ret = D_REDRAWME;
}
return ret;
}
int toggle_proc(int msg, DIALOG *d, int c)
{
int ret;
switch (msg)
{
case MSG_START:
d->d2 = 1;
if ((d->dp = calloc(4, sizeof(char))) == NULL)
{
// don't translate!
sprintf(temp_error_buf, "Could not allocate enough memory for toggle button caption: %i", d->d1);
fatal_error(temp_error_buf);
}
strcpy(d->dp, "ON");
d->bg = C_GREEN;
// Fall through
case MSG_UPDATE:
if (d->d1 >= sensors_on_page)
{
d->flags |= D_DISABLED;
d->bg = C_LIGHT_GRAY;
strcpy(d->dp, empty_string);
if (d->d2 == 0)
num_of_disabled_sensors--;
}
else
{
if ((d->flags & D_DISABLED) && (d->d2 == 0))
num_of_disabled_sensors++;
d->flags &= ~D_DISABLED;
if (d->d2 == 1)
{
d->bg = C_GREEN;
strcpy(d->dp, "ON");
}
else
{
d->bg = C_DARK_YELLOW;
strcpy(d->dp, "OFF");
}
}
d->flags |= D_DIRTY;
break;
case MSG_TOGGLE:
if (((c == d->d1) || ((c == -2) && (d->d2 == 1)) || ((c == -1) && (d->d2 == 0))) && !(d->flags & D_DISABLED))
{
if (d->d2 == 0)
{
d->d2 = 1;
strcpy(d->dp, "ON");
d->bg = C_GREEN;
}
else
{
d->d2 = 0;
strcpy(d->dp, "OFF");
d->bg = C_DARK_YELLOW;
}
return D_REDRAWME;
}
break;
case MSG_END:
free(d->dp);
d->dp = NULL;
break;
}
ret = d_button_proc(msg, d, c);
if (ret == D_CLOSE)
{
broadcast_dialog_message(MSG_TOGGLE, d->d1);
return D_O_K;
}
return ret;
}
int toggle_all_proc(int msg, DIALOG *d, int c)
{
int ret;
switch (msg)
{
case MSG_START:
d->d2 = 1;
if ((d->dp = calloc(64, sizeof(char))) == NULL)
fatal_error("Could not allocate enough memory for toggle_all button caption"); // do not translate
strcpy(d->dp, "All OFF");
// Fall through
case MSG_UPDATE:
if (sensors_on_page == 0)
{
d->flags |= D_DISABLED;
d->bg = C_LIGHT_GRAY;
}
else
{
d->flags &= ~D_DISABLED;
if (d->bg == C_LIGHT_GRAY)
d->bg = C_DARK_YELLOW;
object_message(d, MSG_TOGGLE, 0);
}
d->flags |= D_DIRTY;
break;
case MSG_TOGGLE:
if ((c == -1) || ((c >= 0) && (num_of_disabled_sensors <= 0)))
{
d->d2 = 1;
strcpy(d->dp, "All OFF");
d->bg = C_DARK_YELLOW;
}
else if ((c == -2) || ((c >= 0) && (num_of_disabled_sensors >= sensors_on_page)))
{
d->d2 = 0;
strcpy(d->dp, "All ON");
d->bg = C_GREEN;
inst_refresh_rate = -1;
avg_refresh_rate = -1;
broadcast_dialog_message(MSG_REFRESH, 0);
}
d->flags |= D_DIRTY;
break;
case MSG_END:
free(d->dp);
d->dp = NULL;
break;
}
ret = d_button_proc(msg, d, c);
if (ret == D_CLOSE)
{
if (d->d2 == 0)
broadcast_dialog_message(MSG_TOGGLE, -1);
else
broadcast_dialog_message(MSG_TOGGLE, -2);
ret = D_REDRAWME;
}
return ret;
}
int status_proc(int msg, DIALOG *d, int c)
{
switch (msg)
{
case MSG_START:
if((d->dp = calloc(48, sizeof(char))) == NULL)
fatal_error("Could not allocate enough memory for status control (sensors)");
d->d1 = device_connected;
d->d2 = -1;
object_message(d, MSG_IDLE, 0);
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -