19 #include "indicator.hpp"
21 static const unsigned int INVALID_COLOR = 0xFFFFFFFF;
59 indicator::indicator(
const std::string &name)
63 m_saved_properties.isValid =
false;
64 pthread_mutexattr_t mutex_attribute;
65 REPORT_IF_UNEQUAL(0, pthread_mutexattr_init(&mutex_attribute));
66 REPORT_IF_UNEQUAL(0, pthread_mutexattr_settype(&mutex_attribute, PTHREAD_MUTEX_RECURSIVE));
67 REPORT_IF_UNEQUAL(0, pthread_mutex_init(&m_mutex, &mutex_attribute));
73 #if 0 //Temporarily disabled until DELIA-6363 is available in stable2
74 m_state = (
true == m_indicator->
getState() ? STATE_STEADY_ON : STATE_STEADY_OFF);
76 m_state = STATE_STEADY_OFF;
78 INFO(
"Indicator %s initialized to state 0x%x\n", m_name.c_str(), m_state);
81 indicator::~indicator()
83 REPORT_IF_UNEQUAL(0, pthread_mutex_lock(&m_mutex));
86 REPORT_IF_UNEQUAL(
true, g_source_remove(m_source_id));
89 REPORT_IF_UNEQUAL(0, pthread_mutex_unlock(&m_mutex));
90 pthread_mutex_destroy(&m_mutex);
111 using namespace device;
114 m_indicator->setColor(color,
false);
118 ERROR(
"Error setting color!\n");
129 using namespace device;
132 m_indicator->setBrightness(intensity,
false);
136 ERROR(
"Error setting indicator brightness!\n");
150 if((0 == repetitions) || (2 > pattern->num_sequences))
152 ERROR(
"Bad inputs!\n");
156 REPORT_IF_UNEQUAL(0, pthread_mutex_lock(&m_mutex));
162 REPORT_IF_UNEQUAL(
true, g_source_remove(m_source_id));
167 else if(STATE_STEADY_OFF == m_state)
169 DEBUG(
"Indicator is currently disabled. Turning it back on.\n");
173 m_state = STATE_BLINKING;
174 m_pattern_ptr = pattern;
175 m_pattern_repetitions = repetitions;
176 m_sequence_read_offset = 0;
178 REPORT_IF_UNEQUAL(0, pthread_mutex_unlock(&m_mutex));
191 unsigned char offset = m_sequence_read_offset;
196 m_sequence_read_offset = (m_sequence_read_offset + 1) % m_pattern_ptr->num_sequences;
198 if(m_sequence_read_offset == m_pattern_ptr->num_sequences)
200 ERROR(
"Out of bounds access!\n");
210 if(-1 == m_pattern_repetitions)
218 if(0 == m_sequence_read_offset)
222 m_pattern_repetitions--;
223 if(0 < m_pattern_repetitions)
227 DEBUG(
"End iteration\n");
231 DEBUG(
"Final iteration complete\n");
249 REPORT_IF_UNEQUAL(0, pthread_mutex_lock(&m_mutex));
252 REPORT_IF_UNEQUAL(0, pthread_mutex_unlock(&m_mutex));
265 if(0 == milliseconds)
267 ERROR(
"Zero-wait timer!\n");
273 ERROR(
"Could not register callback!\n");
287 INFO(
"state 0x%x\n", state);
288 if((STATE_STEADY_ON != state) && (STATE_STEADY_OFF != state))
290 ERROR(
"Unsupported state!\n");
294 REPORT_IF_UNEQUAL(0, pthread_mutex_lock(&m_mutex));
296 if(STATE_BLINKING == m_state)
300 REPORT_IF_UNEQUAL(
true, g_source_remove(m_source_id));
302 INFO(
"Cancelled previously started blink operation\n");
306 REPORT_IF_UNEQUAL(0, pthread_mutex_unlock(&m_mutex));
308 if(STATE_STEADY_ON == state)
328 using namespace device;
331 m_indicator->setState(enable);
335 ERROR(
"Could not change indicator state!\n");
348 REPORT_IF_UNEQUAL(0, pthread_mutex_lock(&m_mutex));
349 m_saved_properties.state = m_state;
350 if(STATE_BLINKING == m_state)
352 m_saved_properties.sequence_read_offset = m_sequence_read_offset;
353 m_saved_properties.pattern_ptr = m_pattern_ptr;
354 m_saved_properties.pattern_repetitions= m_pattern_repetitions;
359 m_saved_properties.color = m_indicator->
getColor();
363 ERROR(
"Could not read brightness or color values!\n");
364 m_saved_properties.intensity = 20;
365 m_saved_properties.intensity= INVALID_COLOR;
367 m_saved_properties.isValid =
true;
368 REPORT_IF_UNEQUAL(0, pthread_mutex_unlock(&m_mutex));
369 INFO(
"Saved state.\n");
380 REPORT_IF_UNEQUAL(0, pthread_mutex_lock(&m_mutex));
381 if(m_saved_properties.isValid)
386 if(INVALID_COLOR != m_saved_properties.color)
391 m_state = m_saved_properties.state;
392 if(STATE_STEADY_ON == m_state)
395 INFO(
"Successfully restored to STEADY ON state.\n");
397 else if(STATE_BLINKING == m_state)
399 m_pattern_ptr = m_saved_properties.pattern_ptr;
400 m_sequence_read_offset = m_saved_properties.sequence_read_offset;
401 m_pattern_repetitions = m_saved_properties.pattern_repetitions;
405 if(0 == m_pattern_repetitions)
408 INFO(
"Successfully restored to final holding state of blink pattern.\n");
412 INFO(
"Successfully restored blink pattern.\n");
416 m_saved_properties.isValid =
false;
420 ERROR(
"Won't restore stale settings.\n");
422 REPORT_IF_UNEQUAL(0, pthread_mutex_unlock(&m_mutex));
433 using namespace device;
434 unsigned int preflare_brightness = 20;
437 preflare_brightness = m_indicator->getBrightness();
441 ERROR(
"Could not read brightness!\n");
447 ERROR(
"Could not register callback!\n");
451 unsigned int flare_level = preflare_brightness * (100 + percentage_increase) / 100;
452 if(100 < flare_level)
457 if(100 == preflare_brightness) {
458 flare_level = (preflare_brightness - percentage_increase);
470 using namespace device;
471 unsigned int preflare_brightness = 20;
474 preflare_brightness = m_indicator->getBrightness();
478 ERROR(
"Could not read brightness!\n");